#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(int *, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
void main() {
  int a[100], i, index, n, num;
  printf("Enter the size of array");
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  printf("Enter number to be searched");
  scanf("%d", &num);
  index = linear(a, 0, n - 1, num);
  if (index == -1) {
    printf("element not found");
  } else
    printf("%d is at %d position", num, index + 1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1a0,%rsp
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec8(%rip),%rdi
lea    -0x19c(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x0,-0x194(%rbp)
mov    -0x194(%rbp),%eax
cmp    -0x19c(%rbp),%eax
jge    11ad <main+0x7d>
movslq -0x194(%rbp),%rax
lea    -0x190(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe84(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x194(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x194(%rbp)
jmp    1166 <main+0x36>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe56(%rip),%rdi
lea    -0x1a0(%rbp),%rsi
call   1050 <scanf@plt>
lea    -0x190(%rbp),%rdi
mov    -0x19c(%rbp),%edx
sub    $0x1,%edx
mov    -0x1a0(%rbp),%ecx
xor    %esi,%esi
call   1040 <linear@plt>
mov    %eax,-0x198(%rbp)
cmpl   $0xffffffff,-0x198(%rbp)
jne    1211 <main+0xe1>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122e <main+0xfe>
mov    -0x1a0(%rbp),%esi
mov    -0x198(%rbp),%edx
add    $0x1,%edx
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x1a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1a0,%rsp
lea    0xebd(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec7(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
jle    118d <main+0x5d>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xea8(%rip),%r14
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     1170 <main+0x40>
lea    0xe87(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe76(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%edx
add    $0xffffffff,%edx
mov    0xc(%rsp),%ecx
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <linear@plt>
cmp    $0xffffffff,%eax
je     11e1 <main+0xb1>
mov    0xc(%rsp),%esi
add    $0x1,%eax
lea    0xe73(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11ef <main+0xbf>
lea    0xe4f(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1a0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [24 x i8] c"Enter the size of array\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [28 x i8] c"Enter number to be searched\00"
@.str.3 = [18 x i8] c"element not found\00"
@.str.4 = [21 x i8] c"%d is at %d position\00"
define void @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 ([24 x i8], [24 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 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %0, %11
%12 = phi i64 [ %15, %11 ], [ 0, %0 ]
%13 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %12
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %13)
%15 = add nuw nsw i64 %12, 1
%16 = load i32, i32* %2
%17 = sext i32 %16 to i64
%18 = icmp slt i64 %15, %17
br i1 %18, label %11, label %19
19: ; preds = %11, %0
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%22 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%23 = load i32, i32* %2
%24 = add nsw i32 %23, -1
%25 = load i32, i32* %3
%26 = call i32 @linear(i32* %22, i32 0, i32 %24, i32 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %19
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %34
30: ; preds = %19
%31 = load i32, i32* %3
%32 = add nuw nsw i32 %26, 1
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %31, i32 %32)
br label %34
34: ; preds = %30, %28
ret void
}