#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 */
typedef int /*<<< orphan*/ w;

/* Variables and functions */
int binsearch1(int, int *, int);
int binsearch2(int, int *, int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int w[] = {0, 1, 3, 6, 10, 15, 21, 28, 36};
  int m = sizeof(w) / sizeof(int);
  int i1, i2;
  int j1, j2;
  int k1, k2;
  i1 = binsearch1(3, w, m);
  printf("%d\n", i1);
  i2 = binsearch2(3, w, m);
  printf("%d\n", i2);
  j1 = binsearch1(21, w, m);
  printf("%d\n", j1);
  j2 = binsearch2(21, w, m);
  printf("%d\n", j2);
  k1 = binsearch1(5, w, m);
  printf("%d\n", k1);
  k2 = binsearch2(5, w, m);
  printf("%d\n", k2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xea6(%rip),%rsi
mov    $0x24,%edx
call   1050 <memcpy@plt>
movl   $0x9,-0x34(%rbp)
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    $0x3,%edi
call   1060 <binsearch1@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%esi
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    $0x3,%edi
call   1040 <binsearch2@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%esi
lea    0xe78(%rip),%rdi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    $0x15,%edi
call   1060 <binsearch1@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%esi
lea    0xe55(%rip),%rdi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    $0x15,%edi
call   1040 <binsearch2@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%esi
lea    0xe32(%rip),%rdi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    $0x5,%edi
call   1060 <binsearch1@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%esi
lea    0xe0f(%rip),%rdi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    $0x5,%edi
call   1040 <binsearch2@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%esi
lea    0xdec(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0xee3(%rip),%eax
mov    %eax,0x20(%rsp)
movaps 0xec8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeac(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%r14
mov    $0x3,%edi
mov    %r14,%rsi
mov    $0x9,%edx
call   1050 <binsearch1@plt>
lea    0xeb0(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x3,%edi
mov    %r14,%rsi
mov    $0x9,%edx
call   1040 <binsearch2@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x15,%edi
mov    %r14,%rsi
mov    $0x9,%edx
call   1050 <binsearch1@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x15,%edi
mov    %r14,%rsi
mov    $0x9,%edx
call   1040 <binsearch2@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x5,%edi
mov    %r14,%rsi
mov    $0x9,%edx
call   1050 <binsearch1@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x5,%edi
mov    %r14,%rsi
mov    $0x9,%edx
call   1040 <binsearch2@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

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

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