#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 append_string(char *, char *);
int append_indent(char *buf, int level) {
  int i;
  int written = -1, written_total = 0;
  for (i = 0; i < level; i++) {
    do {
      written = append_string(buf, ("    "));
      if (written < 0) {
        return -1;
      }
      if (buf != NULL) {
        buf += written;
      }
      written_total += written;
    } while (0);
  }
  return written_total;
}


x86 assembly (clang, -O0):
<append_indent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a6 <append_indent+0x96>
jmp    1145 <append_indent+0x35>
mov    -0x10(%rbp),%rdi
lea    0xeb0(%rip),%rsi
call   1030 <append_string@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    116e <append_indent+0x5e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <append_indent+0x9c>
cmpq   $0x0,-0x10(%rbp)
je     118a <append_indent+0x7a>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1198 <append_indent+0x88>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1134 <append_indent+0x24>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_indent>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
jle    1155 <append_indent+0x45>
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %r14d,%r14d
lea    0xed6(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <append_string@plt>
test   %eax,%eax
js     115a <append_indent+0x4a>
mov    %eax,%ecx
add    %rbx,%rcx
test   %rbx,%rbx
cmovne %rcx,%rbx
add    %eax,%r14d
add    $0xffffffff,%ebp
jne    1130 <append_indent+0x20>
jmp    1160 <append_indent+0x50>
xor    %r14d,%r14d
jmp    1160 <append_indent+0x50>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c" \00"
define i32 @append_indent(i8* %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %18
4: ; preds = %2, %10
%5 = phi i32 [ %15, %10 ], [ 0, %2 ]
%6 = phi i32 [ %16, %10 ], [ 0, %2 ]
%7 = phi i8* [ %14, %10 ], [ %0, %2 ]
%8 = tail call i32 @append_string(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = icmp slt i32 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %4
%11 = icmp eq i8* %7, null
%12 = zext i32 %8 to i64
%13 = getelementptr inbounds i8, i8* %7, i64 %12
%14 = select i1 %11, i8* null, i8* %13
%15 = add nsw i32 %8, %5
%16 = add nuw nsw i32 %6, 1
%17 = icmp eq i32 %16, %1
br i1 %17, label %18, label %4
18: ; preds = %4, %10, %2
%19 = phi i32 [ 0, %2 ], [ %15, %10 ], [ -1, %4 ]
ret i32 %19
}