#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 binarysearch(int, int *, int);
int /*<<< orphan*/ pause();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ system(char *);
void prob3(void) {
  system("clear");
  int loop;
  int searchvalue = 0b01010001;
  int searchreturn;
  int data[8] = {0b00000001, 0b00010001, 0b10010101, 0b01101110,
                 0b11011011, 0b11111110, 0b00111101, 0b10011101};
  printf("---------- Data Array Values --------\n");
  for (loop = 0; loop < 8; loop++) {
    printf("%d\n", data[loop]);
  }
  searchreturn = binarysearch(8, data, searchvalue);
  if (searchreturn != -1) {
    printf("\nThis binary value equivalent to %d was found in ", searchvalue);
    printf("element %d of the array.\n", searchreturn);
  } else {
    printf("\nThis binary value equivalent to %d could not ", searchvalue);
    printf("be found in the array.");
  }
  pause();
}


x86 assembly (clang, -O0):
<prob3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xeb1(%rip),%rdi
call   1040 <system@plt>
movl   $0x51,-0x8(%rbp)
mov    0xf6e(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xf6b(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xf68(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xf65(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x8,-0x4(%rbp)
jge    11ca <prob3+0x8a>
movslq -0x4(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    119c <prob3+0x5c>
lea    -0x30(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    $0x8,%edi
call   1030 <binarysearch@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
je     120f <prob3+0xcf>
mov    -0x8(%rbp),%esi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    122e <prob3+0xee>
mov    -0x8(%rbp),%esi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <pause@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prob3>:
push   %rbx
sub    $0x20,%rsp
lea    0xea4(%rip),%rdi
call   1050 <system@plt>
movaps 0xf78(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xf5c(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xf1d(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7b(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0x11,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0x95,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0x6e,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0xdb,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0xfe,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0x3d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0x9d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,%rsi
mov    $0x8,%edi
mov    $0x51,%edx
call   1040 <binarysearch@plt>
cmp    $0xffffffff,%eax
je     1241 <prob3+0xf1>
mov    %eax,%ebx
lea    0xde7(%rip),%rdi
mov    $0x51,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe06(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1262 <prob3+0x112>
lea    0xe0e(%rip),%rdi
mov    $0x51,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe2a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1070 <pause@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"clear\00"
@__const.prob3.data = [8 x i32] [i32 1, i32 17, i32 149, i32 110, i32 219, i32 254, i32 61, i32 157]
@.str.1 = [39 x i8] c"---------- Data Array Values --------\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [50 x i8] c"\0AThis binary value equivalent to %d was found in \00"
@.str.4 = [26 x i8] c"element %d of the array.\0A\00"
@.str.5 = [47 x i8] c"\0AThis binary value equivalent to %d could not \00"
@.str.6 = [23 x i8] c"be found in the array.\00"
define void @prob3() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [8 x i32]
%5 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 81, i32* %2
%6 = bitcast [8 x i32]* %4 to i8*
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %8
8: ; preds = %17, %0
%9 = load i32, i32* %1
%10 = icmp slt i32 %9, 8
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = load i32, i32* %1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [8 x i32], [8 x i32]* %4, i64 0, i64 %13
%15 = load i32, i32* %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %11
%18 = load i32, i32* %1
%19 = add nsw i32 %18, 1
store i32 %19, i32* %1
br label %8
20: ; preds = %8
%21 = getelementptr inbounds [8 x i32], [8 x i32]* %4, i64 0, i64 0
%22 = load i32, i32* %2
%23 = call i32 @binarysearch(i32 8, i32* %21, i32 %22)
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = icmp ne i32 %24, -1
br i1 %25, label %26, label %31
26: ; preds = %20
%27 = load i32, i32* %2
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %3
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %29)
br label %35
31: ; preds = %20
%32 = load i32, i32* %2
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
br label %35
35: ; preds = %31, %26
%36 = call i32 (...) @pause()
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"clear\00"
@__const.prob3.data = [8 x i32] [i32 1, i32 17, i32 149, i32 110, i32 219, i32 254, i32 61, i32 157]
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [50 x i8] c"\0AThis binary value equivalent to %d was found in \00"
@.str.4 = [26 x i8] c"element %d of the array.\0A\00"
@.str.5 = [47 x i8] c"\0AThis binary value equivalent to %d could not \00"
@.str.6 = [23 x i8] c"be found in the array.\00"
@str = [38 x i8] c"---------- Data Array Values --------\00"
define void @prob3() {
%1 = alloca [8 x i32]
%2 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%3 = bitcast [8 x i32]* %1 to i8*
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%5 = getelementptr inbounds [8 x i32], [8 x i32]* %1, i64 0, i64 0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 1)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 17)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 149)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 110)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 219)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 254)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 61)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 157)
%14 = call i32 @binarysearch(i32 8, i32* %5, i32 81)
%15 = icmp eq i32 %14, -1
br i1 %15, label %19, label %16
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i32 81)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %14)
br label %22
19: ; preds = %0
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i32 81)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
br label %22
22: ; preds = %19, %16
%23 = call i32 (...) @pause()
ret void
}