#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*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int sequentialSearch(int *, int, int);
int main() {
  int myarray[10] = {2, 4, 7, 8, 31, 22, 17, 6, 5, 11};
  int i, position, key;
  printf("\nArray is ");
  for (i = 0; i < 10; ++i)
    printf("%d ", myarray[i]);
  printf("\nInput value to search for: ");
  scanf("%d", &key);
  position = sequentialSearch(myarray, key, 10);
  if (position == -1)
    printf("\nValue not found\n\n");
  else
    printf("\nValue found at array position: %d\n\n", position);
  printf("[Press any key to close]");
  getchar();
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xe96(%rip),%rsi
mov    $0x28,%edx
call   1060 <memcpy@plt>
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0xa,-0x34(%rbp)
jge    11b7 <main+0x67>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1189 <main+0x39>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe88(%rip),%rdi
lea    -0x3c(%rbp),%rsi
call   1070 <scanf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    $0xa,%edx
call   1040 <sequentialSearch@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
jne    1206 <main+0xb6>
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1217 <main+0xc7>
mov    -0x38(%rbp),%esi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
mov    0xec4(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0xea8(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe8c(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xea8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea5(%rip),%rbx
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x1f,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x16,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x11,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0xb,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe0c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe1b(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%esi
lea    0x10(%rsp),%rdi
mov    $0xa,%edx
call   1050 <sequentialSearch@plt>
cmp    $0xffffffff,%eax
je     126d <main+0x11d>
lea    0xdf5(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1279 <main+0x129>
lea    0xe21(%rip),%rdi
call   1030 <puts@plt>
lea    0xdfc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.myarray = [10 x i32] [i32 2, i32 4, i32 7, i32 8, i32 31, i32 22, i32 17, i32 6, i32 5, i32 11]
@.str = [11 x i8] c"\0AArray is \00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [29 x i8] c"\0AInput value to search for: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [19 x i8] c"\0AValue not found\0A\0A\00"
@.str.5 = [37 x i8] c"\0AValue found at array position: %d\0A\0A\00"
@.str.6 = [25 x i8] c"[Press any key to close]\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [10 x i32]* %2 to i8*
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %8
8: ; preds = %17, %0
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 10
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %13
%15 = load i32, i32* %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %11
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %8
20: ; preds = %8
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%23 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%24 = load i32, i32* %5
%25 = call i32 @sequentialSearch(i32* %23, i32 %24, i32 10)
store i32 %25, i32* %4
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %20
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %33
30: ; preds = %20
%31 = load i32, i32* %4
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %30, %28
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%35 = call i32 (...) @getchar()
%36 = call i32 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@__const.main.myarray = [10 x i32] [i32 2, i32 4, i32 7, i32 8, i32 31, i32 22, i32 17, i32 6, i32 5, i32 11]
@.str = [11 x i8] c"\0AArray is \00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [29 x i8] c"\0AInput value to search for: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.5 = [37 x i8] c"\0AValue found at array position: %d\0A\0A\00"
@.str.6 = [25 x i8] c"[Press any key to close]\00"
@str = [18 x i8] c"\0AValue not found\0A\00"
define i32 @main() {
%1 = alloca [10 x i32]
%2 = alloca i32
%3 = bitcast [10 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 2)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 4)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 7)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 8)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 31)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 22)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 17)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 6)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 5)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 11)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%19 = load i32, i32* %2
%20 = call i32 @sequentialSearch(i32* %6, i32 %19, i32 10)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %0
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %26
24: ; preds = %0
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %20)
br label %26
26: ; preds = %24, %22
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%28 = call i32 (...) @getchar()
%29 = call i32 (...) @getchar()
ret i32 0
}