#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 /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ run_test(unsigned int);
int main(void) {
  unsigned int mask = 1;
  unsigned int i;
  printf("first_leading_bit unit test \n\n");
  run_test(0);
  for (i = 0; i < 32; i++) {
    run_test(mask);
    mask <<= 1;
  }
  mask = 1;
  for (i = 0; i < 33; i++) {
    run_test(mask - 1);
    mask <<= 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
lea    0xec3(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <run_test@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x20,-0xc(%rbp)
jae    1179 <main+0x59>
mov    -0x8(%rbp),%edi
call   1040 <run_test@plt>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1150 <main+0x30>
movl   $0x1,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x21,-0xc(%rbp)
jae    11b3 <main+0x93>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
call   1040 <run_test@plt>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1187 <main+0x67>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xed6(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1040 <run_test@plt>
mov    $0x1,%ebx
mov    $0x1,%edi
call   1040 <run_test@plt>
mov    $0x2,%edi
call   1040 <run_test@plt>
mov    $0x4,%edi
call   1040 <run_test@plt>
mov    $0x8,%edi
call   1040 <run_test@plt>
mov    $0x10,%edi
call   1040 <run_test@plt>
mov    $0x20,%edi
call   1040 <run_test@plt>
mov    $0x40,%edi
call   1040 <run_test@plt>
mov    $0x80,%edi
call   1040 <run_test@plt>
mov    $0x100,%edi
call   1040 <run_test@plt>
mov    $0x200,%edi
call   1040 <run_test@plt>
mov    $0x400,%edi
call   1040 <run_test@plt>
mov    $0x800,%edi
call   1040 <run_test@plt>
mov    $0x1000,%edi
call   1040 <run_test@plt>
mov    $0x2000,%edi
call   1040 <run_test@plt>
mov    $0x4000,%edi
call   1040 <run_test@plt>
mov    $0x8000,%edi
call   1040 <run_test@plt>
mov    $0x10000,%edi
call   1040 <run_test@plt>
mov    $0x20000,%edi
call   1040 <run_test@plt>
mov    $0x40000,%edi
call   1040 <run_test@plt>
mov    $0x80000,%edi
call   1040 <run_test@plt>
mov    $0x100000,%edi
call   1040 <run_test@plt>
mov    $0x200000,%edi
call   1040 <run_test@plt>
mov    $0x400000,%edi
call   1040 <run_test@plt>
mov    $0x800000,%edi
call   1040 <run_test@plt>
mov    $0x1000000,%edi
call   1040 <run_test@plt>
mov    $0x2000000,%edi
call   1040 <run_test@plt>
mov    $0x4000000,%edi
call   1040 <run_test@plt>
mov    $0x8000000,%edi
call   1040 <run_test@plt>
mov    $0x10000000,%edi
call   1040 <run_test@plt>
mov    $0x20000000,%edi
call   1040 <run_test@plt>
mov    $0x40000000,%edi
call   1040 <run_test@plt>
mov    $0x80000000,%edi
call   1040 <run_test@plt>
mov    $0x21,%ebp
lea    -0x1(%rbx),%edi
call   1040 <run_test@plt>
add    %ebx,%ebx
add    $0xffffffff,%ebp
jne    1280 <main+0x160>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"first_leading_bit unit test \0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %2
%4 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @run_test(i32 0)
store i32 0, i32* %3
br label %6
6: ; preds = %14, %0
%7 = load i32, i32* %3
%8 = icmp ult i32 %7, 32
br i1 %8, label %9, label %17
9: ; preds = %6
%10 = load i32, i32* %2
%11 = call i32 @run_test(i32 %10)
%12 = load i32, i32* %2
%13 = shl i32 %12, 1
store i32 %13, i32* %2
br label %14
14: ; preds = %9
%15 = load i32, i32* %3
%16 = add i32 %15, 1
store i32 %16, i32* %3
br label %6
17: ; preds = %6
store i32 1, i32* %2
store i32 0, i32* %3
br label %18
18: ; preds = %27, %17
%19 = load i32, i32* %3
%20 = icmp ult i32 %19, 33
br i1 %20, label %21, label %30
21: ; preds = %18
%22 = load i32, i32* %2
%23 = sub i32 %22, 1
%24 = call i32 @run_test(i32 %23)
%25 = load i32, i32* %2
%26 = shl i32 %25, 1
store i32 %26, i32* %2
br label %27
27: ; preds = %21
%28 = load i32, i32* %3
%29 = add i32 %28, 1
store i32 %29, i32* %3
br label %18
30: ; preds = %18
ret i32 0
}

LLVM IR (-O2):
@str = [30 x i8] c"first_leading_bit unit test \0A\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @run_test(i32 0)
%3 = tail call i32 @run_test(i32 1)
%4 = tail call i32 @run_test(i32 2)
%5 = tail call i32 @run_test(i32 4)
%6 = tail call i32 @run_test(i32 8)
%7 = tail call i32 @run_test(i32 16)
%8 = tail call i32 @run_test(i32 32)
%9 = tail call i32 @run_test(i32 64)
%10 = tail call i32 @run_test(i32 128)
%11 = tail call i32 @run_test(i32 256)
%12 = tail call i32 @run_test(i32 512)
%13 = tail call i32 @run_test(i32 1024)
%14 = tail call i32 @run_test(i32 2048)
%15 = tail call i32 @run_test(i32 4096)
%16 = tail call i32 @run_test(i32 8192)
%17 = tail call i32 @run_test(i32 16384)
%18 = tail call i32 @run_test(i32 32768)
%19 = tail call i32 @run_test(i32 65536)
%20 = tail call i32 @run_test(i32 131072)
%21 = tail call i32 @run_test(i32 262144)
%22 = tail call i32 @run_test(i32 524288)
%23 = tail call i32 @run_test(i32 1048576)
%24 = tail call i32 @run_test(i32 2097152)
%25 = tail call i32 @run_test(i32 4194304)
%26 = tail call i32 @run_test(i32 8388608)
%27 = tail call i32 @run_test(i32 16777216)
%28 = tail call i32 @run_test(i32 33554432)
%29 = tail call i32 @run_test(i32 67108864)
%30 = tail call i32 @run_test(i32 134217728)
%31 = tail call i32 @run_test(i32 268435456)
%32 = tail call i32 @run_test(i32 536870912)
%33 = tail call i32 @run_test(i32 1073741824)
%34 = tail call i32 @run_test(i32 -2147483648)
br label %35
35: ; preds = %0, %35
%36 = phi i32 [ %41, %35 ], [ 0, %0 ]
%37 = phi i32 [ %40, %35 ], [ 1, %0 ]
%38 = add i32 %37, -1
%39 = tail call i32 @run_test(i32 %38)
%40 = shl i32 %37, 1
%41 = add nuw nsw i32 %36, 1
%42 = icmp eq i32 %41, 33
br i1 %42, label %43, label %35
43: ; preds = %35
ret i32 0
}