#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 binary_search(int *, int, int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int array[100], i, j;
  for (i = 0; i < 100; i++)
    array[i] = i * 2 + i / 2;
  j = binary_search(array, 100, 42);
  printf("value 42 is stored in array[%2d]\n", j);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1a4(%rbp)
cmpl   $0x64,-0x1a4(%rbp)
jge    1184 <main+0x64>
mov    -0x1a4(%rbp),%ecx
shl    $0x1,%ecx
mov    -0x1a4(%rbp),%eax
mov    $0x2,%esi
cltd
idiv   %esi
add    %eax,%ecx
movslq -0x1a4(%rbp),%rax
mov    %ecx,-0x1a0(%rbp,%rax,4)
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    113c <main+0x1c>
lea    -0x1a0(%rbp),%rdi
mov    $0x64,%esi
mov    $0x2a,%edx
call   1040 <binary_search@plt>
mov    %eax,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%esi
lea    0xe53(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x198,%rsp
movdqa 0xed1(%rip),%xmm0
mov    $0x4,%eax
movdqa 0xed4(%rip),%xmm1
movdqa 0xedc(%rip),%xmm2
movdqa %xmm0,%xmm3
nopl   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm5
psrld  $0x1,%xmm5
movdqa %xmm3,%xmm4
paddd  %xmm3,%xmm4
paddd  %xmm4,%xmm5
movdqa %xmm5,-0x10(%rsp,%rax,4)
cmp    $0x64,%rax
je     1199 <main+0x79>
movdqa %xmm0,%xmm5
paddd  %xmm1,%xmm5
psrld  $0x1,%xmm5
paddd  %xmm2,%xmm4
paddd  %xmm5,%xmm4
movdqa %xmm4,(%rsp,%rax,4)
paddd  %xmm2,%xmm0
paddd  %xmm2,%xmm3
add    $0x8,%rax
jmp    1150 <main+0x30>
mov    %rsp,%rdi
mov    $0x64,%esi
mov    $0x2a,%edx
call   1040 <binary_search@plt>
lea    0xe7e(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x198,%rsp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"value 42 is stored in array[%2d]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %5
5: ; preds = %17, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 100
br i1 %7, label %8, label %20
8: ; preds = %5
%9 = load i32, i32* %3
%10 = mul nsw i32 %9, 2
%11 = load i32, i32* %3
%12 = sdiv i32 %11, 2
%13 = add nsw i32 %10, %12
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %15
store i32 %13, i32* %16
br label %17
17: ; preds = %8
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %5
20: ; preds = %5
%21 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%22 = call i32 @binary_search(i32* %21, i32 100, i32 42)
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %23)
ret i32 0
}

LLVM IR (-O2):
@.str = [34 x i8] c"value 42 is stored in array[%2d]\0A\00"
define i32 @main() {
%1 = alloca [100 x i32]
%2 = bitcast [100 x i32]* %1 to i8*
br label %3
3: ; preds = %14, %0
%4 = phi i64 [ 0, %0 ], [ %22, %14 ]
%5 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %0 ], [ %23, %14 ]
%6 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %0 ], [ %24, %14 ]
%7 = lshr <4 x i32> %5, <i32 1, i32 1, i32 1, i32 1>
%8 = shl <4 x i32> %6, <i32 1, i32 1, i32 1, i32 1>
%9 = add nuw nsw <4 x i32> %8, %7
%10 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %4
%11 = bitcast i32* %10 to <4 x i32>*
store <4 x i32> %9, <4 x i32>* %11
%12 = or i64 %4, 4
%13 = icmp eq i64 %12, 100
br i1 %13, label %25, label %14
14: ; preds = %3
%15 = add <4 x i32> %5, <i32 4, i32 4, i32 4, i32 4>
%16 = lshr <4 x i32> %15, <i32 1, i32 1, i32 1, i32 1>
%17 = shl <4 x i32> %6, <i32 1, i32 1, i32 1, i32 1>
%18 = add <4 x i32> %17, <i32 8, i32 8, i32 8, i32 8>
%19 = add nuw nsw <4 x i32> %18, %16
%20 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %12
%21 = bitcast i32* %20 to <4 x i32>*
store <4 x i32> %19, <4 x i32>* %21
%22 = add nuw nsw i64 %4, 8
%23 = add <4 x i32> %5, <i32 8, i32 8, i32 8, i32 8>
%24 = add <4 x i32> %6, <i32 8, i32 8, i32 8, i32 8>
br label %3
25: ; preds = %3
%26 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%27 = call i32 @binary_search(i32* %26, i32 100, i32 42)
%28 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %27)
ret i32 0
}