#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 binary_num(int);
int check_low_bit(void *p) {
  int i = 1;
  int t = ((uintptr_t)p);
  int b;
  while (i <= 60) {
    i++;
    b = binary_num(i);
    if ((t & b) != 0) {
      return i - 1;
    }
  }
  return i - 1;
}


x86 assembly (clang, -O0):
<check_low_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,-0x18(%rbp)
cmpl   $0x3c,-0x14(%rbp)
jg     116a <check_low_bit+0x5a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <binary_num@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
and    -0x1c(%rbp),%eax
cmp    $0x0,%eax
je     1165 <check_low_bit+0x55>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1173 <check_low_bit+0x63>
jmp    112a <check_low_bit+0x1a>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_low_bit>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
cmp    $0x3c,%ebx
je     1137 <check_low_bit+0x27>
lea    0x2(%rbx),%edi
call   1030 <binary_num@plt>
add    $0x1,%ebx
test   %r14d,%eax
je     1120 <check_low_bit+0x10>
jmp    113c <check_low_bit+0x2c>
mov    $0x3c,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @check_low_bit(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 1, i32* %4
%7 = load i8*, i8** %3
%8 = ptrtoint i8* %7 to i64
%9 = trunc i64 %8 to i32
store i32 %9, i32* %5
br label %10
10: ; preds = %25, %1
%11 = load i32, i32* %4
%12 = icmp sle i32 %11, 60
br i1 %12, label %13, label %26
13: ; preds = %10
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 1
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = call i32 @binary_num(i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %5
%19 = load i32, i32* %6
%20 = and i32 %18, %19
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %13
%23 = load i32, i32* %4
%24 = sub nsw i32 %23, 1
store i32 %24, i32* %2
br label %29
25: ; preds = %13
br label %10
26: ; preds = %10
%27 = load i32, i32* %4
%28 = sub nsw i32 %27, 1
store i32 %28, i32* %2
br label %29
29: ; preds = %26, %22
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
define i32 @check_low_bit(i8* %0) {
%2 = ptrtoint i8* %0 to i64
%3 = trunc i64 %2 to i32
br label %4
4: ; preds = %7, %1
%5 = phi i32 [ 1, %1 ], [ %8, %7 ]
%6 = icmp eq i32 %5, 61
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = add nuw nsw i32 %5, 1
%9 = tail call i32 @binary_num(i32 %8)
%10 = and i32 %9, %3
%11 = icmp eq i32 %10, 0
br i1 %11, label %4, label %12
12: ; preds = %7, %4
%13 = phi i32 [ 60, %4 ], [ %5, %7 ]
ret i32 %13
}