#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 */
size_t linearSearch(int *, int, int);
int /*<<< orphan*/ printf(char *, size_t);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
void fig06_18() {
  int a[100];
  size_t x;
  int searchKey;
  size_t element;
  for (x = 0; x < 100; ++x) {
    a[x] = 2 * x;
  }
  puts("Enter integer search key:");
  scanf("%d", &searchKey);
  element = linearSearch(a, searchKey, 100);
  if (element != -1) {
    printf("Found value in element %d\n", element);
  } else {
    puts("Value not found");
  }
}


x86 assembly (clang, -O0):
<fig06_18>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movq   $0x0,-0x198(%rbp)
cmpq   $0x64,-0x198(%rbp)
64
jae    1196 <fig06_18+0x56>
mov    -0x198(%rbp),%rax
shl    $0x1,%rax
mov    %eax,%ecx
mov    -0x198(%rbp),%rax
mov    %ecx,-0x190(%rbp,%rax,4)
mov    -0x198(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x198(%rbp)
jmp    1156 <fig06_18+0x16>
lea    0xe63(%rip),%rdi
call   1040 <puts@plt>
lea    0xe71(%rip),%rdi
lea    -0x19c(%rbp),%rsi
call   1060 <scanf@plt>
lea    -0x190(%rbp),%rdi
mov    -0x19c(%rbp),%esi
mov    $0x64,%edx
call   1030 <linearSearch@plt>
mov    %rax,-0x1a8(%rbp)
cmpq   $0xffffffffffffffff,-0x1a8(%rbp)
ff
je     11f9 <fig06_18+0xb9>
mov    -0x1a8(%rbp),%rsi
lea    0xe2e(%rip),%rdi
call   1050 <printf@plt>
jmp    1205 <fig06_18+0xc5>
lea    0xe38(%rip),%rdi
call   1040 <puts@plt>
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig06_18>:
sub    $0x1a8,%rsp
movaps 0xeb2(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeb6(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xeba(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xebe(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xec2(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xec6(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xeca(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xece(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xecf(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xed0(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movaps 0xed1(%rip),%xmm0
movaps %xmm0,0xb0(%rsp)
movaps 0xed2(%rip),%xmm0
movaps %xmm0,0xc0(%rsp)
movaps 0xed3(%rip),%xmm0
movaps %xmm0,0xd0(%rsp)
movaps 0xed4(%rip),%xmm0
movaps %xmm0,0xe0(%rsp)
movaps 0xed5(%rip),%xmm0
movaps %xmm0,0xf0(%rsp)
movaps 0xed6(%rip),%xmm0
movaps %xmm0,0x100(%rsp)
movaps 0xed7(%rip),%xmm0
movaps %xmm0,0x110(%rsp)
movaps 0xed8(%rip),%xmm0
movaps %xmm0,0x120(%rsp)
movaps 0xed9(%rip),%xmm0
movaps %xmm0,0x130(%rsp)
movaps 0xeda(%rip),%xmm0
movaps %xmm0,0x140(%rsp)
movaps 0xedb(%rip),%xmm0
movaps %xmm0,0x150(%rsp)
movaps 0xedc(%rip),%xmm0
movaps %xmm0,0x160(%rsp)
movaps 0xedd(%rip),%xmm0
movaps %xmm0,0x170(%rsp)
movaps 0xede(%rip),%xmm0
movaps %xmm0,0x180(%rsp)
movaps 0xedf(%rip),%xmm0
movaps %xmm0,0x190(%rsp)
lea    0xee0(%rip),%rdi
call   1040 <puts@plt>
lea    0xeee(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%esi
lea    0x10(%rsp),%rdi
mov    $0x64,%edx
call   1030 <linearSearch@plt>
cmp    $0xffffffffffffffff,%rax
je     12f6 <fig06_18+0x1b6>
lea    0xec7(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
add    $0x1a8,%rsp
ret
lea    0xecb(%rip),%rdi
call   1040 <puts@plt>
add    $0x1a8,%rsp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Enter integer search key:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"Found value in element %d\0A\00"
@.str.3 = [16 x i8] c"Value not found\00"
define void @fig06_18() {
%1 = alloca [100 x i32]
%2 = alloca i64
%3 = alloca i32
%4 = alloca i64
store i64 0, i64* %2
br label %5
5: ; preds = %14, %0
%6 = load i64, i64* %2
%7 = icmp ult i64 %6, 100
br i1 %7, label %8, label %17
8: ; preds = %5
%9 = load i64, i64* %2
%10 = mul i64 2, %9
%11 = trunc i64 %10 to i32
%12 = load i64, i64* %2
%13 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %12
store i32 %11, i32* %13
br label %14
14: ; preds = %8
%15 = load i64, i64* %2
%16 = add i64 %15, 1
store i64 %16, i64* %2
br label %5
17: ; preds = %5
%18 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 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* %3)
%20 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%21 = load i32, i32* %3
%22 = call i64 @linearSearch(i32* %20, i32 %21, i32 100)
store i64 %22, i64* %4
%23 = load i64, i64* %4
%24 = icmp ne i64 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %17
%26 = load i64, i64* %4
%27 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i64 %26)
br label %30
28: ; preds = %17
%29 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %25
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"Enter integer search key:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"Found value in element %d\0A\00"
@.str.3 = [16 x i8] c"Value not found\00"
define void @fig06_18() {
%1 = alloca [100 x i32]
%2 = alloca i32
%3 = bitcast [100 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = bitcast [100 x i32]* %1 to <4 x i32>*
store <4 x i32> <i32 0, i32 2, i32 4, i32 6>, <4 x i32>* %5
%6 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 4
%7 = bitcast i32* %6 to <4 x i32>*
store <4 x i32> <i32 8, i32 10, i32 12, i32 14>, <4 x i32>* %7
%8 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 8
%9 = bitcast i32* %8 to <4 x i32>*
store <4 x i32> <i32 16, i32 18, i32 20, i32 22>, <4 x i32>* %9
%10 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 12
%11 = bitcast i32* %10 to <4 x i32>*
store <4 x i32> <i32 24, i32 26, i32 28, i32 30>, <4 x i32>* %11
%12 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 16
%13 = bitcast i32* %12 to <4 x i32>*
store <4 x i32> <i32 32, i32 34, i32 36, i32 38>, <4 x i32>* %13
%14 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 20
%15 = bitcast i32* %14 to <4 x i32>*
store <4 x i32> <i32 40, i32 42, i32 44, i32 46>, <4 x i32>* %15
%16 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 24
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> <i32 48, i32 50, i32 52, i32 54>, <4 x i32>* %17
%18 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 28
%19 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> <i32 56, i32 58, i32 60, i32 62>, <4 x i32>* %19
%20 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 32
%21 = bitcast i32* %20 to <4 x i32>*
store <4 x i32> <i32 64, i32 66, i32 68, i32 70>, <4 x i32>* %21
%22 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 36
%23 = bitcast i32* %22 to <4 x i32>*
store <4 x i32> <i32 72, i32 74, i32 76, i32 78>, <4 x i32>* %23
%24 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 40
%25 = bitcast i32* %24 to <4 x i32>*
store <4 x i32> <i32 80, i32 82, i32 84, i32 86>, <4 x i32>* %25
%26 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 44
%27 = bitcast i32* %26 to <4 x i32>*
store <4 x i32> <i32 88, i32 90, i32 92, i32 94>, <4 x i32>* %27
%28 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 48
%29 = bitcast i32* %28 to <4 x i32>*
store <4 x i32> <i32 96, i32 98, i32 100, i32 102>, <4 x i32>* %29
%30 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 52
%31 = bitcast i32* %30 to <4 x i32>*
store <4 x i32> <i32 104, i32 106, i32 108, i32 110>, <4 x i32>* %31
%32 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 56
%33 = bitcast i32* %32 to <4 x i32>*
store <4 x i32> <i32 112, i32 114, i32 116, i32 118>, <4 x i32>* %33
%34 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 60
%35 = bitcast i32* %34 to <4 x i32>*
store <4 x i32> <i32 120, i32 122, i32 124, i32 126>, <4 x i32>* %35
%36 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 64
%37 = bitcast i32* %36 to <4 x i32>*
store <4 x i32> <i32 128, i32 130, i32 132, i32 134>, <4 x i32>* %37
%38 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 68
%39 = bitcast i32* %38 to <4 x i32>*
store <4 x i32> <i32 136, i32 138, i32 140, i32 142>, <4 x i32>* %39
%40 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 72
%41 = bitcast i32* %40 to <4 x i32>*
store <4 x i32> <i32 144, i32 146, i32 148, i32 150>, <4 x i32>* %41
%42 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 76
%43 = bitcast i32* %42 to <4 x i32>*
store <4 x i32> <i32 152, i32 154, i32 156, i32 158>, <4 x i32>* %43
%44 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 80
%45 = bitcast i32* %44 to <4 x i32>*
store <4 x i32> <i32 160, i32 162, i32 164, i32 166>, <4 x i32>* %45
%46 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 84
%47 = bitcast i32* %46 to <4 x i32>*
store <4 x i32> <i32 168, i32 170, i32 172, i32 174>, <4 x i32>* %47
%48 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 88
%49 = bitcast i32* %48 to <4 x i32>*
store <4 x i32> <i32 176, i32 178, i32 180, i32 182>, <4 x i32>* %49
%50 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 92
%51 = bitcast i32* %50 to <4 x i32>*
store <4 x i32> <i32 184, i32 186, i32 188, i32 190>, <4 x i32>* %51
%52 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 96
%53 = bitcast i32* %52 to <4 x i32>*
store <4 x i32> <i32 192, i32 194, i32 196, i32 198>, <4 x i32>* %53
%54 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%55 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%56 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%57 = load i32, i32* %2
%58 = call i64 @linearSearch(i32* %56, i32 %57, i32 100)
%59 = icmp eq i64 %58, -1
br i1 %59, label %62, label %60
60: ; preds = %0
%61 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i64 %58)
br label %64
62: ; preds = %0
%63 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %64
64: ; preds = %62, %60
ret void
}