#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 iterative_binary_search(int *, int, int /*<<< orphan*/, int);
int /*<<< orphan*/ print(int *, int);
int /*<<< orphan*/ printf(char *, int, int);
int search(int *, int, int /*<<< orphan*/, int);
int main() {
  int size = 10;
  int list[10] = {0, 1, 3, 5, 7, 11, 13, 17, 19, 23};
  print(list, size);
  printf("pos of %d is %d\n", 3, search(list, 3, 0, size - 1));
  printf("pos of %d is %d\n", 11,
         iterative_binary_search(list, 11, 0, size - 1));
  printf("pos of %d is %d\n", 18, search(list, 18, 0, size - 1));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xe8f(%rip),%rsi
mov    $0x28,%edx
call   1060 <memcpy@plt>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <print@plt>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x3,%esi
xor    %edx,%edx
call   1040 <search@plt>
mov    %eax,%edx
lea    0xe82(%rip),%rdi
mov    $0x3,%esi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
mov    $0xb,%esi
xor    %edx,%edx
call   1070 <iterative_binary_search@plt>
mov    %eax,%edx
lea    0xe59(%rip),%rdi
mov    $0xb,%esi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x12,%esi
xor    %edx,%edx
call   1040 <search@plt>
mov    %eax,%edx
lea    0xe30(%rip),%rdi
mov    $0x12,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0xed2(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xeb6(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe9a(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <print@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %edx,%edx
mov    $0x9,%ecx
call   1040 <search@plt>
lea    0xe93(%rip),%r14
mov    %r14,%rdi
mov    $0x3,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xb,%esi
xor    %edx,%edx
mov    $0x9,%ecx
call   1060 <iterative_binary_search@plt>
mov    %r14,%rdi
mov    $0xb,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x12,%esi
xor    %edx,%edx
mov    $0x9,%ecx
call   1040 <search@plt>
mov    %r14,%rdi
mov    $0x12,%esi
mov    %eax,%edx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.list = [10 x i32] [i32 0, i32 1, i32 3, i32 5, i32 7, i32 11, i32 13, i32 17, i32 19, i32 23]
@.str = [17 x i8] c"pos of %d is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [10 x i32]
store i32 0, i32* %1
store i32 10, i32* %2
%4 = bitcast [10 x i32]* %3 to i8*
%5 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%6 = load i32, i32* %2
%7 = call i32 @print(i32* %5, i32 %6)
%8 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%9 = load i32, i32* %2
%10 = sub nsw i32 %9, 1
%11 = call i32 @search(i32* %8, i32 3, i32 0, i32 %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 3, i32 %11)
%13 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%14 = load i32, i32* %2
%15 = sub nsw i32 %14, 1
%16 = call i32 @iterative_binary_search(i32* %13, i32 11, i32 0, i32 %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 11, i32 %16)
%18 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%19 = load i32, i32* %2
%20 = sub nsw i32 %19, 1
%21 = call i32 @search(i32* %18, i32 18, i32 0, i32 %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 18, i32 %21)
ret i32 0
}

LLVM IR (-O2):
@__const.main.list = [10 x i32] [i32 0, i32 1, i32 3, i32 5, i32 7, i32 11, i32 13, i32 17, i32 19, i32 23]
@.str = [17 x i8] c"pos of %d is %d\0A\00"
define i32 @main() {
%1 = alloca [10 x i32]
%2 = bitcast [10 x i32]* %1 to i8*
%3 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%4 = call i32 @print(i32* %3, i32 10)
%5 = call i32 @search(i32* %3, i32 3, i32 0, i32 9)
%6 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 3, i32 %5)
%7 = call i32 @iterative_binary_search(i32* %3, i32 11, i32 0, i32 9)
%8 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 11, i32 %7)
%9 = call i32 @search(i32* %3, i32 18, i32 0, i32 9)
%10 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 18, i32 %9)
ret i32 0
}