#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*/ calc_bars(int *, int, int *, int);
int /*<<< orphan*/ print_bar(int);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ putchar(char);
void print_graph(int values[], int size, int max_bar_size) {
  int bars[size];
  calc_bars(values, size, bars, max_bar_size);
  int i;
  for (i = 1; i < size; i++) {
    printf("%4d %4d ", i, values[i]);
    print_bar(bars[i]);
    putchar('\n');
  }
  printf(">%3d %4d ", size - 1, values[0]);
  print_bar(bars[0]);
  putchar('\n');
}


x86 assembly (clang, -O0):
<print_graph>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x30(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%ecx
call   1040 <calc_bars@plt>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11dd <print_graph+0x9d>
mov    -0x24(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe50(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1060 <print_bar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118f <print_graph+0x4f>
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
lea    0xe19(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%edi
call   1060 <print_bar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_graph>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ecx
mov    %esi,%ebx
mov    %rdi,%r15
mov    %esi,%r14d
mov    %rsp,%r12
lea    0xf(,%r14,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %r12,%rdx
call   1040 <calc_bars@plt>
mov    %ebx,-0x2c(%rbp)
cmp    $0x2,%ebx
jl     11ba <print_graph+0x7a>
mov    $0x1,%ebx
lea    0xe77(%rip),%r13
nopl   0x0(%rax)
mov    (%r15,%rbx,4),%edx
mov    %r13,%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
mov    (%r12,%rbx,4),%edi
call   1060 <print_bar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1190 <print_graph+0x50>
mov    -0x2c(%rbp),%esi
add    $0xffffffff,%esi
mov    (%r15),%edx
lea    0xe3f(%rip),%rdi
call   1050 <printf@plt>
mov    (%r12),%edi
call   1060 <print_bar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [9 x i8] c"%4d %4d \00"
@.str.1 = [10 x i8] c">%3d %4d \00"
define void @print_graph(i32* %0, i32 %1, i32 %2) {
%4 = zext i32 %1 to i64
%5 = alloca i32, i64 %4
%6 = call i32 @calc_bars(i32* %0, i32 %1, i32* %5, i32 %2)
%7 = icmp sgt i32 %1, 1
br i1 %7, label %8, label %20
8: ; preds = %3, %8
%9 = phi i64 [ %18, %8 ], [ 1, %3 ]
%10 = getelementptr inbounds i32, i32* %0, i64 %9
%11 = load i32, i32* %10
%12 = trunc i64 %9 to i32
%13 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %11)
%14 = getelementptr inbounds i32, i32* %5, i64 %9
%15 = load i32, i32* %14
%16 = call i32 @print_bar(i32 %15)
%17 = call i32 @putchar(i8 signext 10)
%18 = add nuw nsw i64 %9, 1
%19 = icmp eq i64 %18, %4
br i1 %19, label %20, label %8
20: ; preds = %8, %3
%21 = add nsw i32 %1, -1
%22 = load i32, i32* %0
%23 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %22)
%24 = load i32, i32* %5
%25 = call i32 @print_bar(i32 %24)
%26 = call i32 @putchar(i8 signext 10)
ret void
}