#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*/ printf(char *, 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, j;
  for (i = 1; i < max_bar_size; i++) {
    for (j = 0; j < size; j++) {
      int idx = j < size - 1 ? j + 1 : 0;
      printf("   %c", max_bar_size - bars[idx] <= i ? '#' : ' ');
    }
    putchar('\n');
  }
  for (j = 1; j < size; j++) {
    printf("%4d", j);
  }
  printf(" >%2d\n", size - 1);
}


x86 assembly (clang, -O0):
<print_graph>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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,-0x38(%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    -0x10(%rbp),%eax
jge    121f <print_graph+0xef>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1207 <print_graph+0xd7>
mov    -0x28(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11bd <print_graph+0x8d>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11c7 <print_graph+0x97>
xor    %eax,%eax
mov    %eax,-0x3c(%rbp)
jmp    11c7 <print_graph+0x97>
mov    -0x38(%rbp),%rax
mov    -0x3c(%rbp),%ecx
mov    %ecx,-0x2c(%rbp)
mov    -0x10(%rbp),%ecx
movslq -0x2c(%rbp),%rdx
sub    (%rax,%rdx,4),%ecx
mov    -0x24(%rbp),%edx
mov    $0x20,%esi
mov    $0x23,%eax
cmp    %edx,%ecx
cmovle %eax,%esi
lea    0xe0c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1192 <print_graph+0x62>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117f <print_graph+0x4f>
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    124f <print_graph+0x11f>
mov    -0x28(%rbp),%esi
lea    0xdca(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1226 <print_graph+0xf6>
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
lea    0xdae(%rip),%rdi
call   1050 <printf@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
sub    $0x18,%rsp
mov    %edx,%r14d
mov    %esi,%ebx
mov    %esi,%eax
mov    %rsp,%rdx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rdx
mov    %rdx,%rsp
mov    %rdx,-0x38(%rbp)
mov    %r14d,%ecx
call   1040 <calc_bars@plt>
cmp    $0x2,%r14d
jl     11fe <print_graph+0xce>
lea    -0x1(%rbx),%eax
mov    %eax,-0x30(%rbp)
mov    $0x1,%r15d
mov    %r14d,-0x2c(%rbp)
jmp    11a7 <print_graph+0x77>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r15d
mov    -0x2c(%rbp),%r14d
cmp    %r14d,%r15d
je     11fe <print_graph+0xce>
test   %ebx,%ebx
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%ecx
lea    0xe49(%rip),%r12
jle    1190 <print_graph+0x60>
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
lea    0x1(%rax),%r14d
cmp    %ecx,%eax
mov    $0x0,%eax
cmovl  %r14d,%eax
mov    -0x2c(%rbp),%ecx
sub    (%rdx,%rax,4),%ecx
xor    %eax,%eax
cmp    %r15d,%ecx
setle  %al
lea    (%rax,%rax,2),%esi
or     $0x20,%esi
mov    %r12,%rdi
mov    %rdx,%r13
call   1050 <printf@plt>
mov    -0x30(%rbp),%ecx
mov    %r13,%rdx
mov    %r14d,%eax
cmp    %r14d,%ebx
jne    11c0 <print_graph+0x90>
jmp    1190 <print_graph+0x60>
cmp    $0x2,%ebx
jl     1224 <print_graph+0xf4>
mov    $0x1,%r14d
lea    0xdf6(%rip),%r15
mov    %r15,%rdi
mov    %r14d,%esi
call   1050 <printf@plt>
add    $0x1,%r14d
cmp    %r14d,%ebx
jne    1210 <print_graph+0xe0>
add    $0xffffffff,%ebx
lea    0xddc(%rip),%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c" %c\00"
@.str.1 = [4 x i8] c"%4d\00"
@.str.2 = [7 x i8] c" >%2d\0A\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
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%12 = load i32, i32* %5
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %7
%15 = alloca i32, i64 %13
store i64 %13, i64* %8
%16 = load i32*, i32** %4
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = call i32 @calc_bars(i32* %16, i32 %17, i32* %15, i32 %18)
store i32 1, i32* %9
br label %20
20: ; preds = %56, %3
%21 = load i32, i32* %9
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %59
24: ; preds = %20
store i32 0, i32* %10
br label %25
25: ; preds = %51, %24
%26 = load i32, i32* %10
%27 = load i32, i32* %5
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %54
29: ; preds = %25
%30 = load i32, i32* %10
%31 = load i32, i32* %5
%32 = sub nsw i32 %31, 1
%33 = icmp slt i32 %30, %32
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load i32, i32* %10
%36 = add nsw i32 %35, 1
br label %38
37: ; preds = %29
br label %38
38: ; preds = %37, %34
%39 = phi i32 [ %36, %34 ], [ 0, %37 ]
store i32 %39, i32* %11
%40 = load i32, i32* %6
%41 = load i32, i32* %11
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %15, i64 %42
%44 = load i32, i32* %43
%45 = sub nsw i32 %40, %44
%46 = load i32, i32* %9
%47 = icmp sle i32 %45, %46
%48 = zext i1 %47 to i64
%49 = select i1 %47, i32 35, i32 32
%50 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %38
%52 = load i32, i32* %10
%53 = add nsw i32 %52, 1
store i32 %53, i32* %10
br label %25
54: ; preds = %25
%55 = call i32 @putchar(i8 signext 10)
br label %56
56: ; preds = %54
%57 = load i32, i32* %9
%58 = add nsw i32 %57, 1
store i32 %58, i32* %9
br label %20
59: ; preds = %20
store i32 1, i32* %10
br label %60
60: ; preds = %67, %59
%61 = load i32, i32* %10
%62 = load i32, i32* %5
%63 = icmp slt i32 %61, %62
br i1 %63, label %64, label %70
64: ; preds = %60
%65 = load i32, i32* %10
%66 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %64
%68 = load i32, i32* %10
%69 = add nsw i32 %68, 1
store i32 %69, i32* %10
br label %60
70: ; preds = %60
%71 = load i32, i32* %5
%72 = sub nsw i32 %71, 1
%73 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %72)
%74 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c" %c\00"
@.str.1 = [4 x i8] c"%4d\00"
@.str.2 = [7 x i8] c" >%2d\0A\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 %2, 1
br i1 %7, label %8, label %13
8: ; preds = %3
%9 = icmp sgt i32 %1, 0
%10 = add nsw i32 %1, -1
br label %11
11: ; preds = %8, %28
%12 = phi i32 [ 1, %8 ], [ %30, %28 ]
br i1 %9, label %15, label %28
13: ; preds = %28, %3
%14 = icmp sgt i32 %1, 1
br i1 %14, label %32, label %37
15: ; preds = %11, %15
%16 = phi i32 [ %18, %15 ], [ 0, %11 ]
%17 = icmp slt i32 %16, %10
%18 = add nuw nsw i32 %16, 1
%19 = select i1 %17, i32 %18, i32 0
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %5, i64 %20
%22 = load i32, i32* %21
%23 = sub nsw i32 %2, %22
%24 = icmp sgt i32 %23, %12
%25 = select i1 %24, i32 32, i32 35
%26 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = icmp eq i32 %18, %1
br i1 %27, label %28, label %15
28: ; preds = %15, %11
%29 = call i32 @putchar(i8 signext 10)
%30 = add nuw nsw i32 %12, 1
%31 = icmp eq i32 %30, %2
br i1 %31, label %13, label %11
32: ; preds = %13, %32
%33 = phi i32 [ %35, %32 ], [ 1, %13 ]
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = add nuw nsw i32 %33, 1
%36 = icmp eq i32 %35, %1
br i1 %36, label %37, label %32
37: ; preds = %32, %13
%38 = add nsw i32 %1, -1
%39 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %38)
ret void
}