#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*/ b_search(int *, int, int);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ print_vec(int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int length, val, *vec;
  printf("Put length'vector: ");
  scanf("%d", &length);
  vec = (int *)calloc(length, sizeof(int));
  int i;
  for (i = 0; i < length; i++)
    scanf("%d", vec + i);
  print_vec(vec, length);
  printf("Value to be found: ");
  scanf("%d", &val);
  b_search(vec, val, length);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
lea    0xea2(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x8(%rbp),%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11c8 <main+0x78>
mov    -0x18(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe5f(%rip),%rdi
call   1070 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1193 <main+0x43>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1060 <print_vec@plt>
lea    0xe3c(%rip),%rdi
call   1030 <printf@plt>
lea    0xe2d(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1050 <b_search@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
lea    0xea9(%rip),%rdi
mov    %rsp,%rsi
call   1070 <scanf@plt>
mov    (%rsp),%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,%r14
mov    (%rsp),%esi
test   %esi,%esi
jle    11bc <main+0x6c>
xor    %r12d,%r12d
lea    0xe80(%rip),%r15
mov    %r14,%rbx
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
add    $0x1,%r12
movslq (%rsp),%rsi
add    $0x4,%rbx
cmp    %rsi,%r12
jl     11a0 <main+0x50>
mov    %r14,%rdi
call   1060 <print_vec@plt>
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
lea    0xe3d(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x4(%rsp),%esi
mov    (%rsp),%edx
mov    %r14,%rdi
call   1050 <b_search@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Put length'vector: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [20 x i8] c"Value to be found: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = call i64 @calloc(i32 %8, i32 4)
%10 = inttoptr i64 %9 to i32*
store i32* %10, i32** %4
store i32 0, i32* %5
br label %11
11: ; preds = %21, %0
%12 = load i32, i32* %5
%13 = load i32, i32* %2
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %24
15: ; preds = %11
%16 = load i32*, i32** %4
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %19)
br label %21
21: ; preds = %15
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %11
24: ; preds = %11
%25 = load i32*, i32** %4
%26 = load i32, i32* %2
%27 = call i32 @print_vec(i32* %25, i32 %26)
%28 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%30 = load i32*, i32** %4
%31 = load i32, i32* %3
%32 = load i32, i32* %2
%33 = call i32 @b_search(i32* %30, i32 %31, i32 %32)
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"Put length'vector: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [20 x i8] c"Value to be found: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = call i64 @calloc(i32 %7, i32 4)
%9 = inttoptr i64 %8 to i32*
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %0, %12
%13 = phi i64 [ %16, %12 ], [ 0, %0 ]
%14 = getelementptr inbounds i32, i32* %9, i64 %13
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %14)
%16 = add nuw nsw i64 %13, 1
%17 = load i32, i32* %1
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %16, %18
br i1 %19, label %12, label %20
20: ; preds = %12, %0
%21 = phi i32 [ %10, %0 ], [ %17, %12 ]
%22 = call i32 @print_vec(i32* %9, i32 %21)
%23 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%25 = load i32, i32* %2
%26 = load i32, i32* %1
%27 = call i32 @b_search(i32* %9, i32 %25, i32 %26)
ret i32 0
}