void debug_compile(int which, const char *s) {
  static int level = 0;
  static char indent[36] = ">>>>|>>>>|>>>>|>>>>|>>>>|>>>>|>>>>|";
  int i = ((1 + level) * 2) % 35;
  if (which >= 0)
    printf("%*.*s ", i, i, indent);
  if (s)
    printf("%s ", s);
  level += which;
}


x86 assembly (clang, -O0):
<debug_compile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2f33(%rip),%eax
add    $0x1,%eax
shl    $0x1,%eax
mov    $0x23,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     115b <debug_compile+0x4b>
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xeb3(%rip),%rdi
lea    0x2edc(%rip),%rcx
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     1178 <debug_compile+0x68>
mov    -0x10(%rbp),%rsi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    0x2ed7(%rip),%eax
mov    %eax,0x2ed1(%rip)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debug_compile>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
test   %edi,%edi
js     1163 <debug_compile+0x53>
mov    0x2f35(%rip),%eax
lea    (%rax,%rax,1),%ecx
add    $0x2,%ecx
movslq %ecx,%rdx
imul   $0xffffffffea0ea0eb,%rdx,%rcx
shr    $0x20,%rcx
lea    (%rcx,%rax,2),%eax
add    $0x2,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x5,%eax
add    %ecx,%eax
imul   $0x23,%eax,%eax
sub    %eax,%edx
lea    0xead(%rip),%rdi
lea    0x2ed6(%rip),%rcx
mov    %edx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
test   %r14,%r14
je     1179 <debug_compile+0x69>
lea    0xe98(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    %ebx,0x2ed9(%rip)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@debug_compile.level = internal global i32 0
@debug_compile.indent = internal global [36 x i8] c">>>>|>>>>|>>>>|>>>>|>>>>|>>>>|>>>>|\00"
@.str = [7 x i8] c"%*.*s \00"
@.str.1 = [4 x i8] c"%s \00"
define void @debug_compile(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i32, i32* @debug_compile.level
%7 = add nsw i32 1, %6
%8 = mul nsw i32 %7, 2
%9 = srem i32 %8, 35
store i32 %9, i32* %5
%10 = load i32, i32* %3
%11 = icmp sge i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* %5
%14 = load i32, i32* %5
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @debug_compile.indent, i64 0, i64 0))
br label %16
16: ; preds = %12, %2
%17 = load i8*, i8** %4
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i8*, i8** %4
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %19, %16
%23 = load i32, i32* %3
%24 = load i32, i32* @debug_compile.level
%25 = add nsw i32 %24, %23
store i32 %25, i32* @debug_compile.level
ret void
}

LLVM IR (-O2):
@debug_compile.level = internal unnamed_addr global i32 0
@debug_compile.indent = internal global [36 x i8] c">>>>|>>>>|>>>>|>>>>|>>>>|>>>>|>>>>|\00"
@.str = [7 x i8] c"%*.*s \00"
@.str.1 = [4 x i8] c"%s \00"
define void @debug_compile(i32 %0, i8* %1) {
%3 = icmp sgt i32 %0, -1
br i1 %3, label %4, label %10
4: ; preds = %2
%5 = load i32, i32* @debug_compile.level
%6 = shl i32 %5, 1
%7 = add i32 %6, 2
%8 = srem i32 %7, 35
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %8, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @debug_compile.indent, i64 0, i64 0))
br label %10
10: ; preds = %4, %2
%11 = icmp eq i8* %1, null
br i1 %11, label %14, label %12
12: ; preds = %10
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %14
14: ; preds = %12, %10
%15 = load i32, i32* @debug_compile.level
%16 = add nsw i32 %15, %0
store i32 %16, i32* @debug_compile.level
ret void
}