#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 *, char);
char mostFrequentChar(char *in) {
  int occurences[255];
  for (int i = 0; i < 255; i++)
    occurences[i] = 0;
  char mostfrequent = 0;
  int i = 0;
  while (in[i] != '\0') {
    printf("%c", in[i]);
    occurences[in[i]] += 1;
    if (occurences[in[i]] > occurences[mostfrequent])
      mostfrequent = in[i];
    i++;
  }
  return mostfrequent;
}


x86 assembly (clang, -O0):
<mostFrequentChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x414(%rbp)
cmpl   $0xff,-0x414(%rbp)
jge    115f <mostFrequentChar+0x4f>
movslq -0x414(%rbp),%rax
movl   $0x0,-0x410(%rbp,%rax,4)
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    1129 <mostFrequentChar+0x19>
movb   $0x0,-0x415(%rbp)
movl   $0x0,-0x41c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x41c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1218 <mostFrequentChar+0x108>
mov    -0x8(%rbp),%rax
movslq -0x41c(%rbp),%rcx
lea    0xe66(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x41c(%rbp),%rcx
movsbq (%rax,%rcx,1),%rax
mov    -0x410(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x410(%rbp,%rax,4)
mov    -0x8(%rbp),%rax
movslq -0x41c(%rbp),%rcx
movsbq (%rax,%rcx,1),%rax
mov    -0x410(%rbp,%rax,4),%eax
movsbq -0x415(%rbp),%rcx
ff
cmp    -0x410(%rbp,%rcx,4),%eax
jle    1204 <mostFrequentChar+0xf4>
mov    -0x8(%rbp),%rax
movslq -0x41c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x415(%rbp)
mov    -0x41c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x41c(%rbp)
jmp    1170 <mostFrequentChar+0x60>
movsbl -0x415(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mostFrequentChar>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
xor    %ebp,%ebp
mov    $0x3fc,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    (%rbx),%al
test   %al,%al
je     1195 <mostFrequentChar+0x75>
add    $0x1,%rbx
xor    %ebp,%ebp
lea    0xeae(%rip),%r14
jmp    116d <mostFrequentChar+0x4d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,%ebp
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1195 <mostFrequentChar+0x75>
movsbl %al,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movsbq -0x1(%rbx),%rax
mov    (%rsp,%rax,4),%ecx
lea    0x1(%rcx),%edx
mov    %edx,(%rsp,%rax,4)
movsbq %bpl,%rdx
cmp    (%rsp,%rdx,4),%ecx
jge    1160 <mostFrequentChar+0x40>
movzbl %bpl,%ebp
jmp    1162 <mostFrequentChar+0x42>
mov    %ebp,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
define signext i8 @mostFrequentChar(i8* %0) {
%2 = alloca i8*
%3 = alloca [255 x i32]
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
br label %7
7: ; preds = %14, %1
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 255
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [255 x i32], [255 x i32]* %3, i64 0, i64 %12
store i32 0, i32* %13
br label %14
14: ; preds = %10
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
br label %7
17: ; preds = %7
store i8 0, i8* %5
store i32 0, i32* %6
br label %18
18: ; preds = %61, %17
%19 = load i8*, i8** %2
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %64
26: ; preds = %18
%27 = load i8*, i8** %2
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %31)
%33 = load i8*, i8** %2
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i64
%39 = getelementptr inbounds [255 x i32], [255 x i32]* %3, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = add nsw i32 %40, 1
store i32 %41, i32* %39
%42 = load i8*, i8** %2
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i64
%48 = getelementptr inbounds [255 x i32], [255 x i32]* %3, i64 0, i64 %47
%49 = load i32, i32* %48
%50 = load i8, i8* %5
%51 = sext i8 %50 to i64
%52 = getelementptr inbounds [255 x i32], [255 x i32]* %3, i64 0, i64 %51
%53 = load i32, i32* %52
%54 = icmp sgt i32 %49, %53
br i1 %54, label %55, label %61
55: ; preds = %26
%56 = load i8*, i8** %2
%57 = load i32, i32* %6
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = load i8, i8* %59
store i8 %60, i8* %5
br label %61
61: ; preds = %55, %26
%62 = load i32, i32* %6
%63 = add nsw i32 %62, 1
store i32 %63, i32* %6
br label %18
64: ; preds = %18
%65 = load i8, i8* %5
ret i8 %65
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
define signext i8 @mostFrequentChar(i8* nocapture %0) {
%2 = alloca [255 x i32]
%3 = bitcast [255 x i32]* %2 to i8*
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %26, label %6
6: ; preds = %1, %6
%7 = phi i64 [ %22, %6 ], [ 0, %1 ]
%8 = phi i8 [ %24, %6 ], [ %4, %1 ]
%9 = phi i8* [ %23, %6 ], [ %0, %1 ]
%10 = phi i8 [ %21, %6 ], [ 0, %1 ]
%11 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %8)
%12 = load i8, i8* %9
%13 = sext i8 %12 to i64
%14 = getelementptr inbounds [255 x i32], [255 x i32]* %2, i64 0, i64 %13
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 1
store i32 %16, i32* %14
%17 = sext i8 %10 to i64
%18 = getelementptr inbounds [255 x i32], [255 x i32]* %2, i64 0, i64 %17
%19 = load i32, i32* %18
%20 = icmp slt i32 %15, %19
%21 = select i1 %20, i8 %10, i8 %12
%22 = add nuw i64 %7, 1
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %26, label %6
26: ; preds = %6, %1
%27 = phi i8 [ 0, %1 ], [ %21, %6 ]
ret i8 %27
}