#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strtok(char *, char *);
int main() {
  char input[30];
  int i = 0, counter[128] = {0};
  printf("Please enter a string.\n");
  fgets(input, 30, stdin);
  strtok(input, "\n");
  for (i = 0; input[i] != '\0'; i++) {
    counter[(int)input[i]]++;
  }
  for (i = 0; i < 128; i++) {
    if (counter[i] != 0)
      printf("%c is present %d times.\n", i, counter[i]);
    else
      continue;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x34(%rbp)
lea    -0x240(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1040 <memset@plt>
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
mov    $0x1e,%esi
call   1050 <fgets@plt>
lea    -0x30(%rbp),%rdi
lea    0xe7a(%rip),%rsi
call   1060 <strtok@plt>
movl   $0x0,-0x34(%rbp)
movslq -0x34(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     11e4 <main+0xa4>
movslq -0x34(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%eax
cltq
mov    -0x240(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x240(%rbp,%rax,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11a8 <main+0x68>
movl   $0x0,-0x34(%rbp)
cmpl   $0x80,-0x34(%rbp)
jge    1243 <main+0x103>
movslq -0x34(%rbp),%rax
cmpl   $0x0,-0x240(%rbp,%rax,4)
je     122b <main+0xeb>
mov    -0x34(%rbp),%esi
movslq -0x34(%rbp),%rax
mov    -0x240(%rbp,%rax,4),%edx
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1230 <main+0xf0>
jmp    1235 <main+0xf5>
jmp    1235 <main+0xf5>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11eb <main+0xab>
xor    %eax,%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x228,%rsp
lea    0x20(%rsp),%rdi
mov    $0x200,%edx
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xea7(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1e,%esi
call   1060 <fgets@plt>
lea    0xe80(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strtok@plt>
mov    (%rsp),%al
test   %al,%al
je     11c4 <main+0x74>
lea    0x1(%rsp),%rcx
nopl   0x0(%rax,%rax,1)
movsbq %al,%rax
addl   $0x1,0x20(%rsp,%rax,4)
movzbl (%rcx),%eax
add    $0x1,%rcx
test   %al,%al
jne    11b0 <main+0x60>
lea    0xe35(%rip),%r14
xor    %ebx,%ebx
jmp    11dd <main+0x8d>
nop
add    $0x1,%rbx
cmp    $0x80,%rbx
je     11f3 <main+0xa3>
mov    0x20(%rsp,%rbx,4),%edx
test   %edx,%edx
je     11d0 <main+0x80>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11d0 <main+0x80>
xor    %eax,%eax
add    $0x228,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Please enter a string.\0A\00"
@stdin = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [25 x i8] c"%c is present %d times.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [30 x i8]
%3 = alloca i32
%4 = alloca [128 x i32]
store i32 0, i32* %1
store i32 0, i32* %3
%5 = bitcast [128 x i32]* %4 to i8*
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %7, i32 30, i32 %8)
%10 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%11 = call i32 @strtok(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %12
12: ; preds = %29, %0
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %32
19: ; preds = %12
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [128 x i32], [128 x i32]* %4, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1
store i32 %28, i32* %26
br label %29
29: ; preds = %19
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
store i32 %31, i32* %3
br label %12
32: ; preds = %12
store i32 0, i32* %3
br label %33
33: ; preds = %51, %32
%34 = load i32, i32* %3
%35 = icmp slt i32 %34, 128
br i1 %35, label %36, label %54
36: ; preds = %33
%37 = load i32, i32* %3
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [128 x i32], [128 x i32]* %4, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %49
42: ; preds = %36
%43 = load i32, i32* %3
%44 = load i32, i32* %3
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [128 x i32], [128 x i32]* %4, i64 0, i64 %45
%47 = load i32, i32* %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %43, i32 %47)
br label %50
49: ; preds = %36
br label %51
50: ; preds = %42
br label %51
51: ; preds = %50, %49
%52 = load i32, i32* %3
%53 = add nsw i32 %52, 1
store i32 %53, i32* %3
br label %33
54: ; preds = %33
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [25 x i8] c"%c is present %d times.\0A\00"
@str = [23 x i8] c"Please enter a string.\00"
define i32 @main() {
%1 = alloca [30 x i8]
%2 = alloca [128 x i32]
%3 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%4 = bitcast [128 x i32]* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %3, i32 30, i32 %6)
%8 = call i32 @strtok(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = load i8, i8* %3
%10 = icmp eq i8 %9, 0
br i1 %10, label %22, label %11
11: ; preds = %0, %11
%12 = phi i64 [ %18, %11 ], [ 0, %0 ]
%13 = phi i8 [ %20, %11 ], [ %9, %0 ]
%14 = sext i8 %13 to i64
%15 = getelementptr inbounds [128 x i32], [128 x i32]* %2, i64 0, i64 %14
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1
store i32 %17, i32* %15
%18 = add nuw nsw i64 %12, 1
%19 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %11
22: ; preds = %11, %0
br label %23
23: ; preds = %22, %31
%24 = phi i64 [ %32, %31 ], [ 0, %22 ]
%25 = getelementptr inbounds [128 x i32], [128 x i32]* %2, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %23
%29 = trunc i64 %24 to i32
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %29, i32 %26)
br label %31
31: ; preds = %23, %28
%32 = add nuw nsw i64 %24, 1
%33 = icmp eq i64 %32, 128
br i1 %33, label %34, label %23
34: ; preds = %31
ret i32 0
}