#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 *, ...);
draw_histogram(int *a[]) {
  int i, l = sizeof(*a) / sizeof(*a[0]);
  printf("%d", l);
  for (i = 1; i < l; i++) {
    if (*a[i] != 0) {
      printf("%d\t", i);
      while (*a[i] > 0) {
        printf("X");
        a[i]--;
      }
      printf("\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<draw_histogram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x2,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11ca <draw_histogram+0xba>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
cmpl   $0x0,(%rax)
je     11b7 <draw_histogram+0xa7>
mov    -0xc(%rbp),%esi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
cmpl   $0x0,(%rax)
jle    11a9 <draw_histogram+0x99>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
add    $0xfffffffffffffffc,%rdx
mov    %rdx,(%rax,%rcx,8)
jmp    116d <draw_histogram+0x5d>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bc <draw_histogram+0xac>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113b <draw_histogram+0x2b>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw_histogram>:
push   %rbx
mov    %rdi,%rbx
lea    0xed5(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%rax
cmpl   $0x0,(%rax)
je     1186 <draw_histogram+0x66>
lea    0xebc(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%rax
cmpl   $0x0,(%rax)
jle    117c <draw_histogram+0x5c>
nopl   0x0(%rax)
mov    $0x58,%edi
call   1030 <putchar@plt>
mov    0x8(%rbx),%rax
lea    -0x4(%rax),%rcx
mov    %rcx,0x8(%rbx)
cmpl   $0x0,-0x4(%rax)
jg     1160 <draw_histogram+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\09\00"
define i32 @draw_histogram(i32** nocapture %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%3 = getelementptr inbounds i32*, i32** %0, i64 1
%4 = load i32*, i32** %3
%5 = load i32, i32* %4
%6 = icmp eq i32 %5, 0
br i1 %6, label %20, label %7
7: ; preds = %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 1)
%9 = load i32*, i32** %3
%10 = load i32, i32* %9
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %7, %12
%13 = tail call i32 @putchar(i32 88)
%14 = load i32*, i32** %3
%15 = getelementptr inbounds i32, i32* %14, i64 -1
store i32* %15, i32** %3
%16 = load i32, i32* %15
%17 = icmp sgt i32 %16, 0
br i1 %17, label %12, label %18
18: ; preds = %12, %7
%19 = tail call i32 @putchar(i32 10)
br label %20
20: ; preds = %1, %18
ret i32 0
}