#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_my(int, int *, int);
int binsearch_orig(int, int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
void main() {
  int i = 0;
  int arr[1000];
  int place = 0;
  int x = 0;
  int size = 0;
  for (i = 0; i < 1000; ++i) {
    arr[i] = i;
  }
  size = 1000;
  printf("Input please number you want find:");
  scanf("%d", &x);
  place = binsearch_orig(x, arr, size);
  printf("\nWe found you number in %d.\n", place);
  place = binsearch_my(x, arr, size);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfc0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xfb4(%rbp)
movl   $0x0,-0xfb8(%rbp)
movl   $0x0,-0xfbc(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x3e8,-0x4(%rbp)
jge    11a0 <main+0x60>
mov    -0x4(%rbp),%ecx
movslq -0x4(%rbp),%rax
mov    %ecx,-0xfb0(%rbp,%rax,4)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1177 <main+0x37>
movl   $0x3e8,-0xfbc(%rbp)
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe64(%rip),%rdi
lea    -0xfb8(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0xfb8(%rbp),%edi
lea    -0xfb0(%rbp),%rsi
mov    -0xfbc(%rbp),%edx
call   1050 <binsearch_orig@plt>
mov    %eax,-0xfb4(%rbp)
mov    -0xfb4(%rbp),%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xfb8(%rbp),%edi
lea    -0xfb0(%rbp),%rsi
mov    -0xfbc(%rbp),%edx
call   1040 <binsearch_my@plt>
mov    %eax,-0xfb4(%rbp)
add    $0xfc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xfb0,%rsp
movl   $0x0,0xc(%rsp)
movdqa 0xea8(%rip),%xmm0
xor    %eax,%eax
movdqa 0xead(%rip),%xmm8
movdqa 0xeb4(%rip),%xmm9
movdqa 0xebb(%rip),%xmm10
movdqa 0xec2(%rip),%xmm11
movdqa 0xec9(%rip),%xmm12
movdqa 0xed1(%rip),%xmm6
movdqa 0xed9(%rip),%xmm7
movdqa 0xee1(%rip),%xmm1
movdqa 0xee9(%rip),%xmm2
movdqa 0xef1(%rip),%xmm3
nop
movdqa %xmm0,%xmm4
paddd  %xmm8,%xmm4
movdqa %xmm0,0x10(%rsp,%rax,4)
movdqa %xmm4,0x20(%rsp,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm9,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm10,%xmm5
movdqa %xmm4,0x30(%rsp,%rax,4)
movdqa %xmm5,0x40(%rsp,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm11,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm12,%xmm5
movdqa %xmm4,0x50(%rsp,%rax,4)
movdqa %xmm5,0x60(%rsp,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm6,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm7,%xmm5
movdqa %xmm4,0x70(%rsp,%rax,4)
movdqa %xmm5,0x80(%rsp,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm1,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
movdqa %xmm4,0x90(%rsp,%rax,4)
movdqa %xmm5,0xa0(%rsp,%rax,4)
add    $0x28,%rax
paddd  %xmm3,%xmm0
cmp    $0x3e8,%rax
jne    11b0 <main+0x70>
lea    0xe53(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe68(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x3e8,%edx
call   1050 <binsearch_orig@plt>
lea    0xe44(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x3e8,%edx
call   1040 <binsearch_my@plt>
add    $0xfb0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [35 x i8] c"Input please number you want find:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [29 x i8] c"\0AWe found you number in %d.\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca [1000 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %1
br label %6
6: ; preds = %14, %0
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 1000
br i1 %8, label %9, label %17
9: ; preds = %6
%10 = load i32, i32* %1
%11 = load i32, i32* %1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %12
store i32 %10, i32* %13
br label %14
14: ; preds = %9
%15 = load i32, i32* %1
%16 = add nsw i32 %15, 1
store i32 %16, i32* %1
br label %6
17: ; preds = %6
store i32 1000, i32* %5
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%20 = load i32, i32* %4
%21 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 0
%22 = load i32, i32* %5
%23 = call i32 @binsearch_orig(i32 %20, i32* %21, i32 %22)
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %4
%27 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 0
%28 = load i32, i32* %5
%29 = call i32 @binsearch_my(i32 %26, i32* %27, i32 %28)
store i32 %29, i32* %3
ret void
}

LLVM IR (-O2):
@.str = [35 x i8] c"Input please number you want find:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [29 x i8] c"\0AWe found you number in %d.\0A\00"
define void @main() {
%1 = alloca [1000 x i32]
%2 = alloca i32
%3 = bitcast [1000 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
br label %5
5: ; preds = %5, %0
%6 = phi i64 [ 0, %0 ], [ %41, %5 ]
%7 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %0 ], [ %42, %5 ]
%8 = add <4 x i32> %7, <i32 4, i32 4, i32 4, i32 4>
%9 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %6
%10 = bitcast i32* %9 to <4 x i32>*
store <4 x i32> %7, <4 x i32>* %10
%11 = getelementptr inbounds i32, i32* %9, i64 4
%12 = bitcast i32* %11 to <4 x i32>*
store <4 x i32> %8, <4 x i32>* %12
%13 = add nuw nsw i64 %6, 8
%14 = add <4 x i32> %7, <i32 8, i32 8, i32 8, i32 8>
%15 = add <4 x i32> %7, <i32 12, i32 12, i32 12, i32 12>
%16 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %13
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> %14, <4 x i32>* %17
%18 = getelementptr inbounds i32, i32* %16, i64 4
%19 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> %15, <4 x i32>* %19
%20 = add nuw nsw i64 %6, 16
%21 = add <4 x i32> %7, <i32 16, i32 16, i32 16, i32 16>
%22 = add <4 x i32> %7, <i32 20, i32 20, i32 20, i32 20>
%23 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %20
%24 = bitcast i32* %23 to <4 x i32>*
store <4 x i32> %21, <4 x i32>* %24
%25 = getelementptr inbounds i32, i32* %23, i64 4
%26 = bitcast i32* %25 to <4 x i32>*
store <4 x i32> %22, <4 x i32>* %26
%27 = add nuw nsw i64 %6, 24
%28 = add <4 x i32> %7, <i32 24, i32 24, i32 24, i32 24>
%29 = add <4 x i32> %7, <i32 28, i32 28, i32 28, i32 28>
%30 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %27
%31 = bitcast i32* %30 to <4 x i32>*
store <4 x i32> %28, <4 x i32>* %31
%32 = getelementptr inbounds i32, i32* %30, i64 4
%33 = bitcast i32* %32 to <4 x i32>*
store <4 x i32> %29, <4 x i32>* %33
%34 = add nuw nsw i64 %6, 32
%35 = add <4 x i32> %7, <i32 32, i32 32, i32 32, i32 32>
%36 = add <4 x i32> %7, <i32 36, i32 36, i32 36, i32 36>
%37 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %34
%38 = bitcast i32* %37 to <4 x i32>*
store <4 x i32> %35, <4 x i32>* %38
%39 = getelementptr inbounds i32, i32* %37, i64 4
%40 = bitcast i32* %39 to <4 x i32>*
store <4 x i32> %36, <4 x i32>* %40
%41 = add nuw nsw i64 %6, 40
%42 = add <4 x i32> %7, <i32 40, i32 40, i32 40, i32 40>
%43 = icmp eq i64 %41, 1000
br i1 %43, label %44, label %5
44: ; preds = %5
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%46 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%47 = load i32, i32* %2
%48 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 0
%49 = call i32 @binsearch_orig(i32 %47, i32* %48, i32 1000)
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %49)
%51 = load i32, i32* %2
%52 = call i32 @binsearch_my(i32 %51, i32* %48, i32 1000)
ret void
}