#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 linear_search(int *, int, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int x[100], n, m, p, ctr, i;
  printf("Enter number of elements in the array ");
  scanf("%d", &n);
  printf("Enter %d elements into the array ", n);
  for (i = 0; i < n; i++) {
    scanf("%d", &x[i]);
  }
  printf("Enter the element to search ");
  scanf("%d", &m);
  ctr = 0;
  p = linear_search(x, n, m, ctr);
  if (p == 0) {
    printf("Element not found\n");
  } else {
    printf("Element is present at postion %d\n", p);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xed0(%rip),%rdi
lea    -0x1a4(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x1a4(%rbp),%esi
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1b4(%rbp)
mov    -0x1b4(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    11c8 <main+0x98>
movslq -0x1b4(%rbp),%rax
lea    -0x1a0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe78(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x1b4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b4(%rbp)
jmp    1181 <main+0x51>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe4a(%rip),%rdi
lea    -0x1a8(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x0,-0x1b0(%rbp)
lea    -0x1a0(%rbp),%rdi
mov    -0x1a4(%rbp),%esi
mov    -0x1a8(%rbp),%edx
mov    -0x1b0(%rbp),%ecx
call   1030 <linear_search@plt>
mov    %eax,-0x1ac(%rbp)
cmpl   $0x0,-0x1ac(%rbp)
jne    1237 <main+0x107>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    124b <main+0x11b>
mov    -0x1ac(%rbp),%esi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1a0,%rsp
lea    0xead(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec6(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x8(%rsp),%esi
lea    0xeb4(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11bd <main+0x7d>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xe95(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     11a0 <main+0x60>
lea    0xe88(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe55(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0x10(%rsp),%rdi
xor    %ecx,%ecx
call   1040 <linear_search@plt>
test   %eax,%eax
je     1206 <main+0xc6>
lea    0xe6e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1212 <main+0xd2>
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x1a0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Enter number of elements in the array \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [34 x i8] c"Enter %d elements into the array \00"
@.str.3 = [29 x i8] c"Enter the element to search \00"
@.str.4 = [19 x i8] c"Element not found\0A\00"
@.str.5 = [34 x i8] c"Element is present at postion %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 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* %3)
%10 = load i32, i32* %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %10)
store i32 0, i32* %7
br label %12
12: ; preds = %21, %0
%13 = load i32, i32* %7
%14 = load i32, i32* %3
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %24
16: ; preds = %12
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %18
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %19)
br label %21
21: ; preds = %16
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
store i32 %23, i32* %7
br label %12
24: ; preds = %12
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
store i32 0, i32* %6
%27 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%28 = load i32, i32* %3
%29 = load i32, i32* %4
%30 = load i32, i32* %6
%31 = call i32 @linear_search(i32* %27, i32 %28, i32 %29, i32 %30)
store i32 %31, i32* %5
%32 = load i32, i32* %5
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %24
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %39
36: ; preds = %24
%37 = load i32, i32* %5
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %36, %34
ret i32 0
}

LLVM IR (-O2):
@.str = [39 x i8] c"Enter number of elements in the array \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [34 x i8] c"Enter %d elements into the array \00"
@.str.3 = [29 x i8] c"Enter the element to search \00"
@.str.5 = [34 x i8] c"Element is present at postion %d\0A\00"
@str = [18 x i8] c"Element not found\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 ([39 x i8], [39 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 ([34 x i8], [34 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 ([29 x i8], [29 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 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%25 = load i32, i32* %2
%26 = load i32, i32* %3
%27 = call i32 @linear_search(i32* %24, i32 %25, i32 %26, i32 0)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %21
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %33
31: ; preds = %21
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %27)
br label %33
33: ; preds = %31, %29
ret i32 0
}