#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 *, ...);
void mode(int freq[], const int answer[]) {
  int rating;
  int j;
  int h;
  int largest = 0;
  int modeValue = 0;
  for (rating = 1; rating <= 9; rating++) {
    freq[rating] = 0;
  }
  for (j = 0; j < 99; j++) {
    ++freq[answer[j]];
  }
  printf("%s%11s%10s\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("%8d%11d               ", rating, freq[rating]);
    if (freq[rating] > largest) {
      largest = freq[rating];
      modeValue = rating;
    }
    for (h = 1; h <= freq[rating]; h++) {
      printf("*");
    }
    printf("\n");
  }
  printf("The mode is the most frequent value.\n"
         "For this run, the mode is: %d which occurred"
         " %d 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,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x9,-0x14(%rbp)
jg     115c <mode+0x4c>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1135 <mode+0x25>
movl   $0x0,-0x18(%rbp)
cmpl   $0x63,-0x18(%rbp)
jge    1194 <mode+0x84>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x18(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1163 <mode+0x53>
lea    0xe65(%rip),%rdi
lea    0xe76(%rip),%rsi
lea    0xe78(%rip),%rdx
lea    0xe7b(%rip),%rcx
lea    0xe7e(%rip),%r8
lea    0xe8b(%rip),%r9
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x14(%rbp)
cmpl   $0x9,-0x14(%rbp)
jg     126d <mode+0x15d>
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x20(%rbp),%eax
jle    121a <mode+0x10a>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jg     1251 <mode+0x141>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1221 <mode+0x111>
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11cc <mode+0xbc>
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1030 <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    %rdi,%r13
xorps  %xmm0,%xmm0
movups %xmm0,0x14(%rdi)
movups %xmm0,0x4(%rdi)
movl   $0x0,0x24(%rdi)
mov    $0x2,%eax
cs nopw 0x0(%rax,%rax,1)
nop
movslq -0x8(%rsi,%rax,4),%rcx
addl   $0x1,0x0(%r13,%rcx,4)
movslq -0x4(%rsi,%rax,4),%rcx
addl   $0x1,0x0(%r13,%rcx,4)
movslq (%rsi,%rax,4),%rcx
addl   $0x1,0x0(%r13,%rcx,4)
add    $0x3,%rax
cmp    $0x65,%rax
jne    1150 <mode+0x30>
lea    0xe7f(%rip),%rdi
lea    0xe90(%rip),%rsi
lea    0xe92(%rip),%rdx
lea    0xe95(%rip),%rcx
lea    0xe98(%rip),%r8
lea    0xea5(%rip),%r9
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebp
lea    0xeb4(%rip),%r12
xor    %r14d,%r14d
xor    %r15d,%r15d
jmp    11d4 <mode+0xb4>
nop
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%rbp
cmp    $0xa,%rbp
je     1216 <mode+0xf6>
mov    0x0(%r13,%rbp,4),%edx
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13,%rbp,4),%eax
cmp    %r15d,%eax
cmovg  %eax,%r15d
cmovg  %ebp,%r14d
test   %eax,%eax
jle    11c0 <mode+0xa0>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    $0x2a,%edi
call   1030 <putchar@plt>
add    $0x1,%ebx
cmp    0x0(%r13,%rbp,4),%ebx
jl     1200 <mode+0xe0>
jmp    11c0 <mode+0xa0>
lea    0xe65(%rip),%rdi
mov    %r14d,%esi
mov    %r15d,%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 = [24 x i8] c"%s%11s%10s\0A\0A%54s\0A%54s\0A\0A\00"
@.str.1 = [9 x i8] c"Response\00"
@.str.2 = [10 x i8] c"Frequency\00"
@.str.3 = [10 x i8] c"Histogram\00"
@.str.4 = [20 x i8] c"1 1 2 2\00"
@.str.5 = [34 x i8] c" 5 0 5 0 5\00"
@.str.6 = [23 x i8] c"%8d%11d \00"
@.str.7 = [2 x i8] c"*\00"
@.str.8 = [2 x i8] c"\0A\00"
@.str.9 = [93 x i8] c"The mode is the most frequent value.\0AFor this run, the mode is: %d which occurred %d times.\0A\00"
define void @mode(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%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
store i32 1, i32* %5
br label %10
10: ; preds = %18, %2
%11 = load i32, i32* %5
%12 = icmp sle i32 %11, 9
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = load i32*, i32** %3
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %14, i64 %16
store i32 0, i32* %17
br label %18
18: ; preds = %13
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
store i32 %20, i32* %5
br label %10
21: ; preds = %10
store i32 0, i32* %6
br label %22
22: ; preds = %36, %21
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 99
br i1 %24, label %25, label %39
25: ; preds = %22
%26 = load i32*, i32** %3
%27 = load i32*, i32** %4
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %26, i64 %32
%34 = load i32, i32* %33
%35 = add nsw i32 %34, 1
store i32 %35, i32* %33
br label %36
36: ; preds = %25
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %22
39: ; preds = %22
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 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 ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %5
br label %41
41: ; preds = %82, %39
%42 = load i32, i32* %5
%43 = icmp sle i32 %42, 9
br i1 %43, label %44, label %85
44: ; preds = %41
%45 = load i32, i32* %5
%46 = load i32*, i32** %3
%47 = load i32, i32* %5
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %46, i64 %48
%50 = load i32, i32* %49
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 %45, i32 %50)
%52 = load i32*, i32** %3
%53 = load i32, i32* %5
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %52, i64 %54
%56 = load i32, i32* %55
%57 = load i32, i32* %8
%58 = icmp sgt i32 %56, %57
br i1 %58, label %59, label %66
59: ; preds = %44
%60 = load i32*, i32** %3
%61 = load i32, i32* %5
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %60, i64 %62
%64 = load i32, i32* %63
store i32 %64, i32* %8
%65 = load i32, i32* %5
store i32 %65, i32* %9
br label %66
66: ; preds = %59, %44
store i32 1, i32* %7
br label %67
67: ; preds = %77, %66
%68 = load i32, i32* %7
%69 = load i32*, i32** %3
%70 = load i32, i32* %5
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i32, i32* %69, i64 %71
%73 = load i32, i32* %72
%74 = icmp sle i32 %68, %73
br i1 %74, label %75, label %80
75: ; preds = %67
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %77
77: ; preds = %75
%78 = load i32, i32* %7
%79 = add nsw i32 %78, 1
store i32 %79, i32* %7
br label %67
80: ; preds = %67
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %82
82: ; preds = %80
%83 = load i32, i32* %5
%84 = add nsw i32 %83, 1
store i32 %84, i32* %5
br label %41
85: ; preds = %41
%86 = load i32, i32* %9
%87 = load i32, i32* %8
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.9, i64 0, i64 0), i32 %86, i32 %87)
ret void
}

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