#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, i, a[50], j, c = 0, key;
  printf("enter the no of array elements\n");
  scanf("%d", &n);
  printf("enter the elements\n");
  for (i = 0; i < n; i++)
    scanf("%d", &a[i]);
  printf("enter the element to be searched\n");
  scanf("%d", &key);
  for (i = 0; i < n; i++) {
    if (a[i] == key) {
      c = 1;
      goto l;
    }
  }
l:
  if (c == 1)
    printf("element found at position %d\n", i + 1);
  else
    printf("element not found\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xe8(%rbp)
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecf(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11a7 <main+0x87>
movslq -0xc(%rbp),%rax
lea    -0xe0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe8c(%rip),%rdi
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116f <main+0x4f>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe64(%rip),%rdi
lea    -0xec(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1214 <main+0xf4>
movslq -0xc(%rbp),%rax
mov    -0xe0(%rbp,%rax,4),%eax
cmp    -0xec(%rbp),%eax
jne    1201 <main+0xe1>
movl   $0x1,-0xe8(%rbp)
jmp    1219 <main+0xf9>
jmp    1206 <main+0xe6>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11cf <main+0xaf>
jmp    1219 <main+0xf9>
cmpl   $0x1,-0xe8(%rbp)
jne    123f <main+0x11f>
mov    -0xc(%rbp),%esi
add    $0x1,%esi
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124d <main+0x12d>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xe0,%rsp
lea    0xede(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb1(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
lea    0xee0(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0x8(%rsp)
jle    119d <main+0x6d>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xe86(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     1180 <main+0x50>
lea    0xeaf(%rip),%rdi
call   1030 <puts@plt>
lea    0xe50(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%eax
test   %eax,%eax
jle    11df <main+0xaf>
mov    0xc(%rsp),%ecx
xor    %esi,%esi
nopl   0x0(%rax,%rax,1)
cmp    %ecx,0x10(%rsp,%rsi,4)
je     11ed <main+0xbd>
add    $0x1,%rsi
cmp    %rsi,%rax
jne    11d0 <main+0xa0>
lea    0xe8e(%rip),%rdi
call   1030 <puts@plt>
jmp    11fe <main+0xce>
add    $0x1,%esi
lea    0xe0c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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