#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 *);
main() {
  int n;
  int i;
  int item;
  do {
    printf("Enter the number of elements\n");
    scanf("%d", &n);
  } while (n < 1);
  int arr[n];
  for (i = 0; i < n; i++) {
    printf("\nEnter the element\n");
    scanf("%d", &arr[i]);
  }
  printf("\nArray is: {");
  for (i = 0; i < n; i++)
    printf(" %d ", arr[i]);
  printf("}\n");
  printf("\nEnter the item to be searched\n");
  scanf("%d", &item);
  for (i = 0; i < n; i++) {
    if (arr[i] == item) {
      printf("\n%d found at position %d\n", item, i + 1);
      break;
    }
  }
  if (i == n)
    printf("\n%d not found!\n", item);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeda(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x1,-0x8(%rbp)
jl     112f <main+0xf>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11c8 <main+0xa8>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe69(%rip),%rdi
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1185 <main+0x65>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1210 <main+0xf0>
mov    -0x28(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11dd <main+0xbd>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdeb(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1292 <main+0x172>
mov    -0x28(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x10(%rbp),%eax
jne    127f <main+0x15f>
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
add    $0x1,%edx
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1292 <main+0x172>
jmp    1284 <main+0x164>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1243 <main+0x123>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    12af <main+0x18f>
mov    -0x10(%rbp),%esi
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xef7(%rip),%r14
lea    0xeb1(%rip),%r15
lea    -0x2c(%rbp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
jle    1160 <main+0x30>
mov    %rsp,-0x38(%rbp)
mov    %rsp,%r13
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
cmpl   $0x0,-0x2c(%rbp)
jle    11d4 <main+0xa4>
xor    %r12d,%r12d
lea    0xeda(%rip),%r14
lea    0xe56(%rip),%r15
mov    %r13,%rbx
nopl   (%rax)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
add    $0x1,%r12
movslq -0x2c(%rbp),%rax
add    $0x4,%rbx
cmp    %rax,%r12
jl     11b0 <main+0x80>
lea    0xe28(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    121c <main+0xec>
lea    0xe1e(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x0(%r13,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
cmp    %rax,%rbx
jl     1200 <main+0xd0>
lea    0xe39(%rip),%rdi
call   1030 <puts@plt>
lea    0xe2f(%rip),%rdi
call   1030 <puts@plt>
lea    0xdc5(%rip),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
jle    1272 <main+0x142>
mov    -0x30(%rbp),%esi
xor    %r15d,%r15d
mov    -0x38(%rbp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
cmp    %esi,0x0(%r13,%r15,4)
je     127d <main+0x14d>
add    $0x1,%r15
cmp    %r15,%rax
jne    1260 <main+0x130>
jmp    1297 <main+0x167>
mov    -0x38(%rbp),%rbx
cmp    %eax,%r15d
je     1297 <main+0x167>
jmp    12a8 <main+0x178>
lea    0x1(%r15),%edx
lea    0xd8d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
cmp    %eax,%r15d
jne    12a8 <main+0x178>
mov    -0x30(%rbp),%esi
lea    0xd8e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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