#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;
  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("%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)
lea    0xecb(%rip),%rdi
lea    0xecf(%rip),%rcx
lea    0xed1(%rip),%rdx
mov    %rcx,%rsi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x14(%rbp)
cmpl   $0x9,-0x14(%rbp)
jg     117b <mode+0x6b>
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    1154 <mode+0x44>
movl   $0x0,-0x18(%rbp)
cmpl   $0x63,-0x18(%rbp)
jge    11b3 <mode+0xa3>
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    1182 <mode+0x72>
lea    0xe61(%rip),%rdi
lea    0xe72(%rip),%rsi
lea    0xe74(%rip),%rdx
lea    0xe77(%rip),%rcx
lea    0xe7a(%rip),%r8
lea    0xe84(%rip),%r9
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x14(%rbp)
cmpl   $0x9,-0x14(%rbp)
jg     128c <mode+0x17c>
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe6d(%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    1239 <mode+0x129>
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     1270 <mode+0x160>
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1240 <mode+0x130>
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11eb <mode+0xdb>
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xdf0(%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    %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)
movslq -0x8(%rbp,%rax,4),%rcx
addl   $0x1,0x0(%r13,%rcx,4)
movslq -0x4(%rbp,%rax,4),%rcx
addl   $0x1,0x0(%r13,%rcx,4)
movslq 0x0(%rbp,%rax,4),%rcx
addl   $0x1,0x0(%r13,%rcx,4)
add    $0x3,%rax
cmp    $0x65,%rax
jne    1170 <mode+0x50>
lea    0xe79(%rip),%rdi
lea    0xe8a(%rip),%rsi
lea    0xe8c(%rip),%rdx
lea    0xe8f(%rip),%rcx
lea    0xe92(%rip),%r8
lea    0xe9c(%rip),%r9
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebp
lea    0xe9f(%rip),%r12
xor    %r14d,%r14d
xor    %r15d,%r15d
jmp    11f4 <mode+0xd4>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%rbp
cmp    $0xa,%rbp
je     1236 <mode+0x116>
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    11e0 <mode+0xc0>
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     1220 <mode+0x100>
jmp    11e0 <mode+0xc0>
lea    0xe4c(%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 = [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 = [17 x i8] c"1 1 2 2\00"
@.str.8 = [22 x i8] c"5 0 5 0 5\00"
@.str.9 = [18 x i8] c"%8d%11d \00"
@.str.10 = [2 x i8] c"*\00"
@.str.11 = [2 x i8] c"\0A\00"
@.str.12 = [91 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
%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 i32 1, i32* %5
br label %11
11: ; preds = %19, %2
%12 = load i32, i32* %5
%13 = icmp sle i32 %12, 9
br i1 %13, label %14, label %22
14: ; preds = %11
%15 = load i32*, i32** %3
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
store i32 0, i32* %18
br label %19
19: ; preds = %14
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
br label %11
22: ; preds = %11
store i32 0, i32* %6
br label %23
23: ; preds = %37, %22
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 99
br i1 %25, label %26, label %40
26: ; preds = %23
%27 = load i32*, i32** %3
%28 = load i32*, i32** %4
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %27, i64 %33
%35 = load i32, i32* %34
%36 = add nsw i32 %35, 1
store i32 %36, i32* %34
br label %37
37: ; preds = %26
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
br label %23
40: ; preds = %23
%41 = 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 ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %5
br label %42
42: ; preds = %83, %40
%43 = load i32, i32* %5
%44 = icmp sle i32 %43, 9
br i1 %44, label %45, label %86
45: ; preds = %42
%46 = load i32, i32* %5
%47 = load i32*, i32** %3
%48 = load i32, i32* %5
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %47, i64 %49
%51 = load i32, i32* %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), i32 %46, i32 %51)
%53 = load i32*, i32** %3
%54 = load i32, i32* %5
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %53, i64 %55
%57 = load i32, i32* %56
%58 = load i32, i32* %8
%59 = icmp sgt i32 %57, %58
br i1 %59, label %60, label %67
60: ; preds = %45
%61 = load i32*, i32** %3
%62 = load i32, i32* %5
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32, i32* %61, i64 %63
%65 = load i32, i32* %64
store i32 %65, i32* %8
%66 = load i32, i32* %5
store i32 %66, i32* %9
br label %67
67: ; preds = %60, %45
store i32 1, i32* %7
br label %68
68: ; preds = %78, %67
%69 = load i32, i32* %7
%70 = load i32*, i32** %3
%71 = load i32, i32* %5
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32, i32* %70, i64 %72
%74 = load i32, i32* %73
%75 = icmp sle i32 %69, %74
br i1 %75, label %76, label %81
76: ; preds = %68
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
br label %78
78: ; preds = %76
%79 = load i32, i32* %7
%80 = add nsw i32 %79, 1
store i32 %80, i32* %7
br label %68
81: ; preds = %68
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
br label %83
83: ; preds = %81
%84 = load i32, i32* %5
%85 = add nsw i32 %84, 1
store i32 %85, i32* %5
br label %42
86: ; preds = %42
%87 = load i32, i32* %9
%88 = load i32, i32* %8
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.12, i64 0, i64 0), i32 %87, i32 %88)
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 = [17 x i8] c"1 1 2 2\00"
@.str.8 = [22 x i8] c"5 0 5 0 5\00"
@.str.9 = [18 x i8] c"%8d%11d \00"
@.str.12 = [91 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 = 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 = sext i32 %9 to i64
%11 = getelementptr inbounds i32, i32* %0, i64 %10
%12 = load i32, i32* %11
%13 = add nsw 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 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %0, i64 %17
%19 = load i32, i32* %18
%20 = add nsw 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 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %0, i64 %24
%26 = load i32, i32* %25
%27 = add nsw 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 ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
br label %32
32: ; preds = %30, %51
%33 = phi i64 [ 1, %30 ], [ %53, %51 ]
%34 = phi i32 [ 0, %30 ], [ %43, %51 ]
%35 = phi i32 [ 0, %30 ], [ %42, %51 ]
%36 = getelementptr inbounds i32, i32* %0, i64 %33
%37 = load i32, i32* %36
%38 = trunc i64 %33 to i32
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), i32 %38, i32 %37)
%40 = load i32, i32* %36
%41 = icmp sgt i32 %40, %35
%42 = select i1 %41, i32 %40, i32 %35
%43 = select i1 %41, i32 %38, i32 %34
%44 = icmp slt i32 %40, 1
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 nuw nsw i32 %46, 1
%49 = load i32, i32* %36
%50 = icmp slt i32 %46, %49
br i1 %50, label %45, label %51
51: ; preds = %45, %32
%52 = tail call i32 @putchar(i32 10)
%53 = add nuw nsw i64 %33, 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 ([91 x i8], [91 x i8]* @.str.12, i64 0, i64 0), i32 %43, i32 %42)
ret void
}