#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 binsearch(int *, int, int);
int /*<<< orphan*/ printf(char *, int, int);
int main(void) {
  int x[] = {1, 2, 3};
  int i, j;
  for (i = 0; i < 3; i++) {
    printf("%d in pos %d\n", x[i], binsearch(x, x[i], 3));
  }
  for (j = 4; j < 6; j++) {
    printf("%d in pos %d\n", j, binsearch(x, j, 3));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xec8(%rip),%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    1194 <main+0x74>
movslq -0x14(%rbp),%rax
mov    -0x10(%rbp,%rax,4),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
mov    -0x10(%rbp,%rax,4),%esi
mov    $0x3,%edx
call   1030 <binsearch@plt>
mov    -0x1c(%rbp),%esi
mov    %eax,%edx
lea    0xe8b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114a <main+0x2a>
movl   $0x4,-0x18(%rbp)
cmpl   $0x6,-0x18(%rbp)
jge    11db <main+0xbb>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
lea    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    $0x3,%edx
call   1030 <binsearch@plt>
mov    -0x20(%rbp),%esi
mov    %eax,%edx
lea    0xe44(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119b <main+0x7b>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0xeda(%rip),%eax
mov    %eax,0x8(%rsp)
mov    0xec7(%rip),%rax
mov    %rax,(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x3,%edx
call   1030 <binsearch@plt>
lea    0xeb3(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    0x4(%rsp),%ebp
mov    %r14,%rdi
mov    %ebp,%esi
mov    $0x3,%edx
call   1030 <binsearch@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    0x8(%rsp),%ebp
mov    %r14,%rdi
mov    %ebp,%esi
mov    $0x3,%edx
call   1030 <binsearch@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x3,%edx
call   1030 <binsearch@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x5,%esi
mov    $0x3,%edx
call   1030 <binsearch@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.x = [3 x i32] [i32 1, i32 2, i32 3]
@.str = [14 x i8] c"%d in pos %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [3 x i32]* %2 to i8*
store i32 0, i32* %3
br label %6
6: ; preds = %21, %0
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %24
9: ; preds = %6
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 %16
%18 = load i32, i32* %17
%19 = call i32 @binsearch(i32* %14, i32 %18, i32 3)
%20 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %19)
br label %21
21: ; preds = %9
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %6
24: ; preds = %6
store i32 4, i32* %4
br label %25
25: ; preds = %34, %24
%26 = load i32, i32* %4
%27 = icmp slt i32 %26, 6
br i1 %27, label %28, label %37
28: ; preds = %25
%29 = load i32, i32* %4
%30 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%31 = load i32, i32* %4
%32 = call i32 @binsearch(i32* %30, i32 %31, i32 3)
%33 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %29, i32 %32)
br label %34
34: ; preds = %28
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %25
37: ; preds = %25
ret i32 0
}

LLVM IR (-O2):
@__const.main.x = [3 x i32] [i32 1, i32 2, i32 3]
@.str = [14 x i8] c"%d in pos %d\0A\00"
define i32 @main() {
%1 = alloca [3 x i32]
%2 = bitcast [3 x i32]* %1 to i8*
%3 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%4 = call i32 @binsearch(i32* %3, i32 1, i32 3)
%5 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 1, i32 %4)
%6 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 1
%7 = load i32, i32* %6
%8 = call i32 @binsearch(i32* %3, i32 %7, i32 3)
%9 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %8)
%10 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 2
%11 = load i32, i32* %10
%12 = call i32 @binsearch(i32* %3, i32 %11, i32 3)
%13 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12)
%14 = call i32 @binsearch(i32* %3, i32 4, i32 3)
%15 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 4, i32 %14)
%16 = call i32 @binsearch(i32* %3, i32 5, i32 3)
%17 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 5, i32 %16)
ret i32 0
}