#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int count_twos(int);
int count_twos_brute(int);
int test_with_twos() {
  return 1 == count_twos_brute(11) && 1 == count_twos(11) &&
         2 == count_twos_brute(19) && 2 == count_twos(19) &&
         6 == count_twos_brute(22) && 6 == count_twos(22) &&
         175 == count_twos_brute(342) && 175 == count_twos(342);
}


x86 assembly (clang, -O0):
<test_with_twos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0xb,%edi
call   1030 <count_twos_brute@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    %edx,%ecx
mov    %al,-0x1(%rbp)
jne    1213 <test_with_twos+0xf3>
mov    $0xb,%edi
call   1040 <count_twos@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    %edx,%ecx
mov    %al,-0x1(%rbp)
jne    1213 <test_with_twos+0xf3>
mov    $0x13,%edi
call   1030 <count_twos_brute@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    $0x2,%ecx
cmp    %edx,%ecx
mov    %al,-0x1(%rbp)
jne    1213 <test_with_twos+0xf3>
mov    $0x13,%edi
call   1040 <count_twos@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    $0x2,%ecx
cmp    %edx,%ecx
mov    %al,-0x1(%rbp)
jne    1213 <test_with_twos+0xf3>
mov    $0x16,%edi
call   1030 <count_twos_brute@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    $0x6,%ecx
cmp    %edx,%ecx
mov    %al,-0x1(%rbp)
jne    1213 <test_with_twos+0xf3>
mov    $0x16,%edi
call   1040 <count_twos@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    $0x6,%ecx
cmp    %edx,%ecx
mov    %al,-0x1(%rbp)
jne    1213 <test_with_twos+0xf3>
mov    $0x156,%edi
call   1030 <count_twos_brute@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    $0xaf,%ecx
cmp    %edx,%ecx
mov    %al,-0x1(%rbp)
jne    1213 <test_with_twos+0xf3>
mov    $0x156,%edi
call   1040 <count_twos@plt>
mov    %eax,%ecx
mov    $0xaf,%eax
cmp    %ecx,%eax
sete   %al
mov    %al,-0x1(%rbp)
mov    -0x1(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_with_twos>:
push   %rbx
mov    $0xb,%edi
call   1030 <count_twos_brute@plt>
xor    %ebx,%ebx
cmp    $0x1,%eax
jne    11a2 <test_with_twos+0x82>
mov    $0xb,%edi
call   1040 <count_twos@plt>
cmp    $0x1,%eax
jne    11a2 <test_with_twos+0x82>
mov    $0x13,%edi
call   1030 <count_twos_brute@plt>
cmp    $0x2,%eax
jne    11a2 <test_with_twos+0x82>
mov    $0x13,%edi
call   1040 <count_twos@plt>
cmp    $0x2,%eax
jne    11a2 <test_with_twos+0x82>
mov    $0x16,%edi
call   1030 <count_twos_brute@plt>
cmp    $0x6,%eax
jne    11a2 <test_with_twos+0x82>
mov    $0x16,%edi
call   1040 <count_twos@plt>
cmp    $0x6,%eax
jne    11a2 <test_with_twos+0x82>
mov    $0x156,%edi
call   1030 <count_twos_brute@plt>
cmp    $0xaf,%eax
jne    11a2 <test_with_twos+0x82>
mov    $0x156,%edi
call   1040 <count_twos@plt>
xor    %ebx,%ebx
cmp    $0xaf,%eax
sete   %bl
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @test_with_twos() {
%1 = call i32 @count_twos_brute(i32 11)
%2 = icmp eq i32 1, %1
br i1 %2, label %3, label %24
3: ; preds = %0
%4 = call i32 @count_twos(i32 11)
%5 = icmp eq i32 1, %4
br i1 %5, label %6, label %24
6: ; preds = %3
%7 = call i32 @count_twos_brute(i32 19)
%8 = icmp eq i32 2, %7
br i1 %8, label %9, label %24
9: ; preds = %6
%10 = call i32 @count_twos(i32 19)
%11 = icmp eq i32 2, %10
br i1 %11, label %12, label %24
12: ; preds = %9
%13 = call i32 @count_twos_brute(i32 22)
%14 = icmp eq i32 6, %13
br i1 %14, label %15, label %24
15: ; preds = %12
%16 = call i32 @count_twos(i32 22)
%17 = icmp eq i32 6, %16
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = call i32 @count_twos_brute(i32 342)
%20 = icmp eq i32 175, %19
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = call i32 @count_twos(i32 342)
%23 = icmp eq i32 175, %22
br label %24
24: ; preds = %21, %18, %15, %12, %9, %6, %3, %0
%25 = phi i1 [ false, %18 ], [ false, %15 ], [ false, %12 ], [ false, %9 ], [ false, %6 ], [ false, %3 ], [ false, %0 ], [ %23, %21 ]
%26 = zext i1 %25 to i32
ret i32 %26
}

LLVM IR (-O2):
define i32 @test_with_twos() {
%1 = tail call i32 @count_twos_brute(i32 11)
%2 = icmp eq i32 %1, 1
br i1 %2, label %3, label %25
3: ; preds = %0
%4 = tail call i32 @count_twos(i32 11)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %25
6: ; preds = %3
%7 = tail call i32 @count_twos_brute(i32 19)
%8 = icmp eq i32 %7, 2
br i1 %8, label %9, label %25
9: ; preds = %6
%10 = tail call i32 @count_twos(i32 19)
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %25
12: ; preds = %9
%13 = tail call i32 @count_twos_brute(i32 22)
%14 = icmp eq i32 %13, 6
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = tail call i32 @count_twos(i32 22)
%17 = icmp eq i32 %16, 6
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = tail call i32 @count_twos_brute(i32 342)
%20 = icmp eq i32 %19, 175
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = tail call i32 @count_twos(i32 342)
%23 = icmp eq i32 %22, 175
%24 = zext i1 %23 to i32
br label %25
25: ; preds = %21, %18, %15, %12, %9, %6, %3, %0
%26 = phi i32 [ 0, %18 ], [ 0, %15 ], [ 0, %12 ], [ 0, %9 ], [ 0, %6 ], [ 0, %3 ], [ 0, %0 ], [ %24, %21 ]
ret i32 %26
}