#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, int, int);
int scanf(char *, int *);
int seq_search(int *, int, int);
int main(void) {
  int array[1024];
  int n, i;
  for (n = 0; n < 1024; n++)
    if (scanf("%d", &array[n]) != 1)
      break;
  for (i = 0; i < n; i++) {
    int result = seq_search(array, n, array[i]);
    if (result != i)
      printf("seq_search() returned %d looking for %d - expected %d\n", result,
             array[i], i);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1014(%rbp)
cmpl   $0x400,-0x1014(%rbp)
jge    11a4 <main+0x74>
movslq -0x1014(%rbp),%rax
lea    -0x1010(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe88(%rip),%rdi
call   1040 <scanf@plt>
cmp    $0x1,%eax
je     118b <main+0x5b>
jmp    11a4 <main+0x74>
jmp    1190 <main+0x60>
mov    -0x1014(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1014(%rbp)
jmp    114c <main+0x1c>
movl   $0x0,-0x1018(%rbp)
mov    -0x1018(%rbp),%eax
cmp    -0x1014(%rbp),%eax
jge    1237 <main+0x107>
lea    -0x1010(%rbp),%rdi
mov    -0x1014(%rbp),%esi
movslq -0x1018(%rbp),%rax
mov    -0x1010(%rbp,%rax,4),%edx
call   1050 <seq_search@plt>
mov    %eax,-0x101c(%rbp)
mov    -0x101c(%rbp),%eax
cmp    -0x1018(%rbp),%eax
je     121e <main+0xee>
mov    -0x101c(%rbp),%esi
movslq -0x1018(%rbp),%rax
mov    -0x1010(%rbp,%rax,4),%edx
mov    -0x1018(%rbp),%ecx
lea    0xdea(%rip),%rdi
call   1030 <printf@plt>
jmp    1223 <main+0xf3>
mov    -0x1018(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1018(%rbp)
jmp    11ae <main+0x7e>
xor    %eax,%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %rsp,%rbx
xor    %r15d,%r15d
lea    0xeb5(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    1179 <main+0x49>
add    $0x1,%r15
add    $0x4,%rbx
cmp    $0x400,%r15
jne    1150 <main+0x20>
mov    $0x400,%r15d
jmp    117e <main+0x4e>
test   %r15d,%r15d
je     11bf <main+0x8f>
mov    %r15d,%r14d
xor    %ebx,%ebx
mov    %rsp,%r15
lea    0xe76(%rip),%r12
jmp    1199 <main+0x69>
nop
add    $0x1,%rbx
cmp    %rbx,%r14
je     11bf <main+0x8f>
mov    (%rsp,%rbx,4),%edx
mov    %r15,%rdi
mov    %r14d,%esi
call   1050 <seq_search@plt>
mov    %eax,%ecx
cmp    %rcx,%rbx
je     1190 <main+0x60>
mov    (%rsp,%rbx,4),%edx
mov    %r12,%rdi
mov    %eax,%esi
mov    %ebx,%ecx
call   1030 <printf@plt>
jmp    1190 <main+0x60>
xor    %eax,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [55 x i8] c"seq_search() returned %d looking for %d - expected %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %6
6: ; preds = %17, %0
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 1024
br i1 %8, label %9, label %20
9: ; preds = %6
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [1024 x i32], [1024 x i32]* %2, i64 0, i64 %11
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %12)
%14 = icmp ne i32 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %9
br label %20
16: ; preds = %9
br label %17
17: ; preds = %16
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %6
20: ; preds = %15, %6
store i32 0, i32* %4
br label %21
21: ; preds = %45, %20
%22 = load i32, i32* %4
%23 = load i32, i32* %3
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %48
25: ; preds = %21
%26 = getelementptr inbounds [1024 x i32], [1024 x i32]* %2, i64 0, i64 0
%27 = load i32, i32* %3
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [1024 x i32], [1024 x i32]* %2, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = call i32 @seq_search(i32* %26, i32 %27, i32 %31)
store i32 %32, i32* %5
%33 = load i32, i32* %5
%34 = load i32, i32* %4
%35 = icmp ne i32 %33, %34
br i1 %35, label %36, label %44
36: ; preds = %25
%37 = load i32, i32* %5
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [1024 x i32], [1024 x i32]* %2, i64 0, i64 %39
%41 = load i32, i32* %40
%42 = load i32, i32* %4
%43 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i32 %37, i32 %41, i32 %42)
br label %44
44: ; preds = %36, %25
br label %45
45: ; preds = %44
%46 = load i32, i32* %4
%47 = add nsw i32 %46, 1
store i32 %47, i32* %4
br label %21
48: ; preds = %21
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [55 x i8] c"seq_search() returned %d looking for %d - expected %d\0A\00"
define i32 @main() {
%1 = alloca [1024 x i32]
%2 = bitcast [1024 x i32]* %1 to i8*
br label %3
3: ; preds = %0, %8
%4 = phi i64 [ 0, %0 ], [ %9, %8 ]
%5 = getelementptr inbounds [1024 x i32], [1024 x i32]* %1, i64 0, i64 %4
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = add nuw nsw i64 %4, 1
%10 = icmp eq i64 %9, 1024
br i1 %10, label %14, label %3
11: ; preds = %3
%12 = trunc i64 %4 to i32
%13 = icmp eq i32 %12, 0
br i1 %13, label %32, label %14
14: ; preds = %8, %11
%15 = phi i32 [ %12, %11 ], [ 1024, %8 ]
%16 = getelementptr inbounds [1024 x i32], [1024 x i32]* %1, i64 0, i64 0
%17 = zext i32 %15 to i64
br label %18
18: ; preds = %14, %29
%19 = phi i64 [ 0, %14 ], [ %30, %29 ]
%20 = getelementptr inbounds [1024 x i32], [1024 x i32]* %1, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = call i32 @seq_search(i32* %16, i32 %15, i32 %21)
%23 = zext i32 %22 to i64
%24 = icmp eq i64 %19, %23
br i1 %24, label %29, label %25
25: ; preds = %18
%26 = load i32, i32* %20
%27 = trunc i64 %19 to i32
%28 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 %26, i32 %27)
br label %29
29: ; preds = %25, %18
%30 = add nuw nsw i64 %19, 1
%31 = icmp eq i64 %30, %17
br i1 %31, label %32, label %18
32: ; preds = %29, %11
ret i32 0
}