#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 Argmax(int *, int);
int /*<<< orphan*/ Print_Results(int *, int);
int /*<<< orphan*/ Tally_Results(struct Ballot **, int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int Plurality(struct Ballot *Ballots[10000]) {
  printf("Plurality:\n");
  int Results[1503] = {0};
  Tally_Results(Ballots, Results);
  Print_Results(Results, 1503);
  int finalResult = Argmax(Results, 1503);
  if (finalResult <= 0) {
    perror(
        "Ballots array was blank, Plurality winner couldn't be determined\n");
    return -1;
  }
  printf("%d is the Plurality winner\n\n", finalResult);
  return finalResult;
}


x86 assembly (clang, -O0):
<Plurality>:
push   %rbp
mov    %rsp,%rbp
sub    $0x17a0,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1790(%rbp),%rdi
xor    %esi,%esi
mov    $0x177c,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x1790(%rbp),%rsi
call   1030 <Tally_Results@plt>
lea    -0x1790(%rbp),%rdi
mov    $0x5df,%esi
call   1080 <Print_Results@plt>
lea    -0x1790(%rbp),%rdi
mov    $0x5df,%esi
call   1060 <Argmax@plt>
mov    %eax,-0x1794(%rbp)
cmpl   $0x0,-0x1794(%rbp)
jg     11ed <Plurality+0x8d>
lea    0xe30(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <Plurality+0xaa>
mov    -0x1794(%rbp),%esi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1794(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x17a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Plurality>:
push   %r14
push   %rbx
sub    $0x1788,%rsp
mov    %rdi,%r14
lea    0xedb(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rbx
mov    $0x177c,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <Tally_Results@plt>
mov    %rbx,%rdi
mov    $0x5df,%esi
call   1090 <Print_Results@plt>
mov    %rbx,%rdi
mov    $0x5df,%esi
call   1070 <Argmax@plt>
test   %eax,%eax
jle    11e3 <Plurality+0x73>
mov    %eax,%ebx
lea    0xe75(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
add    $0x1788,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe16(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%ebx
jmp    11d6 <Plurality+0x66>

LLVM IR (-O0):
%struct.Ballot = type { i32 }
@.str = [12 x i8] c"Plurality:\0A\00"
@.str.1 = [66 x i8] c"Ballots array was blank, Plurality winner couldn't be determined\0A\00"
@.str.2 = [29 x i8] c"%d is the Plurality winner\0A\0A\00"
define i32 @Plurality(%struct.Ballot** %0) {
%2 = alloca i32
%3 = alloca %struct.Ballot**
%4 = alloca [1503 x i32]
%5 = alloca i32
store %struct.Ballot** %0, %struct.Ballot*** %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%7 = bitcast [1503 x i32]* %4 to i8*
%8 = load %struct.Ballot**, %struct.Ballot*** %3
%9 = getelementptr inbounds [1503 x i32], [1503 x i32]* %4, i64 0, i64 0
%10 = call i32 @Tally_Results(%struct.Ballot** %8, i32* %9)
%11 = getelementptr inbounds [1503 x i32], [1503 x i32]* %4, i64 0, i64 0
%12 = call i32 @Print_Results(i32* %11, i32 1503)
%13 = getelementptr inbounds [1503 x i32], [1503 x i32]* %4, i64 0, i64 0
%14 = call i32 @Argmax(i32* %13, i32 1503)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = icmp sle i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %1
%18 = call i32 @perror(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %23
19: ; preds = %1
%20 = load i32, i32* %5
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %5
store i32 %22, i32* %2
br label %23
23: ; preds = %19, %17
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
%struct.Ballot = type { i32 }
@.str.1 = [66 x i8] c"Ballots array was blank, Plurality winner couldn't be determined\0A\00"
@.str.2 = [29 x i8] c"%d is the Plurality winner\0A\0A\00"
@str = [11 x i8] c"Plurality:\00"
define i32 @Plurality(%struct.Ballot** %0) {
%2 = alloca [1503 x i32]
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%4 = bitcast [1503 x i32]* %2 to i8*
%5 = getelementptr inbounds [1503 x i32], [1503 x i32]* %2, i64 0, i64 0
%6 = call i32 @Tally_Results(%struct.Ballot** %0, i32* %5)
%7 = call i32 @Print_Results(i32* %5, i32 1503)
%8 = call i32 @Argmax(i32* %5, i32 1503)
%9 = icmp slt i32 %8, 1
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.1, i64 0, i64 0))
br label %14
12: ; preds = %1
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %8)
br label %14
14: ; preds = %12, %10
%15 = phi i32 [ -1, %10 ], [ %8, %12 ]
ret i32 %15
}