#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 main() {
  int n;
  int array[n];
  int i, keynum, search = 0, found = 0;
  printf("Please enter the size of the array\n");
  scanf("%d", &n);
  printf("Please enter the array\n");
  for (i = 0; i <= n; i++) {
    scanf("%d", &array[i]);
  }
  printf("The entered array is\n");
  for (i = 0; i <= n; i++) {
    printf("%d\n", array[i]);
  }
  printf("Please enter the value to be searched\n");
  scanf("%d", &keynum);
  for (i = 0; i <= n; i++) {
    if (keynum == array[i]) {
      search = 1;
      found = array[i];
      break;
    }
  }
  if (found == 1) {
    printf("searched element found %d \n", found);
  } else {
    printf("searched element not found\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeab(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11cc <main+0xac>
mov    -0x30(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe6b(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1197 <main+0x77>
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1214 <main+0xf4>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e1 <main+0xc1>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdfb(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1286 <main+0x166>
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%eax
movslq -0x1c(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jne    1273 <main+0x153>
mov    -0x30(%rbp),%rax
movl   $0x1,-0x24(%rbp)
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x28(%rbp)
jmp    1286 <main+0x166>
jmp    1278 <main+0x158>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1239 <main+0x119>
cmpl   $0x1,-0x28(%rbp)
jne    12a6 <main+0x186>
mov    -0x28(%rbp),%esi
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12b4 <main+0x194>
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsp,%r15
lea    0xede(%rip),%rdi
call   1030 <puts@plt>
lea    0xeaf(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <scanf@plt>
lea    0xee4(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0x10(%rsp)
js     119d <main+0x6d>
mov    %rsp,%r12
mov    $0xffffffffffffffff,%rbx
lea    0xe81(%rip),%r14
nop
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
movslq 0x10(%rsp),%rax
add    $0x4,%r12
add    $0x1,%rbx
cmp    %rax,%rbx
jl     1180 <main+0x50>
lea    0xeb9(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0x10(%rsp)
js     11db <main+0xab>
mov    $0xffffffffffffffff,%rbx
lea    0xe45(%rip),%r14
xchg   %ax,%ax
mov    (%rsp),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movslq 0x10(%rsp),%rax
add    $0x1,%rbx
cmp    %rax,%rbx
jl     11c0 <main+0x90>
lea    0xe90(%rip),%rdi
call   1030 <puts@plt>
lea    0xe12(%rip),%rdi
lea    0x14(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x10(%rsp),%eax
test   %eax,%eax
js     1236 <main+0x106>
mov    0x14(%rsp),%ecx
add    $0x1,%rax
mov    (%rsp),%edx
nopl   0x0(%rax,%rax,1)
cmp    %edx,%ecx
je     121c <main+0xec>
add    $0xffffffffffffffff,%rax
jne    1210 <main+0xe0>
jmp    1236 <main+0x106>
cmp    $0x1,%ecx
jne    1236 <main+0x106>
lea    0xddf(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1242 <main+0x112>
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rsp
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Please enter the size of the array\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [24 x i8] c"Please enter the array\0A\00"
@.str.3 = [22 x i8] c"The entered array is\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@.str.5 = [39 x i8] c"Please enter the value to be searched\0A\00"
@.str.6 = [28 x i8] c"searched element found %d \0A\00"
@.str.7 = [28 x i8] c"searched element not found\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = load i32, i32* %2
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %3
%12 = alloca i32, i64 %10
store i64 %10, i64* %4
store i32 0, i32* %7
store i32 0, i32* %8
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %5
br label %16
16: ; preds = %25, %0
%17 = load i32, i32* %5
%18 = load i32, i32* %2
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %12, i64 %22
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %23)
br label %25
25: ; preds = %20
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %16
28: ; preds = %16
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %5
br label %30
30: ; preds = %40, %28
%31 = load i32, i32* %5
%32 = load i32, i32* %2
%33 = icmp sle i32 %31, %32
br i1 %33, label %34, label %43
34: ; preds = %30
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %12, i64 %36
%38 = load i32, i32* %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %34
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 1
store i32 %42, i32* %5
br label %30
43: ; preds = %30
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%45 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
store i32 0, i32* %5
br label %46
46: ; preds = %63, %43
%47 = load i32, i32* %5
%48 = load i32, i32* %2
%49 = icmp sle i32 %47, %48
br i1 %49, label %50, label %66
50: ; preds = %46
%51 = load i32, i32* %6
%52 = load i32, i32* %5
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %12, i64 %53
%55 = load i32, i32* %54
%56 = icmp eq i32 %51, %55
br i1 %56, label %57, label %62
57: ; preds = %50
store i32 1, i32* %7
%58 = load i32, i32* %5
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %12, i64 %59
%61 = load i32, i32* %60
store i32 %61, i32* %8
br label %66
62: ; preds = %50
br label %63
63: ; preds = %62
%64 = load i32, i32* %5
%65 = add nsw i32 %64, 1
store i32 %65, i32* %5
br label %46
66: ; preds = %57, %46
%67 = load i32, i32* %8
%68 = icmp eq i32 %67, 1
br i1 %68, label %69, label %72
69: ; preds = %66
%70 = load i32, i32* %8
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %70)
br label %74
72: ; preds = %66
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
br label %74
74: ; preds = %72, %69
%75 = load i8*, i8** %3
%76 = load i32, i32* %1
ret i32 %76
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@.str.6 = [28 x i8] c"searched element found %d \0A\00"
@str = [35 x i8] c"Please enter the size of the array\00"
@str.8 = [23 x i8] c"Please enter the array\00"
@str.9 = [21 x i8] c"The entered array is\00"
@str.10 = [38 x i8] c"Please enter the value to be searched\00"
@str.11 = [27 x i8] c"searched element not found\00"
define i32 @main() {
%1 = alloca [0 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = tail call i8* @llvm.stacksave()
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.8, i64 0, i64 0))
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 0
br i1 %11, label %20, label %12
12: ; preds = %0, %12
%13 = phi i64 [ %16, %12 ], [ 0, %0 ]
%14 = getelementptr inbounds [0 x i32], [0 x i32]* %1, i64 0, 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* %2
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %13, %18
br i1 %19, label %12, label %20
20: ; preds = %12, %0
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.9, i64 0, i64 0))
%22 = load i32, i32* %2
%23 = icmp slt i32 %22, 0
br i1 %23, label %34, label %24
24: ; preds = %20
%25 = getelementptr inbounds [0 x i32], [0 x i32]* %1, i64 0, i64 0
br label %26
26: ; preds = %24, %26
%27 = phi i64 [ 0, %24 ], [ %30, %26 ]
%28 = load i32, i32* %25
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = add nuw nsw i64 %27, 1
%31 = load i32, i32* %2
%32 = sext i32 %31 to i64
%33 = icmp slt i64 %27, %32
br i1 %33, label %26, label %34
34: ; preds = %26, %20
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.10, i64 0, i64 0))
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%37 = load i32, i32* %2
%38 = icmp slt i32 %37, 0
br i1 %38, label %55, label %39
39: ; preds = %34
%40 = load i32, i32* %3
%41 = add nuw i32 %37, 1
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds [0 x i32], [0 x i32]* %1, i64 0, i64 0
%44 = load i32, i32* %43
%45 = icmp eq i32 %40, %44
br label %49
46: ; preds = %49
%47 = add nuw nsw i64 %50, 1
%48 = icmp eq i64 %47, %42
br i1 %48, label %55, label %49
49: ; preds = %39, %46
%50 = phi i64 [ 0, %39 ], [ %47, %46 ]
br i1 %45, label %51, label %46
51: ; preds = %49
%52 = icmp eq i32 %40, 1
br i1 %52, label %53, label %55
53: ; preds = %51
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 1)
br label %57
55: ; preds = %46, %34, %51
%56 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.11, i64 0, i64 0))
br label %57
57: ; preds = %55, %53
ret i32 0
}