#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 greatest_among_three(int, int, int);
int /*<<< orphan*/ printf(char *, int, int, int, int);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, const char *argv[]) {
  int num1 = 0, num2 = 0, num3 = 0;
  srand(time(NULL));
  for (int i = 0; i < 10; i++) {
    num1 = rand() % 1000;
    num2 = rand() % 1000;
    num3 = rand() % 1000;
    printf("Greatest among (%d,%d,%d) is %d\n", num1, num2, num3,
           greatest_among_three(num1, num2, num3));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
movl   $0x0,-0x20(%rbp)
cmpl   $0xa,-0x20(%rbp)
jge    1218 <main+0xc8>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1030 <greatest_among_three@plt>
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    %eax,%r8d
lea    0xdfb(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1192 <main+0x42>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    $0xa,%ebp
lea    0xe8e(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%r15
imul   $0x10624dd3,%r15,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
imul   $0x3e8,%eax,%eax
sub    %eax,%r15d
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%r12
imul   $0x10624dd3,%r12,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
imul   $0x3e8,%eax,%eax
sub    %eax,%r12d
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rbx
imul   $0x10624dd3,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
imul   $0x3e8,%eax,%eax
sub    %eax,%ebx
mov    %r15d,%edi
mov    %r12d,%esi
mov    %ebx,%edx
call   1030 <greatest_among_three@plt>
mov    %r14,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
call   1040 <printf@plt>
add    $0xffffffff,%ebp
jne    1180 <main+0x30>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Greatest among (%d,%d,%d) is %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca 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
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%10 = call i32 @time(i32* null)
%11 = call i32 @srand(i32 %10)
store i32 0, i32* %9
br label %12
12: ; preds = %30, %2
%13 = load i32, i32* %9
%14 = icmp slt i32 %13, 10
br i1 %14, label %15, label %33
15: ; preds = %12
%16 = call i32 (...) @rand()
%17 = srem i32 %16, 1000
store i32 %17, i32* %6
%18 = call i32 (...) @rand()
%19 = srem i32 %18, 1000
store i32 %19, i32* %7
%20 = call i32 (...) @rand()
%21 = srem i32 %20, 1000
store i32 %21, i32* %8
%22 = load i32, i32* %6
%23 = load i32, i32* %7
%24 = load i32, i32* %8
%25 = load i32, i32* %6
%26 = load i32, i32* %7
%27 = load i32, i32* %8
%28 = call i32 @greatest_among_three(i32 %25, i32 %26, i32 %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %22, i32 %23, i32 %24, i32 %28)
br label %30
30: ; preds = %15
%31 = load i32, i32* %9
%32 = add nsw i32 %31, 1
store i32 %32, i32* %9
br label %12
33: ; preds = %12
ret i32 0
}

LLVM IR (-O2):
@.str = [33 x i8] c"Greatest among (%d,%d,%d) is %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
br label %6
5: ; preds = %6
ret i32 0
6: ; preds = %2, %6
%7 = phi i32 [ 0, %2 ], [ %16, %6 ]
%8 = tail call i32 (...) @rand()
%9 = srem i32 %8, 1000
%10 = tail call i32 (...) @rand()
%11 = srem i32 %10, 1000
%12 = tail call i32 (...) @rand()
%13 = srem i32 %12, 1000
%14 = tail call i32 @greatest_among_three(i32 %9, i32 %11, i32 %13)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %11, i32 %13, i32 %14)
%16 = add nuw nsw i32 %7, 1
%17 = icmp eq i32 %16, 10
br i1 %17, label %5, label %6
}