{"id":351478,"date":"2024-05-20T21:47:27","date_gmt":"2024-05-20T21:47:27","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=351478"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-05-20T21:47:27","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=351478","title":{"rendered":"<span>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 if \u0434\u043b\u044f \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u043e\u0432\u043e\u0434\u043e\u043c \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u044b\u0448\u043b\u0435\u043d\u0438\u044f \u043f\u043e \u044d\u0442\u043e\u0439 \u0442\u0435\u043c\u0435 \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u043b <a href=\"https:\/\/ru.stackoverflow.com\/questions\/946740\/%D0%9D%D0%B5%D1%81%D0%BA%D0%BE%D0%BB%D1%8C%D0%BA%D0%BE-builtin-expect-%D0%B2-%D1%83%D1%81%D0%BB%D0%BE%D0%B2%D0%B8%D0%B8\">\u043f\u043e\u0441\u0442<\/a> \u0433\u0434\u0435 \u043f\u043e\u044f\u0441\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0434\u0432\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u0443\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0433\u043e <em>\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430<\/em> <em>if<\/em>.\u00a0\u041f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440 \u0433\u0434\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e, \u0447\u0442\u043e \u0432 \u043e\u0434\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u0434\u0430 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0438\u0434\u0435\u0442 \u0431\u043b\u043e\u043a \u0441 \u043a\u043e\u0434\u043e\u043c \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0430 \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u0441\u043b\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0438\u0434\u0435\u0442 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0432\u0435\u0442\u043a\u0430. \u042f \u0440\u0435\u0448\u0438\u043b \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0441\u0432\u043e\u0438 \u0442\u0435\u0441\u0442\u044b \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u044f\u0445, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043a\u043e\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u0438 \u043a\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430.<\/p>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440 \u0441 \u0442\u0430\u043a\u0438\u043c \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c, \u0447\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 <em>if<\/em> \u043c\u0430\u043b\u043e\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u0438 \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u0434\u0430 \u0441\u0430\u043c\u043e\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 <em>if<\/em><strong> <\/strong>\u0441\u0442\u0430\u0432\u0438\u0442 \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 (<em>je, jne<\/em><strong> <\/strong>\u0438 \u043f\u0440\u043e\u0447\u0438\u0435) \u043d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439 \u0435\u0441\u043b\u0438 \u043a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u0442\u0438\u043d\u043d\u044b\u043c.\u00a0\u041f\u043e\u0441\u043b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u043c \u0438\u0434\u0443\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c <em>if<\/em> \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438. \u041c\u0435\u0442\u043a\u0430 \u0431\u043b\u043e\u043a\u0430 \u043a\u043e\u0434\u0430, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u043c\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u044e <em>if<\/em>, \u043e\u0431\u044b\u0447\u043d\u043e \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d \u043f\u043e \u0442\u0435\u043a\u0441\u0442\u0443\u00a0\u0433\u0434\u0435-\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435 \u043e\u0442 \u0441\u0430\u043c\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <em>if<\/em>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0443, \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0432 \u0432 \u043a\u044d\u0448 \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0433\u0434\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d \u0431\u043b\u043e\u043a <em>if<\/em><strong> <\/strong>\u0438 \u0431\u043b\u0438\u0437\u043b\u0435\u0436\u0430\u0449\u0438\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f, <em>if<\/em> \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u0442\u043e \u0447\u0442\u043e \u043e\u043d \u0443\u0436\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043b \u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043a\u043e\u0434 \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 \u043c\u0435\u0442\u043a\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u0441 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c.\u00a0 \u0410 \u0443\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u0435\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u043e, \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u044f \u0442\u043e, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0441\u0435\u0439\u0447\u0430\u0441 \u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u044f \u0442\u043e \u043c\u0435\u0441\u0442\u043e \u0433\u0434\u0435 \u043e\u043d \u0431\u044b\u043b, \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044f <em>\u0431\u043b\u043e\u043a if<\/em>. \u0422\u0430\u043a \u0436\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430. <\/p>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438 \u043f\u043e \u0434\u0440\u0443\u0433\u043e\u043c\u0443 (\u043e\u0431 \u044d\u0442\u043e\u043c \u0438 \u0441\u0442\u0430\u0442\u044c\u044f). \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u043a\u0430\u043a\u0443\u044e \u0432\u0435\u0442\u0432\u044c <em>if<\/em> \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043d\u043e\u0439 \u0435\u0441\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f <strong>__builtin_expect(long, long)<\/strong>. \u0413\u0434\u0435 \u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u043d\u0434 \u0441\u0442\u0430\u0432\u0438\u0442\u0441\u044f\u00a0 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435, \u0430 \u0432\u0442\u043e\u0440\u044b\u043c <strong>1<\/strong> \u0438\u043b\u0438 <strong>0<\/strong> &#8212; \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043d\u043e\u0435 \u0438\u043b\u0438 \u043d\u0435\u0442.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440: <a href=\"https:\/\/godbolt.org\/z\/7PnrWPvxe\">https:\/\/godbolt.org\/z\/7PnrWPvxe<\/a><\/p>\n<p>\u0418\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f<strong> b():<\/strong><\/p>\n<pre><code class=\"cpp\">bool b(bool ptr) {     if(__builtin_expect(ptr, 1)){             std::cout &lt;&lt; \" true )\" &lt;&lt; std::endl;             return true;         }     std::cout &lt;&lt; \" false (\" &lt;&lt; std::endl;     return false; }<\/code><\/pre>\n<p>\u0415\u0435 ASM:<\/p>\n<details class=\"spoiler\">\n<summary>Hidden text<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"assembly\">.LC0:         .string \" true )\" .LC1:         .string \" false (\" b(bool):         push    rbp         mov     ebp, edi         push    rbx         sub     rsp, 8         test    dil, dil         je      .L12         mov     edx, 7         mov     esi, OFFSET FLAT:.LC0 .L32:         mov     edi, OFFSET FLAT:std::cout         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp; std::__ostream_insert&lt;char, std::char_traits&lt;char> >(std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp;, char const*, long)         mov     rax, QWORD PTR std::cout[rip]         mov     rax, QWORD PTR [rax-24]         mov     rbx, QWORD PTR std::cout[rax+240]         test    rbx, rbx         je      .L33         cmp     BYTE PTR [rbx+56], 0         je      .L18         movsx   esi, BYTE PTR [rbx+67] .L19:         mov     edi, OFFSET FLAT:std::cout         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >::put(char)         mov     rdi, rax         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >::flush()         add     rsp, 8         mov     eax, ebp         pop     rbx         pop     rbp         ret .L18:         mov     rdi, rbx         call    std::ctype&lt;char>::_M_widen_init() const         mov     rax, QWORD PTR [rbx]         mov     esi, 10         mov     rax, QWORD PTR [rax+48]         cmp     rax, OFFSET FLAT:std::ctype&lt;char>::do_widen(char) const         je      .L19         mov     rdi, rbx         call    rax         movsx   esi, al         jmp     .L19 .L12:         mov     edx, 8         mov     esi, OFFSET FLAT:.LC1         jmp     .L32 .L33:         call    std::__throw_bad_cast() <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0447\u0430\u0441\u0442\u044c:<\/p>\n<pre><code class=\"assembly\">        test    dil, dil         je      .L12         mov     edx, 7         mov     esi, OFFSET FLAT:.LC0 <\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f <strong>test <\/strong>\u0442\u043e <a href=\"https:\/\/reverseengineering.stackexchange.com\/questions\/25188\/what-does-test-al-al-mean\">\u0441\u044e\u0434\u0430<\/a>. \u0415\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 <strong>false <\/strong>\u0442\u043e \u043f\u0440\u044b\u0433\u0430\u0435\u043c \u043d\u0430 \u043c\u0435\u0442\u043a\u0443 <strong>.L12<\/strong> (\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0447\u0435\u043d\u044c \u0434\u0430\u043b\u0435\u043a\u043e, \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u043f\u043e\u0441\u043b\u0435 \u0442\u0435\u043b\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438). \u0415\u0441\u043b\u0438 <strong>true\u00a0<\/strong> \u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0434\u0432\u0438\u0433\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u00a0 &#8212; \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c <strong>.string &#187; true )&#187;<\/strong>, \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u0431\u0443\u0434\u0435\u0442 \u043a\u0430\u043a \u043c\u044b \u0437\u0430\u0434\u0443\u043c\u0430\u043b\u0438, \u0442\u043e \u0435\u0441\u0442\u044c\u00a0 <strong>ptr <\/strong>\u0431\u0443\u0434\u0435\u0442 <strong>true <\/strong>\u0442\u043e \u0432\u0435\u0441\u044c \u043d\u0430\u0448 \u043a\u043e\u0434 &#8212; \u044d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0432 \u043a\u0435\u0448 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0442\u044c.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 &#8212; \u0444\u0443\u043d\u043a\u0446\u0438\u044e <strong>c()<\/strong>:<\/p>\n<pre><code class=\"cpp\">bool c(bool ptr) {     if(ptr){             std::cout &lt;&lt; \" true )\" &lt;&lt; std::endl;             return true;         }     std::cout &lt;&lt; \" false (\" &lt;&lt; std::endl;     return false; }<\/code><\/pre>\n<p>\u0415\u0435 ASM \u0443\u0436\u0435 \u0434\u0440\u0443\u0433\u043e\u0439:<\/p>\n<details class=\"spoiler\">\n<summary>Hidden text<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"assembly\">c(bool):         push    rbp         mov     edx, 8         mov     ebp, edi         mov     esi, OFFSET FLAT:.LC1         push    rbx         sub     rsp, 8         test    dil, dil         je      .L55         mov     edx, 7         mov     esi, OFFSET FLAT:.LC0 .L55:         mov     edi, OFFSET FLAT:std::cout         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp; std::__ostream_insert&lt;char, std::char_traits&lt;char> >(std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp;, char const*, long)         mov     rax, QWORD PTR std::cout[rip]         mov     rax, QWORD PTR [rax-24]         mov     rbx, QWORD PTR std::cout[rax+240]         test    rbx, rbx         je      .L56         cmp     BYTE PTR [rbx+56], 0         je      .L41         movsx   esi, BYTE PTR [rbx+67] .L42:         mov     edi, OFFSET FLAT:std::cout         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >::put(char)         mov     rdi, rax         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >::flush()         add     rsp, 8         mov     eax, ebp         pop     rbx         pop     rbp         ret .L41:         mov     rdi, rbx         call    std::ctype&lt;char>::_M_widen_init() const         mov     rax, QWORD PTR [rbx]         mov     esi, 10         mov     rax, QWORD PTR [rax+48]         cmp     rax, OFFSET FLAT:std::ctype&lt;char>::do_widen(char) const         je      .L42         mov     rdi, rbx         call    rax         movsx   esi, al         jmp     .L42 .L56:         call    std::__throw_bad_cast() <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<pre><code class=\"assembly\">        mov     esi, OFFSET FLAT:.LC1         push    rbx         sub     rsp, 8         test    dil, dil         je      .L55         mov     edx, 7         mov     esi, OFFSET FLAT:.LC0 .L55:         mov     edi, OFFSET FLAT:std::cout<\/code><\/pre>\n<p>\u0412 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0434\u0430\u0436\u0435 \u0434\u043e <strong>\u0431\u043b\u043e\u043a\u0430 if<\/strong> \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0430<strong> .LC1<\/strong>, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f<strong>. string &#187; false (&#171;<\/strong>.\u00a0\u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0430\u043d\u0430\u043b\u0438\u0437 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 <strong>false <\/strong>\u043f\u0435\u0440\u0435\u043f\u0440\u044b\u0433\u0438\u0432\u0430\u0435\u043c \u0434\u0432\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0434\u0435\u043b\u0430\u0435\u043c \u0432\u044b\u0432\u043e\u0434 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d, \u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 <strong>true<\/strong> \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0435 \u0440\u0430\u043d\u0435\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043d\u0430 \u043c\u0435\u0442\u043a\u0443 <strong>.LC0<\/strong> \u0438 \u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435, \u0432\u044b\u0432\u043e\u0434\u044f \u043d\u0430 \u044d\u043a\u0440\u0430\u043d.\u00a0\u0412 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e\u0433\u043e \u043d\u0435 \u0441\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u043b\u044e\u0431\u043e\u0439 \u0440\u0430\u0441\u043a\u043b\u0430\u0434\u043a\u0435, \u0440\u0430\u0437\u0432\u0435 \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043b\u0438\u0448\u043d\u044f\u044f \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u044c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u0441\u0445\u043e\u0434\u0430. \u042d\u0442\u043e \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u0430\u043b\u0430. \u0412\u0438\u0434\u0438\u043c \u0442\u0430\u043a \u0436\u0435, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0437\u0434\u0435\u0441\u044c \u0432\u044b\u0431\u0440\u0430\u043b \u0434\u0440\u0443\u0433\u0443\u044e \u0432\u0435\u0442\u0432\u044c <em>if<\/em> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0430. <\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <strong>main <\/strong>\u0433\u0434\u0435 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u043c\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430\u043c\u0438 \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0430.<\/p>\n<pre><code class=\"cpp\">int main(int argc, char **argv) {     std::cout &lt;&lt; \" main\" &lt;&lt; std::endl;         if(__builtin_expect(b(true),1))     {         std::cout &lt;&lt; \" main true\" &lt;&lt; std::endl;     }      if(c(true))     {          std::cout &lt;&lt; \" main false\" &lt;&lt; std::endl;     }     return EXIT_SUCCESS; }<\/code><\/pre>\n<p>\u041d\u0430\u0447\u0430\u043b\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <strong>main <\/strong>\u0438 \u043f\u0435\u0440\u0432\u044b\u0439 <strong>if <\/strong>\u0433\u0435\u043d\u0435\u0440\u0438\u0442 \u0442\u0430\u043a\u043e\u0439 ASM \u043a\u043e\u0434:<\/p>\n<details class=\"spoiler\">\n<summary>Hidden text<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"assembly\">.LC2:         .string \" main\" .LC3:         .string \" main true\" .LC4:         .string \" main false\" main:         sub     rsp, 8         mov     esi, OFFSET FLAT:.LC2         mov     edi, OFFSET FLAT:std::cout         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp; std::operator&lt;&lt; &lt;std::char_traits&lt;char> >(std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp;, char const*)         mov     rdi, rax         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp; std::endl&lt;char, std::char_traits&lt;char> >(std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp;) [clone .isra.0]         mov     edi, 1         call    b(bool)         test    al, al         je      .L58         mov     edi, OFFSET FLAT:std::cout         mov     esi, OFFSET FLAT:.LC3         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp; std::operator&lt;&lt; &lt;std::char_traits&lt;char> >(std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp;, char const*)         mov     rdi, rax         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp; std::endl&lt;char, std::char_traits&lt;char> >(std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp;) [clone .isra.0] .L58:         mov     edi, 1         call    c(bool) <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0421\u0443\u0442\u044c \u0441\u0430\u043c\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438:<\/p>\n<pre><code class=\"assembly\">        call    b(bool)         test    al, al         je      .L58         mov     edi, OFFSET FLAT:std::cout mov     esi, OFFSET FLAT:.LC3<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 <strong>true <\/strong>\u0442\u043e \u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0443\u0441\u043b\u043e\u0432\u0438\u044e. <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 <strong>false <\/strong>\u0442\u043e \u043f\u0435\u0440\u0435\u043f\u0440\u044b\u0433\u0438\u0432\u0430\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a \u0438 \u0438\u0434\u0435\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0443\u0441\u043b\u043e\u0432\u0438\u044e. \u0412\u0441\u0435 \u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e.<\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u0442\u043e\u0440\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435:<\/p>\n<pre><code class=\"assembly\">.L58:         mov     edi, 1         call    c(bool)         test    al, al         jne     .L67 .L59:         xor     eax, eax         add     rsp, 8         ret .L67:         mov     esi, OFFSET FLAT:.LC4         mov     edi, OFFSET FLAT:std::cout         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp; std::operator&lt;&lt; &lt;std::char_traits&lt;char> >(std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp;, char const*)         mov     rdi, rax         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp; std::endl&lt;char, std::char_traits&lt;char> >(std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp;) [clone .isra.0]         jmp     .L59 <\/code><\/pre>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u0435, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 <strong>false <\/strong>\u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435 \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 <strong>true <\/strong>\u043f\u0440\u044b\u0433\u0430\u0435\u043c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430 <strong>.L67<\/strong> \u0433\u0434\u0435 \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0442\u0435\u043a\u0441\u0442, \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u044b\u0433\u0430\u0435\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043d\u0430 \u0442\u0440\u0435\u0442\u044c\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u043e\u0441\u043b\u0435 <strong>if <\/strong>\u0433\u0434\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0442\u0435\u043b\u043e \u0431\u043b\u043e\u043a\u0430 \u0441 <strong>true <\/strong>\u0431\u044b\u043b\u043e \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0433\u043e \u043c\u0435\u0442\u043a\u0430 <strong>.L67<\/strong>\u00a0\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0434\u0430\u043b\u0435\u043a\u043e \u043e\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u044f, \u043d\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u0432\u0441\u0435 \u0431\u043b\u043e\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0435 \u0432\u0441\u0435 \u0442\u0430\u043a \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e \u0432 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f\u0445. \u0412\u043e\u0437\u044c\u043c\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440: <a href=\"https:\/\/godbolt.org\/z\/3W9r1s3d8\">https:\/\/godbolt.org\/z\/3W9r1s3d8<\/a> . \u0414\u0432\u0435 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <strong>foo()<\/strong> \u0438 <strong>bar()<\/strong> \u043f\u043e\u0447\u0442\u0438 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c \u0442\u0435\u043b\u043e\u043c \u0438 \u043e\u0434\u043d\u0438\u043c \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c <strong>if<\/strong> \u0432 \u043a\u0430\u0436\u0434\u043e\u0439:<\/p>\n<pre><code class=\"cpp\">bool foo(int i) {     if(i != 1)     {         fprintf(stderr, \"error foo\");         return false;     }          fprintf(stdout, \"good foo\");     return true; }  bool bar(int i) {     if(i == 1)     {         fprintf(stderr, \"error bar\");         return false;     }          fprintf(stdout, \"good bar\");     return true; }<\/code><\/pre>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u0430 \u043f\u0435\u0440\u0432\u043e\u0439:<\/p>\n<pre><code class=\"assembly\">.LC0:         .string \"error foo\" .LC1:         .string \"good foo\" foo(int):         subq    $8, %rsp         cmpl    $1, %edi         je      .L2         movl    $9, %edx         movl    $1, %esi         movl    $.LC0, %edi<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u0435 <em>\u00ab!=\u00bb<\/em> \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u044b\u043c. \u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <strong>bar()<\/strong> \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442:<\/p>\n<pre><code class=\"assembly\">.LC2:         .string \"error bar\" .LC3:         .string \"good bar\" bar(int):         subq    $8, %rsp         cmpl    $1, %edi         je      .L10         movl    $8, %edx         movl    $1, %esi         movl    $.LC3, %edi<\/code><\/pre>\n<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435 <em>\u00ab==\u00bb<\/em> \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u043d\u0435\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u044b\u043c, \u0447\u0435\u043c \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0438. <\/p>\n<p>\u0422\u0430\u043a\u043e\u0439 \u0436\u0435 \u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 main():<\/p>\n<pre><code class=\"assembly\">.LC4:         .string \"Unexpected number\" .LC5:         .string \"--error\" .LC6:         .string \"error\" .LC7:         .string \"fail\" .LC8:         .string \"main good\" main:         pushq   %rbx         cmpl    $2, %edi         jne     .L24         movq    8(%rsi), %rdi         movl    $.LC5, %esi         call    strcmp         testl   %eax, %eax         je      .L25         movl    $1, %edi         call    foo(int)         movl    $2, %edi         movl    %eax, %ebx         call    bar(int)         testb   %bl, %bl         je      .L16         testb   %al, %al         je      .L16         movl    $4, %edx         movl    $1, %esi         movl    $.LC7, %edi<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u043f\u0435\u0440\u0435\u043c\u0435\u0448\u043a\u0443: \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0441\u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u043a\u0430\u043a \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0447\u0430\u0441\u0442\u044b\u0435, \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043d\u0435\u0442. \u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u00ab\u0448\u0442\u0430\u0442\u043d\u043e\u0433\u043e\u00bb \u0440\u0435\u0436\u0438\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u0435\u0436\u0430\u0442\u044c \u043f\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u0443\u0433\u0430\u0434\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0439, \u0432 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0447\u0438\u0442\u0430\u0435\u0442, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u0438\u0434\u0435\u0442 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0441 \u043a\u0430\u043a\u0438\u043c-\u043b\u0438\u0431\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c, \u0442\u043e \u044d\u0442\u043e \u043c\u0430\u043b\u043e\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u044b\u0439 \u0438\u0441\u0445\u043e\u0434 \u0438 \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0431\u0443\u0434\u0443\u0442 \u0434\u0430\u043b\u0435\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u0441\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u043f\u043e\u0441\u043b\u0435 \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430. \u041d\u043e \u043a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 foo() \u0438 bar() \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u043e\u0442\u043b\u0438\u0447\u043d\u0443\u044e \u043e\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u0437\u0430\u043c\u044b\u0441\u043b\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043b\u0443\u0447\u0448\u0435 \u0435\u043c\u0443 \u044f\u0432\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <strong>__builtin_expect <\/strong>\u043a\u0430\u043a\u0430\u044f \u0432\u0435\u0442\u043a\u0430 \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0447\u0430\u0441\u0442\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c\u043e\u0439 \u0441 \u043d\u0430\u0448\u0435\u0439 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f. \u0421 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u044d\u0442\u043e\u0433\u043e \u043c\u0430\u043a\u0440\u043e\u0441\u0430 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 (\u0442\u0430 \u0447\u0430\u0441\u0442\u044c \u0433\u0434\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d -DUSE_EXPECTED) \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430 \u043d\u0438\u043c\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438, \u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0432\u044b\u043d\u0435\u0441\u0435\u043d\u0430 \u0432 \u043a\u043e\u043d\u0435\u0446 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0447\u0442\u043e\u0431\u044b \u0432 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044f \u043a\u043e\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0441\u043f\u043e\u0442\u044b\u043a\u0430\u043b\u0441\u044f \u043e \u0431\u043b\u043e\u043a\u0438 \u0441 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0440\u0435\u0434\u043a\u0438\u0445 \u043e\u0448\u0438\u0431\u043e\u043a.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/752974\/\"> https:\/\/habr.com\/ru\/articles\/752974\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u043e\u0432\u043e\u0434\u043e\u043c \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u044b\u0448\u043b\u0435\u043d\u0438\u044f \u043f\u043e \u044d\u0442\u043e\u0439 \u0442\u0435\u043c\u0435 \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u043b <a href=\"https:\/\/ru.stackoverflow.com\/questions\/946740\/%D0%9D%D0%B5%D1%81%D0%BA%D0%BE%D0%BB%D1%8C%D0%BA%D0%BE-builtin-expect-%D0%B2-%D1%83%D1%81%D0%BB%D0%BE%D0%B2%D0%B8%D0%B8\">\u043f\u043e\u0441\u0442<\/a> \u0433\u0434\u0435 \u043f\u043e\u044f\u0441\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0434\u0432\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u0443\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0433\u043e <em>\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430<\/em> <em>if<\/em>.\u00a0\u041f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440 \u0433\u0434\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e, \u0447\u0442\u043e \u0432 \u043e\u0434\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u0434\u0430 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0438\u0434\u0435\u0442 \u0431\u043b\u043e\u043a \u0441 \u043a\u043e\u0434\u043e\u043c \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0430 \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u0441\u043b\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0438\u0434\u0435\u0442 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0432\u0435\u0442\u043a\u0430. \u042f \u0440\u0435\u0448\u0438\u043b \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0441\u0432\u043e\u0438 \u0442\u0435\u0441\u0442\u044b \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u044f\u0445, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043a\u043e\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u0438 \u043a\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430.<\/p>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440 \u0441 \u0442\u0430\u043a\u0438\u043c \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c, \u0447\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 <em>if<\/em> \u043c\u0430\u043b\u043e\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u0438 \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u0434\u0430 \u0441\u0430\u043c\u043e\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 <em>if<\/em><strong> <\/strong>\u0441\u0442\u0430\u0432\u0438\u0442 \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 (<em>je, jne<\/em><strong> <\/strong>\u0438 \u043f\u0440\u043e\u0447\u0438\u0435) \u043d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439 \u0435\u0441\u043b\u0438 \u043a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u0442\u0438\u043d\u043d\u044b\u043c.\u00a0\u041f\u043e\u0441\u043b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u043c \u0438\u0434\u0443\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c <em>if<\/em> \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438. \u041c\u0435\u0442\u043a\u0430 \u0431\u043b\u043e\u043a\u0430 \u043a\u043e\u0434\u0430, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u043c\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u044e <em>if<\/em>, \u043e\u0431\u044b\u0447\u043d\u043e \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d \u043f\u043e \u0442\u0435\u043a\u0441\u0442\u0443\u00a0\u0433\u0434\u0435-\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435 \u043e\u0442 \u0441\u0430\u043c\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <em>if<\/em>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0443, \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0432 \u0432 \u043a\u044d\u0448 \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0433\u0434\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d \u0431\u043b\u043e\u043a <em>if<\/em><strong> <\/strong>\u0438 \u0431\u043b\u0438\u0437\u043b\u0435\u0436\u0430\u0449\u0438\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f, <em>if<\/em> \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u0442\u043e \u0447\u0442\u043e \u043e\u043d \u0443\u0436\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043b \u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043a\u043e\u0434 \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 \u043c\u0435\u0442\u043a\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u0441 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c.\u00a0 \u0410 \u0443\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u0435\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u043e, \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u044f \u0442\u043e, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0441\u0435\u0439\u0447\u0430\u0441 \u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u044f \u0442\u043e \u043c\u0435\u0441\u0442\u043e \u0433\u0434\u0435 \u043e\u043d \u0431\u044b\u043b, \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044f <em>\u0431\u043b\u043e\u043a if<\/em>. \u0422\u0430\u043a \u0436\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430. <\/p>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438 \u043f\u043e \u0434\u0440\u0443\u0433\u043e\u043c\u0443 (\u043e\u0431 \u044d\u0442\u043e\u043c \u0438 \u0441\u0442\u0430\u0442\u044c\u044f). \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u043a\u0430\u043a\u0443\u044e \u0432\u0435\u0442\u0432\u044c <em>if<\/em> \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043d\u043e\u0439 \u0435\u0441\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f <strong>__builtin_expect(long, long)<\/strong>. \u0413\u0434\u0435 \u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u043d\u0434 \u0441\u0442\u0430\u0432\u0438\u0442\u0441\u044f\u00a0 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435, \u0430 \u0432\u0442\u043e\u0440\u044b\u043c <strong>1<\/strong> \u0438\u043b\u0438 <strong>0<\/strong> &#8212; \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043d\u043e\u0435 \u0438\u043b\u0438 \u043d\u0435\u0442.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440: <a href=\"https:\/\/godbolt.org\/z\/7PnrWPvxe\">https:\/\/godbolt.org\/z\/7PnrWPvxe<\/a><\/p>\n<p>\u0418\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f<strong> b():<\/strong><\/p>\n<pre><code class=\"cpp\">bool b(bool ptr) {     if(__builtin_expect(ptr, 1)){             std::cout &lt;&lt; \" true )\" &lt;&lt; std::endl;             return true;         }     std::cout &lt;&lt; \" false (\" &lt;&lt; std::endl;     return false; }<\/code><\/pre>\n<p>\u0415\u0435 ASM:<\/p>\n<details class=\"spoiler\">\n<summary>Hidden text<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"assembly\">.LC0:         .string \" true )\" .LC1:         .string \" false (\" b(bool):         push    rbp         mov     ebp, edi         push    rbx         sub     rsp, 8         test    dil, dil         je      .L12         mov     edx, 7         mov     esi, OFFSET FLAT:.LC0 .L32:         mov     edi, OFFSET FLAT:std::cout         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp; std::__ostream_insert&lt;char, std::char_traits&lt;char> >(std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp;, char const*, long)         mov     rax, QWORD PTR std::cout[rip]         mov     rax, QWORD PTR [rax-24]         mov     rbx, QWORD PTR std::cout[rax+240]         test    rbx, rbx         je      .L33         cmp     BYTE PTR [rbx+56], 0         je      .L18         movsx   esi, BYTE PTR [rbx+67] .L19:         mov     edi, OFFSET FLAT:std::cout         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >::put(char)         mov     rdi, rax         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >::flush()         add     rsp, 8         mov     eax, ebp         pop     rbx         pop     rbp         ret .L18:         mov     rdi, rbx         call    std::ctype&lt;char>::_M_widen_init() const         mov     rax, QWORD PTR [rbx]         mov     esi, 10         mov     rax, QWORD PTR [rax+48]         cmp     rax, OFFSET FLAT:std::ctype&lt;char>::do_widen(char) const         je      .L19         mov     rdi, rbx         call    rax         movsx   esi, al         jmp     .L19 .L12:         mov     edx, 8         mov     esi, OFFSET FLAT:.LC1         jmp     .L32 .L33:         call    std::__throw_bad_cast() <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0447\u0430\u0441\u0442\u044c:<\/p>\n<pre><code class=\"assembly\">        test    dil, dil         je      .L12         mov     edx, 7         mov     esi, OFFSET FLAT:.LC0 <\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f <strong>test <\/strong>\u0442\u043e <a href=\"https:\/\/reverseengineering.stackexchange.com\/questions\/25188\/what-does-test-al-al-mean\">\u0441\u044e\u0434\u0430<\/a>. \u0415\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 <strong>false <\/strong>\u0442\u043e \u043f\u0440\u044b\u0433\u0430\u0435\u043c \u043d\u0430 \u043c\u0435\u0442\u043a\u0443 <strong>.L12<\/strong> (\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0447\u0435\u043d\u044c \u0434\u0430\u043b\u0435\u043a\u043e, \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u043f\u043e\u0441\u043b\u0435 \u0442\u0435\u043b\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438). \u0415\u0441\u043b\u0438 <strong>true\u00a0<\/strong> \u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0434\u0432\u0438\u0433\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u00a0 &#8212; \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c <strong>.string &#187; true )&#187;<\/strong>, \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u0431\u0443\u0434\u0435\u0442 \u043a\u0430\u043a \u043c\u044b \u0437\u0430\u0434\u0443\u043c\u0430\u043b\u0438, \u0442\u043e \u0435\u0441\u0442\u044c\u00a0 <strong>ptr <\/strong>\u0431\u0443\u0434\u0435\u0442 <strong>true <\/strong>\u0442\u043e \u0432\u0435\u0441\u044c \u043d\u0430\u0448 \u043a\u043e\u0434 &#8212; \u044d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0432 \u043a\u0435\u0448 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0442\u044c.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 &#8212; \u0444\u0443\u043d\u043a\u0446\u0438\u044e <strong>c()<\/strong>:<\/p>\n<pre><code class=\"cpp\">bool c(bool ptr) {     if(ptr){             std::cout &lt;&lt; \" true )\" &lt;&lt; std::endl;             return true;         }     std::cout &lt;&lt; \" false (\" &lt;&lt; std::endl;     return false; }<\/code><\/pre>\n<p>\u0415\u0435 ASM \u0443\u0436\u0435 \u0434\u0440\u0443\u0433\u043e\u0439:<\/p>\n<details class=\"spoiler\">\n<summary>Hidden text<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"assembly\">c(bool):         push    rbp         mov     edx, 8         mov     ebp, edi         mov     esi, OFFSET FLAT:.LC1         push    rbx         sub     rsp, 8         test    dil, dil         je      .L55         mov     edx, 7         mov     esi, OFFSET FLAT:.LC0 .L55:         mov     edi, OFFSET FLAT:std::cout         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp; std::__ostream_insert&lt;char, std::char_traits&lt;char> >(std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp;, char const*, long)         mov     rax, QWORD PTR std::cout[rip]         mov     rax, QWORD PTR [rax-24]         mov     rbx, QWORD PTR std::cout[rax+240]         test    rbx, rbx         je      .L56         cmp     BYTE PTR [rbx+56], 0         je      .L41         movsx   esi, BYTE PTR [rbx+67] .L42:         mov     edi, OFFSET FLAT:std::cout         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >::put(char)         mov     rdi, rax         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >::flush()         add     rsp, 8         mov     eax, ebp         pop     rbx         pop     rbp         ret .L41:         mov     rdi, rbx         call    std::ctype&lt;char>::_M_widen_init() const         mov     rax, QWORD PTR [rbx]         mov     esi, 10         mov     rax, QWORD PTR [rax+48]         cmp     rax, OFFSET FLAT:std::ctype&lt;char>::do_widen(char) const         je      .L42         mov     rdi, rbx         call    rax         movsx   esi, al         jmp     .L42 .L56:         call    std::__throw_bad_cast() <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<pre><code class=\"assembly\">        mov     esi, OFFSET FLAT:.LC1         push    rbx         sub     rsp, 8         test    dil, dil         je      .L55         mov     edx, 7         mov     esi, OFFSET FLAT:.LC0 .L55:         mov     edi, OFFSET FLAT:std::cout<\/code><\/pre>\n<p>\u0412 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0434\u0430\u0436\u0435 \u0434\u043e <strong>\u0431\u043b\u043e\u043a\u0430 if<\/strong> \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0430<strong> .LC1<\/strong>, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f<strong>. string &#187; false (&#171;<\/strong>.\u00a0\u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0430\u043d\u0430\u043b\u0438\u0437 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 <strong>false <\/strong>\u043f\u0435\u0440\u0435\u043f\u0440\u044b\u0433\u0438\u0432\u0430\u0435\u043c \u0434\u0432\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0434\u0435\u043b\u0430\u0435\u043c \u0432\u044b\u0432\u043e\u0434 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d, \u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 <strong>true<\/strong> \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0435 \u0440\u0430\u043d\u0435\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043d\u0430 \u043c\u0435\u0442\u043a\u0443 <strong>.LC0<\/strong> \u0438 \u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435, \u0432\u044b\u0432\u043e\u0434\u044f \u043d\u0430 \u044d\u043a\u0440\u0430\u043d.\u00a0\u0412 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e\u0433\u043e \u043d\u0435 \u0441\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u043b\u044e\u0431\u043e\u0439 \u0440\u0430\u0441\u043a\u043b\u0430\u0434\u043a\u0435, \u0440\u0430\u0437\u0432\u0435 \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043b\u0438\u0448\u043d\u044f\u044f \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u044c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u0441\u0445\u043e\u0434\u0430. \u042d\u0442\u043e \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u0430\u043b\u0430. \u0412\u0438\u0434\u0438\u043c \u0442\u0430\u043a \u0436\u0435, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0437\u0434\u0435\u0441\u044c \u0432\u044b\u0431\u0440\u0430\u043b \u0434\u0440\u0443\u0433\u0443\u044e \u0432\u0435\u0442\u0432\u044c <em>if<\/em> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0430. <\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <strong>main <\/strong>\u0433\u0434\u0435 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u043c\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430\u043c\u0438 \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0430.<\/p>\n<pre><code class=\"cpp\">int main(int argc, char **argv) {     std::cout &lt;&lt; \" main\" &lt;&lt; std::endl;         if(__builtin_expect(b(true),1))     {         std::cout &lt;&lt; \" main true\" &lt;&lt; std::endl;     }      if(c(true))     {          std::cout &lt;&lt; \" main false\" &lt;&lt; std::endl;     }     return EXIT_SUCCESS; }<\/code><\/pre>\n<p>\u041d\u0430\u0447\u0430\u043b\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <strong>main <\/strong>\u0438 \u043f\u0435\u0440\u0432\u044b\u0439 <strong>if <\/strong>\u0433\u0435\u043d\u0435\u0440\u0438\u0442 \u0442\u0430\u043a\u043e\u0439 ASM \u043a\u043e\u0434:<\/p>\n<details class=\"spoiler\">\n<summary>Hidden text<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"assembly\">.LC2:         .string \" main\" .LC3:         .string \" main true\" .LC4:         .string \" main false\" main:         sub     rsp, 8         mov     esi, OFFSET FLAT:.LC2         mov     edi, OFFSET FLAT:std::cout         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp; std::operator&lt;&lt; &lt;std::char_traits&lt;char> >(std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp;, char const*)         mov     rdi, rax         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp; std::endl&lt;char, std::char_traits&lt;char> >(std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp;) [clone .isra.0]         mov     edi, 1         call    b(bool)         test    al, al         je      .L58         mov     edi, OFFSET FLAT:std::cout         mov     esi, OFFSET FLAT:.LC3         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp; std::operator&lt;&lt; &lt;std::char_traits&lt;char> >(std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp;, char const*)         mov     rdi, rax         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp; std::endl&lt;char, std::char_traits&lt;char> >(std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp;) [clone .isra.0] .L58:         mov     edi, 1         call    c(bool) <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0421\u0443\u0442\u044c \u0441\u0430\u043c\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438:<\/p>\n<pre><code class=\"assembly\">        call    b(bool)         test    al, al         je      .L58         mov     edi, OFFSET FLAT:std::cout mov     esi, OFFSET FLAT:.LC3<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 <strong>true <\/strong>\u0442\u043e \u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0443\u0441\u043b\u043e\u0432\u0438\u044e. <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 <strong>false <\/strong>\u0442\u043e \u043f\u0435\u0440\u0435\u043f\u0440\u044b\u0433\u0438\u0432\u0430\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a \u0438 \u0438\u0434\u0435\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0443\u0441\u043b\u043e\u0432\u0438\u044e. \u0412\u0441\u0435 \u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e.<\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u0442\u043e\u0440\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435:<\/p>\n<pre><code class=\"assembly\">.L58:         mov     edi, 1         call    c(bool)         test    al, al         jne     .L67 .L59:         xor     eax, eax         add     rsp, 8         ret .L67:         mov     esi, OFFSET FLAT:.LC4         mov     edi, OFFSET FLAT:std::cout         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp; std::operator&lt;&lt; &lt;std::char_traits&lt;char> >(std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp;, char const*)         mov     rdi, rax         call    std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp; std::endl&lt;char, std::char_traits&lt;char> >(std::basic_ostream&lt;char, std::char_traits&lt;char> >&amp;) [clone .isra.0]         jmp     .L59 <\/code><\/pre>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u0435, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 <strong>false <\/strong>\u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435 \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 <strong>true <\/strong>\u043f\u0440\u044b\u0433\u0430\u0435\u043c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430 <strong>.L67<\/strong> \u0433\u0434\u0435 \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0442\u0435\u043a\u0441\u0442, \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u044b\u0433\u0430\u0435\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043d\u0430 \u0442\u0440\u0435\u0442\u044c\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u043e\u0441\u043b\u0435 <strong>if <\/strong>\u0433\u0434\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0442\u0435\u043b\u043e \u0431\u043b\u043e\u043a\u0430 \u0441 <strong>true <\/strong>\u0431\u044b\u043b\u043e \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0433\u043e \u043c\u0435\u0442\u043a\u0430 <strong>.L67<\/strong>\u00a0\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0434\u0430\u043b\u0435\u043a\u043e \u043e\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u044f, \u043d\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u0432\u0441\u0435 \u0431\u043b\u043e\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0435 \u0432\u0441\u0435 \u0442\u0430\u043a \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e \u0432 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f\u0445. \u0412\u043e\u0437\u044c\u043c\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440: <a href=\"https:\/\/godbolt.org\/z\/3W9r1s3d8\">https:\/\/godbolt.org\/z\/3W9r1s3d8<\/a> . \u0414\u0432\u0435 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <strong>foo()<\/strong> \u0438 <strong>bar()<\/strong> \u043f\u043e\u0447\u0442\u0438 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c \u0442\u0435\u043b\u043e\u043c \u0438 \u043e\u0434\u043d\u0438\u043c \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c <strong>if<\/strong><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-351478","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/351478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=351478"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/351478\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=351478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=351478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=351478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}