#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 KarmarkarKarp(int *, int);
int /*<<< orphan*/ NEWLINE();
int RAND_MAX;
int /*<<< orphan*/ Randomize();
int *hill_climbing(int);
int /*<<< orphan*/ printf(char *, int);
int rand();
int *repeated_random(int);
int *simulated_annealing(int);
main() {
  int loop_cnt;
  int *random_arr;
  int *hill_climing_arr;
  int *simulated_arr;
  int i;
  int set_A[100];
  loop_cnt = 25000;
  for (i = 0; i < 100; i++) {
    set_A[i] = rand();
  }
  Randomize();
  printf("On this computer RAND_MAX: %7d\n", RAND_MAX);
  printf("Number of iterations: %12d\n\n", loop_cnt);
  random_arr = repeated_random(loop_cnt);
  hill_climing_arr = hill_climbing(loop_cnt);
  simulated_arr = simulated_annealing(loop_cnt);
  NEWLINE();
  printf("KarmarkarKap residue = %d\n", KarmarkarKarp(set_A, 100));
  NEWLINE();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x61a8,-0x8(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x64,-0x24(%rbp)
jge    11cc <main+0x4c>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    %eax,%ecx
movslq -0x24(%rbp),%rax
mov    %ecx,-0x1c0(%rbp,%rax,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a0 <main+0x20>
mov    $0x0,%al
call   1080 <Randomize@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
lea    0xe1d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xe2e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1090 <repeated_random@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <hill_climbing@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <simulated_annealing@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <NEWLINE@plt>
lea    -0x1c0(%rbp),%rdi
mov    $0x64,%esi
call   1040 <KarmarkarKarp@plt>
mov    %eax,%esi
lea    0xe01(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <NEWLINE@plt>
mov    -0x4(%rbp),%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x190,%rsp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x64,%rbx
jne    1190 <main+0x10>
xor    %eax,%eax
call   1080 <Randomize@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
lea    0xe45(%rip),%rdi
call   1030 <printf@plt>
lea    0xe59(%rip),%rdi
mov    $0x61a8,%esi
call   1030 <printf@plt>
mov    $0x61a8,%edi
call   1090 <repeated_random@plt>
mov    $0x61a8,%edi
call   1060 <hill_climbing@plt>
mov    $0x61a8,%edi
call   1070 <simulated_annealing@plt>
xor    %eax,%eax
call   1050 <NEWLINE@plt>
mov    %rsp,%rdi
mov    $0x64,%esi
call   1040 <KarmarkarKarp@plt>
lea    0xe33(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <NEWLINE@plt>
xor    %eax,%eax
add    $0x190,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [32 x i8] c"On this computer RAND_MAX: %7d\0A\00"
@RAND_MAX = global i32 0
@.str.1 = [29 x i8] c"Number of iterations: %12d\0A\0A\00"
@.str.2 = [27 x i8] c"KarmarkarKap residue = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca [100 x i32]
store i32 0, i32* %1
store i32 25000, i32* %2
store i32 0, i32* %6
br label %8
8: ; preds = %16, %0
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 100
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = call i32 (...) @rand()
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [100 x i32], [100 x i32]* %7, i64 0, i64 %14
store i32 %12, i32* %15
br label %16
16: ; preds = %11
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 1
store i32 %18, i32* %6
br label %8
19: ; preds = %8
%20 = call i32 (...) @Randomize()
%21 = load i32, i32* @RAND_MAX
%22 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %2
%24 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %2
%26 = call i32* @repeated_random(i32 %25)
store i32* %26, i32** %3
%27 = load i32, i32* %2
%28 = call i32* @hill_climbing(i32 %27)
store i32* %28, i32** %4
%29 = load i32, i32* %2
%30 = call i32* @simulated_annealing(i32 %29)
store i32* %30, i32** %5
%31 = call i32 (...) @NEWLINE()
%32 = getelementptr inbounds [100 x i32], [100 x i32]* %7, i64 0, i64 0
%33 = call i32 @KarmarkarKarp(i32* %32, i32 100)
%34 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = call i32 (...) @NEWLINE()
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@.str = [32 x i8] c"On this computer RAND_MAX: %7d\0A\00"
@RAND_MAX = global i32 0
@.str.1 = [29 x i8] c"Number of iterations: %12d\0A\0A\00"
@.str.2 = [27 x i8] c"KarmarkarKap residue = %d\0A\00"
define i32 @main() {
%1 = alloca [100 x i32]
%2 = bitcast [100 x i32]* %1 to i8*
br label %3
3: ; preds = %0, %3
%4 = phi i64 [ 0, %0 ], [ %7, %3 ]
%5 = tail call i32 (...) @rand()
%6 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %4
store i32 %5, i32* %6
%7 = add nuw nsw i64 %4, 1
%8 = icmp eq i64 %7, 100
br i1 %8, label %9, label %3
9: ; preds = %3
%10 = tail call i32 (...) @Randomize()
%11 = load i32, i32* @RAND_MAX
%12 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 25000)
%14 = tail call i32* @repeated_random(i32 25000)
%15 = tail call i32* @hill_climbing(i32 25000)
%16 = tail call i32* @simulated_annealing(i32 25000)
%17 = tail call i32 (...) @NEWLINE()
%18 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%19 = call i32 @KarmarkarKarp(i32* %18, i32 100)
%20 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = call i32 (...) @NEWLINE()
ret i32 0
}