#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 ar[] = {2, 3, 4, 1, 5, 7, 6, 8};
  int i;
  int elem;
  int position = -1;
  printf("Enter element to be searched: ");
  scanf("%d", &elem);
  for (i = 0; i < 8; i++) {
    if (elem == ar[i]) {
      position = i;
      break;
    }
  }
  if (position != -1) {
    printf("Element %d found at position %d\n", elem, position);
  } else {
    printf("Sorry, the element you were looking for could not be found.\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xec4(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xec1(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0xffffffff,-0x3c(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec8(%rip),%rdi
lea    -0x38(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x8,-0x34(%rbp)
jge    11c0 <main+0xa0>
mov    -0x38(%rbp),%eax
movslq -0x34(%rbp),%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
jne    11ad <main+0x8d>
mov    -0x34(%rbp),%eax
mov    %eax,-0x3c(%rbp)
jmp    11c0 <main+0xa0>
jmp    11b2 <main+0x92>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1187 <main+0x67>
cmpl   $0xffffffff,-0x3c(%rbp)
je     11e3 <main+0xc3>
mov    -0x38(%rbp),%esi
mov    -0x3c(%rbp),%edx
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f1 <main+0xd1>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xec8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed9(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%esi
lea    -0x1(%rsi),%eax
cmp    $0x8,%eax
jae    1178 <main+0x48>
cltq
lea    0xf1b(%rip),%rcx
mov    (%rcx,%rax,4),%edx
lea    0xeb3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1184 <main+0x54>
lea    0xec4(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@__const.main.ar = [8 x i32] [i32 2, i32 3, i32 4, i32 1, i32 5, i32 7, i32 6, i32 8]
@.str = [31 x i8] c"Enter element to be searched: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [33 x i8] c"Element %d found at position %d\0A\00"
@.str.3 = [61 x i8] c"Sorry, the element you were looking for could not be found.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [8 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [8 x i32]* %2 to i8*
store i32 -1, i32* %5
%7 = call i32 (i8*, ...) @printf(i8* 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* %4)
store i32 0, i32* %3
br label %9
9: ; preds = %22, %0
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 8
br i1 %11, label %12, label %25
12: ; preds = %9
%13 = load i32, i32* %4
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = icmp eq i32 %13, %17
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = load i32, i32* %3
store i32 %20, i32* %5
br label %25
21: ; preds = %12
br label %22
22: ; preds = %21
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %9
25: ; preds = %19, %9
%26 = load i32, i32* %5
%27 = icmp ne i32 %26, -1
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i32, i32* %4
%30 = load i32, i32* %5
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %29, i32 %30)
br label %34
32: ; preds = %25
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %32, %28
ret i32 0
}

LLVM IR (-O2):
@.str = [31 x i8] c"Enter element to be searched: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [33 x i8] c"Element %d found at position %d\0A\00"
@str = [60 x i8] c"Sorry, the element you were looking for could not be found.\00"
@switch.table.main = [8 x i32] [i32 3, i32 0, i32 1, i32 2, i32 4, i32 6, i32 5, i32 7]
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = add i32 %5, -1
%7 = icmp ult i32 %6, 8
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str, i64 0, i64 0))
br label %15
10: ; preds = %0
%11 = sext i32 %6 to i64
%12 = getelementptr inbounds [8 x i32], [8 x i32]* @switch.table.main, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %5, i32 %13)
br label %15
15: ; preds = %8, %10
ret i32 0
}