#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 /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
void mode(unsigned int freq[], const unsigned int answer[]) {
  size_t rating;
  size_t j;
  unsigned int h;
  unsigned int largest = 0;
  unsigned int modeValue = 0;
  printf("\n%s\n%s\n%s\n", "********", "  Mode", "********");
  for (rating = 1; rating <= 9; ++rating) {
    freq[rating] = 0;
  }
  for (j = 0; j < 99; ++j) {
    ++freq[answer[j]];
  }
  printf("%s%11s%19s\n\n%54s\n%54s\n\n", "Response", "Frequency", "Histogram",
         "1   1   2   2", "5   0   5   0   5");
  for (rating = 1; rating <= 9; ++rating) {
    printf("%8u%11u        ", rating, freq[rating]);
    if (freq[rating] > largest) {
      largest = freq[rating];
      modeValue = rating;
    }
    for (h = 1; h <= freq[rating]; ++h) {
      printf("%s", "*");
    }
    puts("");
  }
  printf("\nThe mode is the most frequent value.\n"
         "For this run the mode is %u which occurred"
         " %u times.\n",
         modeValue, largest);
}


x86 assembly (clang, -O0):
<mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
lea    0xebb(%rip),%rdi
lea    0xebf(%rip),%rcx
lea    0xec1(%rip),%rdx
mov    %rcx,%rsi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x1,-0x18(%rbp)
cmpq   $0x9,-0x18(%rbp)
ja     1190 <mode+0x70>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1165 <mode+0x45>
movq   $0x0,-0x20(%rbp)
cmpq   $0x63,-0x20(%rbp)
jae    11cc <mode+0xac>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%rdx
mov    (%rcx,%rdx,4),%ecx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1198 <mode+0x78>
lea    0xe48(%rip),%rdi
lea    0xe59(%rip),%rsi
lea    0xe5b(%rip),%rdx
lea    0xe5e(%rip),%rcx
lea    0xe61(%rip),%r8
lea    0xe68(%rip),%r9
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x1,-0x18(%rbp)
cmpq   $0x9,-0x18(%rbp)
ja     12b1 <mode+0x191>
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x28(%rbp),%eax
jbe    1256 <mode+0x136>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %eax,-0x2c(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x8(%rbp),%rcx
mov    -0x18(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
ja     1294 <mode+0x174>
lea    0xe08(%rip),%rdi
lea    0xd93(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    125d <mode+0x13d>
lea    0xd97(%rip),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1205 <mode+0xe5>
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %rdi,%r13
lea    0xec8(%rip),%rdi
lea    0xed5(%rip),%rdx
lea    0xec5(%rip),%rcx
mov    %rcx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
movups %xmm0,0x4(%r13)
movups %xmm0,0x14(%r13)
movl   $0x0,0x24(%r13)
mov    $0x2,%eax
nopw   0x0(%rax,%rax,1)
mov    -0x8(%rbp,%rax,4),%ecx
addl   $0x1,0x0(%r13,%rcx,4)
mov    -0x4(%rbp,%rax,4),%ecx
addl   $0x1,0x0(%r13,%rcx,4)
mov    0x0(%rbp,%rax,4),%ecx
addl   $0x1,0x0(%r13,%rcx,4)
add    $0x3,%rax
cmp    $0x65,%rax
jne    1170 <mode+0x50>
lea    0xe7c(%rip),%rdi
lea    0xe8d(%rip),%rsi
lea    0xe8f(%rip),%rdx
lea    0xe92(%rip),%rcx
lea    0xe95(%rip),%r8
lea    0xe9c(%rip),%r9
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebp
lea    0xe9b(%rip),%r15
xor    %r12d,%r12d
xor    %r14d,%r14d
jmp    11f4 <mode+0xd4>
nopl   (%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%rbp
cmp    $0xa,%rbp
je     1246 <mode+0x126>
mov    %r12d,%ebx
mov    0x0(%r13,%rbp,4),%edx
mov    %r15,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13,%rbp,4),%eax
cmp    %r14d,%eax
cmova  %eax,%r14d
mov    %ebp,%r12d
cmovbe %ebx,%r12d
test   %eax,%eax
je     11e0 <mode+0xc0>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x2a,%edi
call   1030 <putchar@plt>
add    $0x1,%ebx
cmp    0x0(%r13,%rbp,4),%ebx
jbe    1230 <mode+0x110>
jmp    11e0 <mode+0xc0>
lea    0xe33(%rip),%rdi
mov    %r12d,%esi
mov    %r14d,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"\0A%s\0A%s\0A%s\0A\00"
@.str.1 = [9 x i8] c"********\00"
@.str.2 = [7 x i8] c" Mode\00"
@.str.3 = [24 x i8] c"%s%11s%19s\0A\0A%54s\0A%54s\0A\0A\00"
@.str.4 = [9 x i8] c"Response\00"
@.str.5 = [10 x i8] c"Frequency\00"
@.str.6 = [10 x i8] c"Histogram\00"
@.str.7 = [14 x i8] c"1 1 2 2\00"
@.str.8 = [18 x i8] c"5 0 5 0 5\00"
@.str.9 = [16 x i8] c"%8u%11u \00"
@.str.10 = [3 x i8] c"%s\00"
@.str.11 = [2 x i8] c"*\00"
@.str.12 = [1 x i8] zeroinitializer
@.str.13 = [92 x i8] c"\0AThe mode is the most frequent value.\0AFor this run the mode is %u which occurred %u times.\0A\00"
define void @mode(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
store i32 0, i32* %8
store i32 0, i32* %9
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i64 1, i64* %5
br label %11
11: ; preds = %18, %2
%12 = load i64, i64* %5
%13 = icmp ule i64 %12, 9
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load i32*, i32** %3
%16 = load i64, i64* %5
%17 = getelementptr inbounds i32, i32* %15, i64 %16
store i32 0, i32* %17
br label %18
18: ; preds = %14
%19 = load i64, i64* %5
%20 = add i64 %19, 1
store i64 %20, i64* %5
br label %11
21: ; preds = %11
store i64 0, i64* %6
br label %22
22: ; preds = %35, %21
%23 = load i64, i64* %6
%24 = icmp ult i64 %23, 99
br i1 %24, label %25, label %38
25: ; preds = %22
%26 = load i32*, i32** %3
%27 = load i32*, i32** %4
%28 = load i64, i64* %6
%29 = getelementptr inbounds i32, i32* %27, i64 %28
%30 = load i32, i32* %29
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %26, i64 %31
%33 = load i32, i32* %32
%34 = add i32 %33, 1
store i32 %34, i32* %32
br label %35
35: ; preds = %25
%36 = load i64, i64* %6
%37 = add i64 %36, 1
store i64 %37, i64* %6
br label %22
38: ; preds = %22
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
store i64 1, i64* %5
br label %40
40: ; preds = %78, %38
%41 = load i64, i64* %5
%42 = icmp ule i64 %41, 9
br i1 %42, label %43, label %81
43: ; preds = %40
%44 = load i64, i64* %5
%45 = load i32*, i32** %3
%46 = load i64, i64* %5
%47 = getelementptr inbounds i32, i32* %45, i64 %46
%48 = load i32, i32* %47
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i64 %44, i32 %48)
%50 = load i32*, i32** %3
%51 = load i64, i64* %5
%52 = getelementptr inbounds i32, i32* %50, i64 %51
%53 = load i32, i32* %52
%54 = load i32, i32* %8
%55 = icmp ugt i32 %53, %54
br i1 %55, label %56, label %63
56: ; preds = %43
%57 = load i32*, i32** %3
%58 = load i64, i64* %5
%59 = getelementptr inbounds i32, i32* %57, i64 %58
%60 = load i32, i32* %59
store i32 %60, i32* %8
%61 = load i64, i64* %5
%62 = trunc i64 %61 to i32
store i32 %62, i32* %9
br label %63
63: ; preds = %56, %43
store i32 1, i32* %7
br label %64
64: ; preds = %73, %63
%65 = load i32, i32* %7
%66 = load i32*, i32** %3
%67 = load i64, i64* %5
%68 = getelementptr inbounds i32, i32* %66, i64 %67
%69 = load i32, i32* %68
%70 = icmp ule i32 %65, %69
br i1 %70, label %71, label %76
71: ; preds = %64
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
br label %73
73: ; preds = %71
%74 = load i32, i32* %7
%75 = add i32 %74, 1
store i32 %75, i32* %7
br label %64
76: ; preds = %64
%77 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.12, i64 0, i64 0))
br label %78
78: ; preds = %76
%79 = load i64, i64* %5
%80 = add i64 %79, 1
store i64 %80, i64* %5
br label %40
81: ; preds = %40
%82 = load i32, i32* %9
%83 = load i32, i32* %8
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.13, i64 0, i64 0), i32 %82, i32 %83)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"\0A%s\0A%s\0A%s\0A\00"
@.str.1 = [9 x i8] c"********\00"
@.str.2 = [7 x i8] c" Mode\00"
@.str.3 = [24 x i8] c"%s%11s%19s\0A\0A%54s\0A%54s\0A\0A\00"
@.str.4 = [9 x i8] c"Response\00"
@.str.5 = [10 x i8] c"Frequency\00"
@.str.6 = [10 x i8] c"Histogram\00"
@.str.7 = [14 x i8] c"1 1 2 2\00"
@.str.8 = [18 x i8] c"5 0 5 0 5\00"
@.str.9 = [16 x i8] c"%8u%11u \00"
@.str.13 = [92 x i8] c"\0AThe mode is the most frequent value.\0AFor this run the mode is %u which occurred %u times.\0A\00"
define void @mode(i32* nocapture %0, i32* nocapture %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%4 = getelementptr i32, i32* %0, i64 1
%5 = bitcast i32* %4 to i8*
br label %6
6: ; preds = %6, %2
%7 = phi i64 [ 0, %2 ], [ %28, %6 ]
%8 = getelementptr inbounds i32, i32* %1, i64 %7
%9 = load i32, i32* %8
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds i32, i32* %0, i64 %10
%12 = load i32, i32* %11
%13 = add i32 %12, 1
store i32 %13, i32* %11
%14 = add nuw nsw i64 %7, 1
%15 = getelementptr inbounds i32, i32* %1, i64 %14
%16 = load i32, i32* %15
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %0, i64 %17
%19 = load i32, i32* %18
%20 = add i32 %19, 1
store i32 %20, i32* %18
%21 = add nuw nsw i64 %7, 2
%22 = getelementptr inbounds i32, i32* %1, i64 %21
%23 = load i32, i32* %22
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %0, i64 %24
%26 = load i32, i32* %25
%27 = add i32 %26, 1
store i32 %27, i32* %25
%28 = add nuw nsw i64 %7, 3
%29 = icmp eq i64 %28, 99
br i1 %29, label %30, label %6
30: ; preds = %6
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
br label %32
32: ; preds = %30, %51
%33 = phi i32 [ 0, %30 ], [ %43, %51 ]
%34 = phi i32 [ 0, %30 ], [ %42, %51 ]
%35 = phi i64 [ 1, %30 ], [ %53, %51 ]
%36 = getelementptr inbounds i32, i32* %0, i64 %35
%37 = load i32, i32* %36
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i64 %35, i32 %37)
%39 = load i32, i32* %36
%40 = icmp ugt i32 %39, %34
%41 = trunc i64 %35 to i32
%42 = select i1 %40, i32 %39, i32 %34
%43 = select i1 %40, i32 %41, i32 %33
%44 = icmp eq i32 %39, 0
br i1 %44, label %51, label %45
45: ; preds = %32, %45
%46 = phi i32 [ %48, %45 ], [ 1, %32 ]
%47 = tail call i32 @putchar(i32 42)
%48 = add i32 %46, 1
%49 = load i32, i32* %36
%50 = icmp ugt i32 %48, %49
br i1 %50, label %51, label %45
51: ; preds = %45, %32
%52 = tail call i32 @putchar(i32 10)
%53 = add nuw nsw i64 %35, 1
%54 = icmp eq i64 %53, 10
br i1 %54, label %55, label %32
55: ; preds = %51
%56 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([92 x i8], [92 x i8]* @.str.13, i64 0, i64 0), i32 %43, i32 %42)
ret void
}