#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 another_search(int *, int, int);
int /*<<< orphan*/ print_array(int *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int a[20 + 1] = {0};
  int i = 0;
  int key = 0;
  int index = 0;
  srand((unsigned int)time(NULL));
  for (i = 1; i <= 20; i++)
    a[i] = rand() % 100;
  key = rand() % 100;
  printf("Another Search Demo\n");
  printf("Key: %d\n", key);
  printf("Array: \n");
  print_array(a, 1, 20);
  index = another_search(a, 20, key);
  if (index > 0)
    printf("Success: a[%d] = %d\n", index, a[index]);
  else
    printf("Failed!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x54,%edx
call   1050 <memset@plt>
movl   $0x0,-0x74(%rbp)
movl   $0x0,-0x78(%rbp)
movl   $0x0,-0x7c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movl   $0x1,-0x74(%rbp)
cmpl   $0x14,-0x74(%rbp)
jg     11f4 <main+0x84>
mov    $0x0,%al
call   1090 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
movslq -0x74(%rbp),%rax
mov    %edx,-0x70(%rbp,%rax,4)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    11c5 <main+0x55>
mov    $0x0,%al
call   1090 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,-0x78(%rbp)
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x78(%rbp),%esi
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    $0x1,%esi
mov    $0x14,%edx
call   1030 <print_array@plt>
lea    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%edx
mov    $0x14,%esi
call   1070 <another_search@plt>
mov    %eax,-0x7c(%rbp)
cmpl   $0x0,-0x7c(%rbp)
jle    1282 <main+0x112>
mov    -0x7c(%rbp),%esi
movslq -0x7c(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%edx
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1290 <main+0x120>
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x58,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x50(%rsp)
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    $0x1,%ebx
nopl   (%rax)
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x15,%rbx
jne    11b0 <main+0x40>
xor    %eax,%eax
call   1090 <rand@plt>
movslq %eax,%rbx
imul   $0x51eb851f,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%ebx
lea    0xe15(%rip),%rdi
call   1030 <puts@plt>
lea    0xdeb(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe0d(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x14,%edx
call   1040 <print_array@plt>
mov    %r14,%rdi
mov    $0x14,%esi
mov    %ebx,%edx
call   1070 <another_search@plt>
test   %eax,%eax
jle    1269 <main+0xf9>
mov    %eax,%ecx
mov    (%rsp,%rcx,4),%edx
lea    0xdab(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1275 <main+0x105>
lea    0xdca(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Another Search Demo\0A\00"
@.str.1 = [9 x i8] c"Key: %d\0A\00"
@.str.2 = [9 x i8] c"Array: \0A\00"
@.str.3 = [21 x i8] c"Success: a[%d] = %d\0A\00"
@.str.4 = [9 x i8] c"Failed!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [21 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [21 x i32]* %6 to i8*
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%11 = call i64 @time(i32* null)
%12 = trunc i64 %11 to i32
%13 = call i32 @srand(i32 %12)
store i32 1, i32* %7
br label %14
14: ; preds = %23, %2
%15 = load i32, i32* %7
%16 = icmp sle i32 %15, 20
br i1 %16, label %17, label %26
17: ; preds = %14
%18 = call i32 (...) @rand()
%19 = srem i32 %18, 100
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 %21
store i32 %19, i32* %22
br label %23
23: ; preds = %17
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %14
26: ; preds = %14
%27 = call i32 (...) @rand()
%28 = srem i32 %27, 100
store i32 %28, i32* %8
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%30 = load i32, i32* %8
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%33 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 0
%34 = call i32 @print_array(i32* %33, i32 1, i32 20)
%35 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 0
%36 = load i32, i32* %8
%37 = call i32 @another_search(i32* %35, i32 20, i32 %36)
store i32 %37, i32* %9
%38 = load i32, i32* %9
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %47
40: ; preds = %26
%41 = load i32, i32* %9
%42 = load i32, i32* %9
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %41, i32 %45)
br label %49
47: ; preds = %26
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %49
49: ; preds = %47, %40
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [9 x i8] c"Key: %d\0A\00"
@.str.3 = [21 x i8] c"Success: a[%d] = %d\0A\00"
@str = [20 x i8] c"Another Search Demo\00"
@str.5 = [8 x i8] c"Array: \00"
@str.6 = [8 x i8] c"Failed!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [21 x i32]
%4 = bitcast [21 x i32]* %3 to i8*
%5 = tail call i64 @time(i32* null)
%6 = trunc i64 %5 to i32
%7 = tail call i32 @srand(i32 %6)
br label %8
8: ; preds = %2, %8
%9 = phi i64 [ 1, %2 ], [ %13, %8 ]
%10 = tail call i32 (...) @rand()
%11 = srem i32 %10, 100
%12 = getelementptr inbounds [21 x i32], [21 x i32]* %3, i64 0, i64 %9
store i32 %11, i32* %12
%13 = add nuw nsw i64 %9, 1
%14 = icmp eq i64 %13, 21
br i1 %14, label %15, label %8
15: ; preds = %8
%16 = tail call i32 (...) @rand()
%17 = srem i32 %16, 100
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.5, i64 0, i64 0))
%21 = getelementptr inbounds [21 x i32], [21 x i32]* %3, i64 0, i64 0
%22 = call i32 @print_array(i32* %21, i32 1, i32 20)
%23 = call i32 @another_search(i32* %21, i32 20, i32 %17)
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %15
%26 = zext i32 %23 to i64
%27 = getelementptr inbounds [21 x i32], [21 x i32]* %3, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %23, i32 %28)
br label %32
30: ; preds = %15
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.6, i64 0, i64 0))
br label %32
32: ; preds = %30, %25
ret i32 0
}