#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 A[100], n, i, s;
  printf("Enter Number of Elements: ");
  scanf("%d", &n);
  printf("Enter %d Elements:\n", n);
  for (i = 0; i < n; i++)
    scanf("%d", &A[i]);
  printf("Enter Element to Search: ");
  scanf("%d", &s);
  for (i = 0; i < n; i++) {
    if (A[i] == s)
      break;
  }
  if (i < n)
    printf("%d found at index %d\n", s, i + 1);
  else
    printf("%d not found\n", s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed4(%rip),%rdi
lea    -0x1a4(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x1a4(%rbp),%esi
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    11b8 <main+0x98>
movslq -0x1a8(%rbp),%rax
lea    -0x1a0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe7c(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
jmp    1171 <main+0x51>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe4e(%rip),%rdi
lea    -0x1ac(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    122d <main+0x10d>
movslq -0x1a8(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
cmp    -0x1ac(%rbp),%eax
jne    1214 <main+0xf4>
jmp    122d <main+0x10d>
jmp    1219 <main+0xf9>
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
jmp    11e3 <main+0xc3>
mov    -0x1a8(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    1261 <main+0x141>
mov    -0x1ac(%rbp),%esi
mov    -0x1a8(%rbp),%edx
add    $0x1,%edx
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1275 <main+0x155>
mov    -0x1ac(%rbp),%esi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1a0,%rsp
lea    0xecd(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeda(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x8(%rsp),%esi
lea    0xec8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
cmpl   $0x0,0x8(%rsp)
jle    119d <main+0x7d>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xea9(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     1180 <main+0x60>
lea    0xe8e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe69(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%esi
test   %eax,%eax
jle    11df <main+0xbf>
xor    %edx,%edx
nopw   0x0(%rax,%rax,1)
cmp    %esi,0x10(%rsp,%rdx,4)
je     11ef <main+0xcf>
add    $0x1,%rdx
cmp    %rdx,%rax
jne    11d0 <main+0xb0>
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1200 <main+0xe0>
add    $0x1,%edx
lea    0xe53(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1a0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Enter Number of Elements: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [20 x i8] c"Enter %d Elements:\0A\00"
@.str.3 = [26 x i8] c"Enter Element to Search: \00"
@.str.4 = [22 x i8] c"%d found at index %d\0A\00"
@.str.5 = [14 x i8] c"%d not found\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 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* %3)
%8 = load i32, i32* %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %8)
store i32 0, i32* %4
br label %10
10: ; preds = %19, %0
%11 = load i32, i32* %4
%12 = load i32, i32* %3
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %22
14: ; preds = %10
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %16
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %17)
br label %19
19: ; preds = %14
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %10
22: ; preds = %10
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
store i32 0, i32* %4
br label %25
25: ; preds = %38, %22
%26 = load i32, i32* %4
%27 = load i32, i32* %3
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %41
29: ; preds = %25
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = load i32, i32* %5
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %37
36: ; preds = %29
br label %41
37: ; preds = %29
br label %38
38: ; preds = %37
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 1
store i32 %40, i32* %4
br label %25
41: ; preds = %36, %25
%42 = load i32, i32* %4
%43 = load i32, i32* %3
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %50
45: ; preds = %41
%46 = load i32, i32* %5
%47 = load i32, i32* %4
%48 = add nsw i32 %47, 1
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %46, i32 %48)
br label %53
50: ; preds = %41
%51 = load i32, i32* %5
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %50, %45
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"Enter Number of Elements: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [20 x i8] c"Enter %d Elements:\0A\00"
@.str.3 = [26 x i8] c"Enter Element to Search: \00"
@.str.4 = [22 x i8] c"%d found at index %d\0A\00"
@.str.5 = [14 x i8] c"%d not found\0A\00"
define i32 @main() {
%1 = alloca [100 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = bitcast [100 x i32]* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 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 = load i32, i32* %2
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %2
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %0, %13
%14 = phi i64 [ %17, %13 ], [ 0, %0 ]
%15 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %14
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %15)
%17 = add nuw nsw i64 %14, 1
%18 = load i32, i32* %2
%19 = sext i32 %18 to i64
%20 = icmp slt i64 %17, %19
br i1 %20, label %13, label %21
21: ; preds = %13, %0
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%24 = load i32, i32* %2
%25 = icmp sgt i32 %24, 0
%26 = load i32, i32* %3
br i1 %25, label %27, label %41
27: ; preds = %21
%28 = zext i32 %24 to i64
br label %29
29: ; preds = %27, %34
%30 = phi i64 [ 0, %27 ], [ %35, %34 ]
%31 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = icmp eq i32 %32, %26
br i1 %33, label %37, label %34
34: ; preds = %29
%35 = add nuw nsw i64 %30, 1
%36 = icmp eq i64 %35, %28
br i1 %36, label %41, label %29
37: ; preds = %29
%38 = trunc i64 %30 to i32
%39 = add nuw nsw i32 %38, 1
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %26, i32 %39)
br label %43
41: ; preds = %34, %21
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %26)
br label %43
43: ; preds = %41, %37
ret i32 0
}