#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 */
struct Ballot {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ Print_Results(int *, int);
int /*<<< orphan*/ Tally_Results(struct Ballot **, int *);
int /*<<< orphan*/ Tally_Secondary_Results(struct Ballot **, int *, int, int,
                                           int, int);
int /*<<< orphan*/ Top_Two(int *, int *, int *, int *, int *);
int /*<<< orphan*/ printf(char *, ...);
int Two_Round_Runoff(struct Ballot *Ballots[10000]) {
  printf("Two Round Runoff:\n");
  int Results[1503] = {0};
  Tally_Results(Ballots, Results);
  Print_Results(Results, 1503);
  int Biggest = -1, BiggestPos = -1, secondBiggest = -1, secondBiggestPos = -1;
  Top_Two(Results, &Biggest, &BiggestPos, &secondBiggest, &secondBiggestPos);
  float top = Biggest / 10000;
  if (top >= 0.5) {
    printf("%d is the Two Round Runoff winner with %f percent of the votes.\n",
           BiggestPos + 1, top);
    return BiggestPos + 1;
  }
  int CandidateOne = 0;
  int CandidateTwo = 1;
  int SecondResults[2] = {0};
  Tally_Secondary_Results(Ballots, SecondResults, CandidateOne, CandidateTwo,
                          BiggestPos, secondBiggestPos);
  Print_Results(SecondResults, 2);
  if (SecondResults[CandidateOne] >= SecondResults[CandidateTwo]) {
    printf("%d is the Two Round Runoff winner\n", BiggestPos + 1);
    return BiggestPos + 1;
  } else {
    printf("%d is the Two Round Runoff winner\n", secondBiggestPos + 1);
    return secondBiggestPos + 1;
  }
}


x86 assembly (clang, -O0):
<Two_Round_Runoff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x17c0,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x1790(%rbp),%rdi
xor    %esi,%esi
mov    $0x177c,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x1790(%rbp),%rsi
call   1040 <Tally_Results@plt>
lea    -0x1790(%rbp),%rdi
mov    $0x5df,%esi
call   1080 <Print_Results@plt>
movl   $0xffffffff,-0x1794(%rbp)
ff ff ff
movl   $0xffffffff,-0x1798(%rbp)
ff ff ff
movl   $0xffffffff,-0x179c(%rbp)
ff ff ff
movl   $0xffffffff,-0x17a0(%rbp)
ff ff ff
lea    -0x1790(%rbp),%rdi
lea    -0x1794(%rbp),%rsi
lea    -0x1798(%rbp),%rdx
lea    -0x179c(%rbp),%rcx
lea    -0x17a0(%rbp),%r8
call   1070 <Top_Two@plt>
mov    -0x1794(%rbp),%eax
mov    $0x2710,%ecx
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x17a4(%rbp)
ff
movss  -0x17a4(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
movsd  0xdd1(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     126d <Two_Round_Runoff+0x10d>
mov    -0x1798(%rbp),%esi
add    $0x1,%esi
movss  -0x17a4(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
lea    0xdc6(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x1798(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    133c <Two_Round_Runoff+0x1dc>
movl   $0x0,-0x17a8(%rbp)
movl   $0x1,-0x17ac(%rbp)
lea    -0x17b4(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x17b4(%rbp),%rsi
mov    -0x17a8(%rbp),%edx
mov    -0x17ac(%rbp),%ecx
mov    -0x1798(%rbp),%r8d
mov    -0x17a0(%rbp),%r9d
call   1030 <Tally_Secondary_Results@plt>
lea    -0x17b4(%rbp),%rdi
mov    $0x2,%esi
call   1080 <Print_Results@plt>
movslq -0x17a8(%rbp),%rax
mov    -0x17b4(%rbp,%rax,4),%eax
movslq -0x17ac(%rbp),%rcx
cmp    -0x17b4(%rbp,%rcx,4),%eax
jl     1319 <Two_Round_Runoff+0x1b9>
mov    -0x1798(%rbp),%esi
add    $0x1,%esi
lea    0xd5b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1798(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    133c <Two_Round_Runoff+0x1dc>
mov    -0x17a0(%rbp),%esi
add    $0x1,%esi
lea    0xd33(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x17a0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x17c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Two_Round_Runoff>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x17a8,%rsp
mov    %rdi,%r14
lea    0xedc(%rip),%rdi
call   1050 <puts@plt>
lea    0x20(%rsp),%r12
mov    $0x177c,%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <Tally_Results@plt>
mov    %r12,%rdi
mov    $0x5df,%esi
call   1090 <Print_Results@plt>
movl   $0xffffffff,0xc(%rsp)
ff
movl   $0xffffffff,0x4(%rsp)
ff
movl   $0xffffffff,0x1c(%rsp)
ff
movl   $0xffffffff,0x8(%rsp)
ff
lea    0xc(%rsp),%rsi
lea    0x4(%rsp),%rbx
lea    0x1c(%rsp),%rcx
lea    0x8(%rsp),%r15
mov    %r12,%rdi
mov    %rbx,%rdx
mov    %r15,%r8
call   1080 <Top_Two@plt>
mov    0xc(%rsp),%eax
cmp    $0x2710,%eax
jl     1238 <Two_Round_Runoff+0xc8>
mov    %eax,%eax
mov    $0xd1b71759,%ecx
imul   %rax,%rcx
shr    $0x2d,%rcx
cvtsi2ss %ecx,%xmm0
cvtss2sd %xmm0,%xmm0
mov    0x4(%rsp),%esi
add    $0x1,%esi
lea    0xdd5(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    0x4(%rsp),%eax
jmp    1290 <Two_Round_Runoff+0x120>
movq   $0x0,0x10(%rsp)
mov    0x4(%rsp),%r8d
mov    0x8(%rsp),%r9d
lea    0x10(%rsp),%r12
mov    %r14,%rdi
mov    %r12,%rsi
xor    %edx,%edx
mov    $0x1,%ecx
call   1030 <Tally_Secondary_Results@plt>
mov    %r12,%rdi
mov    $0x2,%esi
call   1090 <Print_Results@plt>
mov    0x10(%rsp),%eax
cmp    0x14(%rsp),%eax
cmovl  %r15,%rbx
mov    (%rbx),%esi
add    $0x1,%esi
lea    0xdba(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%rbx),%eax
add    $0x1,%eax
add    $0x17a8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.Ballot = type { i32 }
@.str = [19 x i8] c"Two Round Runoff:\0A\00"
@.str.1 = [65 x i8] c"%d is the Two Round Runoff winner with %f percent of the votes.\0A\00"
@.str.2 = [35 x i8] c"%d is the Two Round Runoff winner\0A\00"
define i32 @Two_Round_Runoff(%struct.Ballot** %0) {
%2 = alloca i32
%3 = alloca %struct.Ballot**
%4 = alloca [1503 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca float
%10 = alloca i32
%11 = alloca i32
%12 = alloca [2 x i32]
store %struct.Ballot** %0, %struct.Ballot*** %3
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%14 = bitcast [1503 x i32]* %4 to i8*
%15 = load %struct.Ballot**, %struct.Ballot*** %3
%16 = getelementptr inbounds [1503 x i32], [1503 x i32]* %4, i64 0, i64 0
%17 = call i32 @Tally_Results(%struct.Ballot** %15, i32* %16)
%18 = getelementptr inbounds [1503 x i32], [1503 x i32]* %4, i64 0, i64 0
%19 = call i32 @Print_Results(i32* %18, i32 1503)
store i32 -1, i32* %5
store i32 -1, i32* %6
store i32 -1, i32* %7
store i32 -1, i32* %8
%20 = getelementptr inbounds [1503 x i32], [1503 x i32]* %4, i64 0, i64 0
%21 = call i32 @Top_Two(i32* %20, i32* %5, i32* %6, i32* %7, i32* %8)
%22 = load i32, i32* %5
%23 = sdiv i32 %22, 10000
%24 = sitofp i32 %23 to float
store float %24, float* %9
%25 = load float, float* %9
%26 = fpext float %25 to double
%27 = fcmp oge double %26, 5.000000e-01
br i1 %27, label %28, label %36
28: ; preds = %1
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
%31 = load float, float* %9
%32 = fpext float %31 to double
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0), i32 %30, double %32)
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %2
br label %68
36: ; preds = %1
store i32 0, i32* %10
store i32 1, i32* %11
%37 = bitcast [2 x i32]* %12 to i8*
%38 = load %struct.Ballot**, %struct.Ballot*** %3
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%40 = load i32, i32* %10
%41 = load i32, i32* %11
%42 = load i32, i32* %6
%43 = load i32, i32* %8
%44 = call i32 @Tally_Secondary_Results(%struct.Ballot** %38, i32* %39, i32 %40, i32 %41, i32 %42, i32 %43)
%45 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%46 = call i32 @Print_Results(i32* %45, i32 2)
%47 = load i32, i32* %10
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = load i32, i32* %11
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 %52
%54 = load i32, i32* %53
%55 = icmp sge i32 %50, %54
br i1 %55, label %56, label %62
56: ; preds = %36
%57 = load i32, i32* %6
%58 = add nsw i32 %57, 1
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %58)
%60 = load i32, i32* %6
%61 = add nsw i32 %60, 1
store i32 %61, i32* %2
br label %68
62: ; preds = %36
%63 = load i32, i32* %8
%64 = add nsw i32 %63, 1
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %64)
%66 = load i32, i32* %8
%67 = add nsw i32 %66, 1
store i32 %67, i32* %2
br label %68
68: ; preds = %62, %56, %28
%69 = load i32, i32* %2
ret i32 %69
}

LLVM IR (-O2):
%struct.Ballot = type { i32 }
@.str.1 = [65 x i8] c"%d is the Two Round Runoff winner with %f percent of the votes.\0A\00"
@.str.2 = [35 x i8] c"%d is the Two Round Runoff winner\0A\00"
@str = [18 x i8] c"Two Round Runoff:\00"
define i32 @Two_Round_Runoff(%struct.Ballot** %0) {
%2 = alloca [1503 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%9 = bitcast [1503 x i32]* %2 to i8*
%10 = getelementptr inbounds [1503 x i32], [1503 x i32]* %2, i64 0, i64 0
%11 = call i32 @Tally_Results(%struct.Ballot** %0, i32* %10)
%12 = call i32 @Print_Results(i32* %10, i32 1503)
%13 = bitcast i32* %3 to i8*
store i32 -1, i32* %3
%14 = bitcast i32* %4 to i8*
store i32 -1, i32* %4
%15 = bitcast i32* %5 to i8*
store i32 -1, i32* %5
%16 = bitcast i32* %6 to i8*
store i32 -1, i32* %6
%17 = call i32 @Top_Two(i32* %10, i32* %3, i32* %4, i32* %5, i32* %6)
%18 = load i32, i32* %3
%19 = icmp sgt i32 %18, 9999
br i1 %19, label %20, label %28
20: ; preds = %1
%21 = udiv i32 %18, 10000
%22 = sitofp i32 %21 to float
%23 = fpext float %22 to double
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0), i32 %25, double %23)
%27 = load i32, i32* %4
br label %48
28: ; preds = %1
%29 = bitcast i64* %7 to [2 x i32]*
%30 = bitcast i64* %7 to i8*
store i64 0, i64* %7
%31 = bitcast i64* %7 to i32*
%32 = load i32, i32* %4
%33 = load i32, i32* %6
%34 = call i32 @Tally_Secondary_Results(%struct.Ballot** %0, i32* %31, i32 0, i32 1, i32 %32, i32 %33)
%35 = call i32 @Print_Results(i32* %31, i32 2)
%36 = load i32, i32* %31
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %29, i64 0, i64 1
%38 = load i32, i32* %37
%39 = icmp slt i32 %36, %38
%40 = load i32, i32* %6
%41 = load i32, i32* %4
%42 = select i1 %39, i32 %40, i32 %41
%43 = add nsw i32 %42, 1
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %43)
%45 = load i32, i32* %6
%46 = load i32, i32* %4
%47 = select i1 %39, i32 %45, i32 %46
br label %48
48: ; preds = %28, %20
%49 = phi i32 [ %27, %20 ], [ %47, %28 ]
%50 = add nsw i32 %49, 1
ret i32 %50
}