#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 */
unsigned int input(unsigned int);
unsigned int num_peers();
int /*<<< orphan*/ printf(char *, unsigned int, unsigned int);
int main() {
  unsigned int cur_max = input(0);
  unsigned int max_i = 0;
  for (unsigned int i = 1; i < num_peers(); i++) {
    unsigned int val = input(i);
    if (val > cur_max) {
      cur_max = val;
      max_i = i;
    }
  }
  printf("Participant %d had max value %d\n", max_i, cur_max);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1030 <input@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1050 <num_peers@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jae    11a7 <main+0x77>
mov    -0x10(%rbp),%edi
call   1030 <input@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jbe    1194 <main+0x64>
mov    -0x14(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1199 <main+0x69>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1157 <main+0x27>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe4c(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %r14d,%r14d
xor    %edi,%edi
call   1030 <input@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <num_peers@plt>
cmp    $0x2,%eax
jb     117e <main+0x4e>
mov    $0x1,%ebp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
call   1030 <input@plt>
cmp    %ebx,%eax
cmova  %ebp,%r14d
cmova  %eax,%ebx
add    $0x1,%ebp
xor    %eax,%eax
call   1050 <num_peers@plt>
cmp    %eax,%ebp
jb     1160 <main+0x30>
lea    0xe7b(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Participant %d had max value %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @input(i32 0)
store i32 %6, i32* %2
store i32 0, i32* %3
store i32 1, i32* %4
br label %7
7: ; preds = %21, %0
%8 = load i32, i32* %4
%9 = call i32 (...) @num_peers()
%10 = icmp ult i32 %8, %9
br i1 %10, label %11, label %24
11: ; preds = %7
%12 = load i32, i32* %4
%13 = call i32 @input(i32 %12)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = load i32, i32* %2
%16 = icmp ugt i32 %14, %15
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load i32, i32* %5
store i32 %18, i32* %2
%19 = load i32, i32* %4
store i32 %19, i32* %3
br label %20
20: ; preds = %17, %11
br label %21
21: ; preds = %20
%22 = load i32, i32* %4
%23 = add i32 %22, 1
store i32 %23, i32* %4
br label %7
24: ; preds = %7
%25 = load i32, i32* %3
%26 = load i32, i32* %2
%27 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %25, i32 %26)
ret i32 0
}

LLVM IR (-O2):
@.str = [33 x i8] c"Participant %d had max value %d\0A\00"
define i32 @main() {
%1 = tail call i32 @input(i32 0)
%2 = tail call i32 (...) @num_peers()
%3 = icmp ugt i32 %2, 1
br i1 %3, label %8, label %4
4: ; preds = %8, %0
%5 = phi i32 [ 0, %0 ], [ %14, %8 ]
%6 = phi i32 [ %1, %0 ], [ %15, %8 ]
%7 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
ret i32 0
8: ; preds = %0, %8
%9 = phi i32 [ %15, %8 ], [ %1, %0 ]
%10 = phi i32 [ %16, %8 ], [ 1, %0 ]
%11 = phi i32 [ %14, %8 ], [ 0, %0 ]
%12 = tail call i32 @input(i32 %10)
%13 = icmp ugt i32 %12, %9
%14 = select i1 %13, i32 %10, i32 %11
%15 = select i1 %13, i32 %12, i32 %9
%16 = add nuw i32 %10, 1
%17 = tail call i32 (...) @num_peers()
%18 = icmp ult i32 %16, %17
br i1 %18, label %8, label %4
}