#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 EX_OK;
int /*<<< orphan*/ printf(char *, ...);
int rand();
int search(int *, int, int, int);
int /*<<< orphan*/ srand(unsigned int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  int result;
  unsigned seed = (unsigned)time(NULL);
  int count = 4;
  int limit = 4;
  int values[count];
  int index;
  printf("Seed: %u\n", seed);
  srand(seed);
  printf("Input:\n");
  for (index = 0; index < count; index++) {
    values[index] = rand() % limit;
    printf("%8d: %d\n", index, values[index]);
  }
  result = search(values, count, count / 2, count / 2);
  if (result != -1) {
    printf("Peak found at index %d: %d\n", result, values[result]);
  } else {
    printf("No peak found\n");
  }
  return EX_OK;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0xc(%rbp)
movl   $0x4,-0x10(%rbp)
movl   $0x4,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <srand@plt>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1216 <main+0xc6>
mov    $0x0,%al
call   1070 <rand@plt>
cltd
idivl  -0x14(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%esi
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ce <main+0x7e>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x3c(%rbp),%edx
mov    %eax,%ecx
call   1040 <search@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
je     126e <main+0x11e>
mov    -0x38(%rbp),%rax
mov    -0x8(%rbp),%esi
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    127c <main+0x12c>
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%ebx
lea    0xe8b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1060 <srand@plt>
lea    0xea3(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1080 <rand@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
mov    %eax,(%rsp)
lea    0xe5b(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1080 <rand@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
mov    %eax,0x4(%rsp)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1080 <rand@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
mov    %eax,0x8(%rsp)
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1080 <rand@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
mov    %eax,0xc(%rsp)
mov    %rbx,%rdi
mov    $0x3,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rdi
mov    $0x4,%esi
mov    $0x2,%edx
mov    $0x2,%ecx
call   1050 <search@plt>
cmp    $0xffffffff,%eax
je     126c <main+0x10c>
movslq %eax,%rcx
mov    (%rsp,%rcx,4),%edx
lea    0xdb2(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1278 <main+0x118>
lea    0xdc3(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d61(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"Seed: %u\0A\00"
@.str.1 = [8 x i8] c"Input:\0A\00"
@.str.2 = [9 x i8] c"%8d: %d\0A\00"
@.str.3 = [28 x i8] c"Peak found at index %d: %d\0A\00"
@.str.4 = [15 x i8] c"No peak found\0A\00"
@EX_OK = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 @time(i32* null)
store i32 %9, i32* %3
store i32 4, i32* %4
store i32 4, i32* %5
%10 = load i32, i32* %4
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %6
%13 = alloca i32, i64 %11
store i64 %11, i64* %7
%14 = load i32, i32* %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %3
%17 = call i32 @srand(i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %8
br label %19
19: ; preds = %36, %0
%20 = load i32, i32* %8
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %39
23: ; preds = %19
%24 = call i32 (...) @rand()
%25 = load i32, i32* %5
%26 = srem i32 %24, %25
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %13, i64 %28
store i32 %26, i32* %29
%30 = load i32, i32* %8
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %13, i64 %32
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %30, i32 %34)
br label %36
36: ; preds = %23
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %19
39: ; preds = %19
%40 = load i32, i32* %4
%41 = load i32, i32* %4
%42 = sdiv i32 %41, 2
%43 = load i32, i32* %4
%44 = sdiv i32 %43, 2
%45 = call i32 @search(i32* %13, i32 %40, i32 %42, i32 %44)
store i32 %45, i32* %2
%46 = load i32, i32* %2
%47 = icmp ne i32 %46, -1
br i1 %47, label %48, label %55
48: ; preds = %39
%49 = load i32, i32* %2
%50 = load i32, i32* %2
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %13, i64 %51
%53 = load i32, i32* %52
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %49, i32 %53)
br label %57
55: ; preds = %39
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %57
57: ; preds = %55, %48
%58 = load i32, i32* @EX_OK
store i32 %58, i32* %1
%59 = load i8*, i8** %6
%60 = load i32, i32* %1
ret i32 %60
}

LLVM IR (-O2):
@.str = [10 x i8] c"Seed: %u\0A\00"
@.str.2 = [9 x i8] c"%8d: %d\0A\00"
@.str.3 = [28 x i8] c"Peak found at index %d: %d\0A\00"
@EX_OK = global i32 0
@str = [7 x i8] c"Input:\00"
@str.5 = [14 x i8] c"No peak found\00"
define i32 @main() {
%1 = tail call i32 @time(i32* null)
%2 = alloca [4 x i32]
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %1)
%4 = tail call i32 @srand(i32 %1)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, 4
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
store i32 %7, i32* %8
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 %7)
%10 = tail call i32 (...) @rand()
%11 = srem i32 %10, 4
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
store i32 %11, i32* %12
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 %11)
%14 = tail call i32 (...) @rand()
%15 = srem i32 %14, 4
%16 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
store i32 %15, i32* %16
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 2, i32 %15)
%18 = tail call i32 (...) @rand()
%19 = srem i32 %18, 4
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
store i32 %19, i32* %20
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 3, i32 %19)
%22 = call i32 @search(i32* %8, i32 4, i32 2, i32 2)
%23 = icmp eq i32 %22, -1
br i1 %23, label %29, label %24
24: ; preds = %0
%25 = sext i32 %22 to i64
%26 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %22, i32 %27)
br label %31
29: ; preds = %0
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0))
br label %31
31: ; preds = %29, %24
%32 = load i32, i32* @EX_OK
ret i32 %32
}