#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 bidder = 0;
  unsigned int ultimate = input(0);
  unsigned int penultimate = 0;
  for (unsigned int i = 1; i < num_peers(); i++) {
    unsigned int bid = input(i);
    if (bid > ultimate) {
      bidder = i;
      penultimate = ultimate;
      ultimate = bid;
    } else if (bid > penultimate) {
      penultimate = bid;
    }
  }
  printf("Bidder %d pays %d\n", bidder, penultimate);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
xor    %edi,%edi
call   1030 <input@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1050 <num_peers@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jae    11d0 <main+0xa0>
mov    -0x14(%rbp),%edi
call   1030 <input@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jbe    11a6 <main+0x76>
mov    -0x14(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11bd <main+0x8d>
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jbe    11b8 <main+0x88>
mov    -0x18(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11bd <main+0x8d>
jmp    11c2 <main+0x92>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115e <main+0x2e>
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe23(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %ebx,%ebx
xor    %edi,%edi
call   1030 <input@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1050 <num_peers@plt>
mov    $0x0,%r14d
cmp    $0x2,%eax
jb     11a1 <main+0x71>
mov    $0x1,%r12d
xor    %r14d,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12d,%edi
call   1030 <input@plt>
mov    %eax,%ebp
cmp    %ebx,%eax
cmova  %eax,%ebx
cmp    %r15d,%eax
cmovbe %r15d,%ebp
cmova  %r15d,%ebx
cmova  %r12d,%r14d
add    $0x1,%r12d
xor    %eax,%eax
call   1050 <num_peers@plt>
mov    %ebp,%r15d
cmp    %eax,%r12d
jb     1170 <main+0x40>
lea    0xe58(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [19 x i8] c"Bidder %d pays %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 ], [ %18, %8 ]
%6 = phi i32 [ 0, %0 ], [ %19, %8 ]
%7 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %5)
ret i32 0
8: ; preds = %0, %8
%9 = phi i32 [ %19, %8 ], [ 0, %0 ]
%10 = phi i32 [ %20, %8 ], [ 1, %0 ]
%11 = phi i32 [ %18, %8 ], [ 0, %0 ]
%12 = phi i32 [ %17, %8 ], [ %1, %0 ]
%13 = tail call i32 @input(i32 %10)
%14 = icmp ugt i32 %13, %12
%15 = icmp ugt i32 %13, %11
%16 = select i1 %15, i32 %13, i32 %11
%17 = select i1 %14, i32 %13, i32 %12
%18 = select i1 %14, i32 %12, i32 %16
%19 = select i1 %14, i32 %10, i32 %9
%20 = add nuw i32 %10, 1
%21 = tail call i32 (...) @num_peers()
%22 = icmp ult i32 %20, %21
br i1 %22, label %8, label %4
}