#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 binsrch(int *, int, int);
int /*<<< orphan*/ printf(char *, int, int, int);
int main() {
  int x[] = {1, 2, 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 22, 13, 54321, 22223};
  printf("%d %d %d\n", binsrch(x, 2, 16), binsrch(x, 20, 16),
         binsrch(x, 54321, 16));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
lea    -0x50(%rbp),%rdi
mov    $0x2,%esi
mov    $0x10,%edx
call   1040 <binsrch@plt>
mov    %eax,-0x58(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x14,%esi
mov    $0x10,%edx
call   1040 <binsrch@plt>
mov    %eax,-0x54(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0xd431,%esi
mov    $0x10,%edx
call   1040 <binsrch@plt>
mov    -0x58(%rbp),%esi
mov    -0x54(%rbp),%edx
mov    %eax,%ecx
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
movaps 0xf01(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xee5(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xec9(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xead(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x10,%edx
call   1040 <binsrch@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
mov    $0x14,%esi
mov    $0x10,%edx
call   1040 <binsrch@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0xd431,%esi
mov    $0x10,%edx
call   1040 <binsrch@plt>
lea    0xea4(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %eax,%ecx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.x = [16 x i32] [i32 1, i32 2, i32 2, i32 2, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 22, i32 13, i32 54321, i32 22223]
@.str = [10 x i8] c"%d %d %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [16 x i32]
store i32 0, i32* %1
%3 = bitcast [16 x i32]* %2 to i8*
%4 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%5 = call i32 @binsrch(i32* %4, i32 2, i32 16)
%6 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%7 = call i32 @binsrch(i32* %6, i32 20, i32 16)
%8 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%9 = call i32 @binsrch(i32* %8, i32 54321, i32 16)
%10 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %7, i32 %9)
ret i32 0
}

LLVM IR (-O2):
@__const.main.x = [16 x i32] [i32 1, i32 2, i32 2, i32 2, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 22, i32 13, i32 54321, i32 22223]
@.str = [10 x i8] c"%d %d %d\0A\00"
define i32 @main() {
%1 = alloca [16 x i32]
%2 = bitcast [16 x i32]* %1 to i8*
%3 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 0
%4 = call i32 @binsrch(i32* %3, i32 2, i32 16)
%5 = call i32 @binsrch(i32* %3, i32 20, i32 16)
%6 = call i32 @binsrch(i32* %3, i32 54321, i32 16)
%7 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %5, i32 %6)
ret i32 0
}