#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 */
typedef int /*<<< orphan*/ stringX;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int, char *);
int /*<<< orphan*/ strcat(char *, char *);
void draw_histogram(int freq[], int tab[]) {
  char stringX[100];
  for (int i = 0; i < 100; i++) {
    if (freq[i] != 0) {
      int count = freq[i];
      memset(stringX, 0, sizeof(stringX));
      for (int i = 0; i < count; i++) {
        strcat(stringX, "X");
      }
      printf("%d is %s times.\n", tab[i], stringX);
    }
  }
}


x86 assembly (clang, -O0):
<draw_histogram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x84(%rbp)
cmpl   $0x64,-0x84(%rbp)
jge    120a <draw_histogram+0xda>
mov    -0x8(%rbp),%rax
movslq -0x84(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     11f1 <draw_histogram+0xc1>
mov    -0x8(%rbp),%rax
movslq -0x84(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x88(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
movl   $0x0,-0x8c(%rbp)
mov    -0x8c(%rbp),%eax
cmp    -0x88(%rbp),%eax
jge    11d3 <draw_histogram+0xa3>
lea    -0x80(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
jmp    119d <draw_histogram+0x6d>
mov    -0x10(%rbp),%rax
movslq -0x84(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    -0x80(%rbp),%rdx
lea    0xe16(%rip),%rdi
call   1030 <printf@plt>
jmp    11f6 <draw_histogram+0xc6>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    114d <draw_histogram+0x1d>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw_histogram>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebp,%ebp
mov    %rsp,%rbx
lea    0xeb0(%rip),%r12
jmp    117d <draw_histogram+0x4d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14,%rbp,4),%esi
lea    0xe97(%rip),%rdi
mov    %rbx,%rdx
call   1030 <printf@plt>
add    $0x1,%rbp
cmp    $0x64,%rbp
je     11b3 <draw_histogram+0x83>
mov    (%r15,%rbp,4),%r13d
test   %r13d,%r13d
je     1173 <draw_histogram+0x43>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
test   %r13d,%r13d
jle    1160 <draw_histogram+0x30>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <strcat@plt>
add    $0xffffffff,%r13d
jne    11a0 <draw_histogram+0x70>
jmp    1160 <draw_histogram+0x30>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"X\00"
@.str.1 = [17 x i8] c"%d is %s times.\0A\00"
define void @draw_histogram(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
br label %6
5: ; preds = %23
ret void
6: ; preds = %2, %23
%7 = phi i64 [ 0, %2 ], [ %24, %23 ]
%8 = getelementptr inbounds i32, i32* %0, i64 %7
%9 = load i32, i32* %8
%10 = icmp eq i32 %9, 0
br i1 %10, label %23, label %11
11: ; preds = %6
%12 = call i32 @memset(i8* %4, i32 0, i32 100)
%13 = icmp sgt i32 %9, 0
br i1 %13, label %18, label %14
14: ; preds = %18, %11
%15 = getelementptr inbounds i32, i32* %1, i64 %7
%16 = load i32, i32* %15
%17 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %16, i8* %4)
br label %23
18: ; preds = %11, %18
%19 = phi i32 [ %21, %18 ], [ 0, %11 ]
%20 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = add nuw nsw i32 %19, 1
%22 = icmp eq i32 %21, %9
br i1 %22, label %14, label %18
23: ; preds = %6, %14
%24 = add nuw nsw i64 %7, 1
%25 = icmp eq i64 %24, 100
br i1 %25, label %5, label %6
}