#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 /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int binary(int ren[], int low, int high, int mid, int n) {
  int key;
  printf("\nEnter your Searching Number:");
  scanf("%d", &key);
  low = 0;
  high = n - 1;
  int flag = 0;
  while (low <= high) {
    mid = (low + high) / 2;
    if (ren[mid] == key) {
      printf("\nNumber has Found at %d position.", mid);
      flag++;
      break;
    } else if (ren[mid] > key) {
      high = mid - 1;
    } else if (ren[mid] < key) {
      low = mid + 1;
    }
  }
  if (flag == 0) {
    printf("\nNumber Has Not Found");
  }
}


x86 assembly (clang, -O0):
<binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed0(%rip),%rdi
lea    -0x24(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     120c <binary+0xec>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x24(%rbp),%eax
jne    11be <binary+0x9e>
mov    -0x1c(%rbp),%esi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    120c <binary+0xec>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x24(%rbp),%eax
jle    11e0 <binary+0xc0>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1202 <binary+0xe2>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x24(%rbp),%eax
jge    11fd <binary+0xdd>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1202 <binary+0xe2>
jmp    1207 <binary+0xe7>
jmp    116e <binary+0x4e>
cmpl   $0x0,-0x28(%rbp)
jne    1224 <binary+0x104>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binary>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %r8d,%ebx
mov    %rdi,%r14
lea    0xeca(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed7(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
test   %ebx,%ebx
jle    1192 <binary+0x72>
add    $0xffffffff,%ebx
mov    0xc(%rsp),%eax
nopl   0x0(%rax)
lea    (%r15,%rbx,1),%ecx
mov    %ecx,%esi
shr    $0x1f,%esi
add    %ecx,%esi
sar    %esi
movslq %esi,%rcx
mov    (%r14,%rcx,4),%ecx
cmp    %eax,%ecx
je     11a2 <binary+0x82>
lea    -0x1(%rsi),%edx
add    $0x1,%esi
cmp    %eax,%ecx
cmovge %r15d,%esi
cmovg  %edx,%ebx
cmovg  %r15d,%esi
mov    %esi,%r15d
cmp    %ebx,%esi
jle    1160 <binary+0x40>
lea    0xeaa(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11b0 <binary+0x90>
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [30 x i8] c"\0AEnter your Searching Number:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [34 x i8] c"\0ANumber has Found at %d position.\00"
@.str.3 = [22 x i8] c"\0ANumber Has Not Found\00"
define i32 @binary(i32* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %12)
store i32 0, i32* %8
%16 = load i32, i32* %11
%17 = sub nsw i32 %16, 1
store i32 %17, i32* %9
store i32 0, i32* %13
br label %18
18: ; preds = %63, %5
%19 = load i32, i32* %8
%20 = load i32, i32* %9
%21 = icmp sle i32 %19, %20
br i1 %21, label %22, label %64
22: ; preds = %18
%23 = load i32, i32* %8
%24 = load i32, i32* %9
%25 = add nsw i32 %23, %24
%26 = sdiv i32 %25, 2
store i32 %26, i32* %10
%27 = load i32*, i32** %7
%28 = load i32, i32* %10
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = load i32, i32* %12
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %39
34: ; preds = %22
%35 = load i32, i32* %10
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %13
%38 = add nsw i32 %37, 1
store i32 %38, i32* %13
br label %64
39: ; preds = %22
%40 = load i32*, i32** %7
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
%44 = load i32, i32* %43
%45 = load i32, i32* %12
%46 = icmp sgt i32 %44, %45
br i1 %46, label %47, label %50
47: ; preds = %39
%48 = load i32, i32* %10
%49 = sub nsw i32 %48, 1
store i32 %49, i32* %9
br label %62
50: ; preds = %39
%51 = load i32*, i32** %7
%52 = load i32, i32* %10
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
%55 = load i32, i32* %54
%56 = load i32, i32* %12
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %61
58: ; preds = %50
%59 = load i32, i32* %10
%60 = add nsw i32 %59, 1
store i32 %60, i32* %8
br label %61
61: ; preds = %58, %50
br label %62
62: ; preds = %61, %47
br label %63
63: ; preds = %62
br label %18
64: ; preds = %34, %18
%65 = load i32, i32* %13
%66 = icmp eq i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %64
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %69
69: ; preds = %67, %64
%70 = load i32, i32* %6
ret i32 %70
}

LLVM IR (-O2):
@.str = [30 x i8] c"\0AEnter your Searching Number:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [34 x i8] c"\0ANumber has Found at %d position.\00"
@.str.3 = [22 x i8] c"\0ANumber Has Not Found\00"
define i32 @binary(i32* nocapture %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%10 = icmp slt i32 %4, 1
br i1 %10, label %34, label %11
11: ; preds = %5
%12 = add nsw i32 %4, -1
%13 = load i32, i32* %6
br label %14
14: ; preds = %11, %25
%15 = phi i32 [ 0, %11 ], [ %32, %25 ]
%16 = phi i32 [ %12, %11 ], [ %31, %25 ]
%17 = add nsw i32 %15, %16
%18 = sdiv i32 %17, 2
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %0, i64 %19
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, %13
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %36
25: ; preds = %14
%26 = icmp sgt i32 %21, %13
%27 = add nsw i32 %18, -1
%28 = icmp slt i32 %21, %13
%29 = add nsw i32 %18, 1
%30 = select i1 %28, i32 %29, i32 %15
%31 = select i1 %26, i32 %27, i32 %16
%32 = select i1 %26, i32 %15, i32 %30
%33 = icmp sgt i32 %32, %31
br i1 %33, label %34, label %14
34: ; preds = %25, %5
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %23, %34
ret i32 undef
}