#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 */
struct strbuf {
  int dummy;
};

/* Variables and functions */
char *gitstrchrnul(char const *, char);
int /*<<< orphan*/ print_spaces(struct strbuf *, int);
int /*<<< orphan*/ strbuf_write(struct strbuf *, char const *, int);
void strbuf_add_indented_text(struct strbuf *buf, const char *text, int indent,
                              int indent2) {
  if (indent < 0)
    indent = 0;
  while (*text) {
    const char *eol = gitstrchrnul(text, '\n');
    if (*eol == '\n')
      eol++;
    print_spaces(buf, indent);
    strbuf_write(buf, text, eol - text);
    text = eol;
    indent = indent2;
  }
}


x86 assembly (clang, -O0):
<strbuf_add_indented_text>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1157 <strbuf_add_indented_text+0x27>
movl   $0x0,-0x14(%rbp)
jmp    115c <strbuf_add_indented_text+0x2c>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d0 <strbuf_add_indented_text+0xa0>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1050 <gitstrchrnul@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1197 <strbuf_add_indented_text+0x67>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <print_spaces@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1040 <strbuf_write@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    115c <strbuf_add_indented_text+0x2c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strbuf_add_indented_text>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmpb   $0x0,(%rsi)
je     11e2 <strbuf_add_indented_text+0xb2>
mov    %ecx,%r14d
mov    %rsi,%r15
mov    %rdi,%r13
xor    %ebp,%ebp
test   %edx,%edx
cmovns %edx,%ebp
mov    %rsi,%rdi
mov    $0xa,%esi
call   1050 <gitstrchrnul@plt>
mov    %rax,(%rsp)
xor    %ebx,%ebx
cmpb   $0xa,(%rax)
sete   %bl
lea    (%rax,%rbx,1),%r12
mov    %r13,%rdi
mov    %ebp,%esi
call   1030 <print_spaces@plt>
mov    %r12d,%edx
sub    %r15d,%edx
mov    %r13,%rdi
mov    %r15,%rsi
call   1040 <strbuf_write@plt>
mov    (%rsp),%rax
cmpb   $0x0,(%rax,%rbx,1)
je     11e2 <strbuf_add_indented_text+0xb2>
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0xa,%esi
call   1050 <gitstrchrnul@plt>
mov    %rax,%rbx
xor    %ebp,%ebp
cmpb   $0xa,(%rax)
sete   %bpl
lea    (%rax,%rbp,1),%r15
mov    %r13,%rdi
mov    %r14d,%esi
call   1030 <print_spaces@plt>
mov    %r15d,%edx
sub    %r12d,%edx
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <strbuf_write@plt>
cmpb   $0x0,(%rbx,%rbp,1)
mov    %r15,%r12
jne    11a0 <strbuf_add_indented_text+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.strbuf = type { i32 }
define void @strbuf_add_indented_text(%struct.strbuf* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca %struct.strbuf*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store %struct.strbuf* %0, %struct.strbuf** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %4
store i32 0, i32* %7
br label %13
13: ; preds = %12, %4
br label %14
14: ; preds = %28, %13
%15 = load i8*, i8** %6
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
br i1 %17, label %18, label %43
18: ; preds = %14
%19 = load i8*, i8** %6
%20 = call i8* @gitstrchrnul(i8* %19, i8 signext 10)
store i8* %20, i8** %9
%21 = load i8*, i8** %9
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 10
br i1 %24, label %25, label %28
25: ; preds = %18
%26 = load i8*, i8** %9
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %9
br label %28
28: ; preds = %25, %18
%29 = load %struct.strbuf*, %struct.strbuf** %5
%30 = load i32, i32* %7
%31 = call i32 @print_spaces(%struct.strbuf* %29, i32 %30)
%32 = load %struct.strbuf*, %struct.strbuf** %5
%33 = load i8*, i8** %6
%34 = load i8*, i8** %9
%35 = load i8*, i8** %6
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = trunc i64 %38 to i32
%40 = call i32 @strbuf_write(%struct.strbuf* %32, i8* %33, i32 %39)
%41 = load i8*, i8** %9
store i8* %41, i8** %6
%42 = load i32, i32* %8
store i32 %42, i32* %7
br label %14
43: ; preds = %14
ret void
}

LLVM IR (-O2):
%struct.strbuf = type { i32 }
define void @strbuf_add_indented_text(%struct.strbuf* %0, i8* %1, i32 %2, i32 %3) {
%5 = load i8, i8* %1
%6 = icmp eq i8 %5, 0
br i1 %6, label %38, label %7
7: ; preds = %4
%8 = icmp sgt i32 %2, 0
%9 = select i1 %8, i32 %2, i32 0
%10 = tail call i8* @gitstrchrnul(i8* %1, i8 signext 10)
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 10
%13 = zext i1 %12 to i64
%14 = getelementptr i8, i8* %10, i64 %13
%15 = tail call i32 @print_spaces(%struct.strbuf* %0, i32 %9)
%16 = ptrtoint i8* %14 to i64
%17 = ptrtoint i8* %1 to i64
%18 = sub i64 %16, %17
%19 = trunc i64 %18 to i32
%20 = tail call i32 @strbuf_write(%struct.strbuf* %0, i8* %1, i32 %19)
%21 = load i8, i8* %14
%22 = icmp eq i8 %21, 0
br i1 %22, label %38, label %23
23: ; preds = %7, %23
%24 = phi i8* [ %29, %23 ], [ %14, %7 ]
%25 = tail call i8* @gitstrchrnul(i8* %24, i8 signext 10)
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 10
%28 = zext i1 %27 to i64
%29 = getelementptr i8, i8* %25, i64 %28
%30 = tail call i32 @print_spaces(%struct.strbuf* %0, i32 %3)
%31 = ptrtoint i8* %29 to i64
%32 = ptrtoint i8* %24 to i64
%33 = sub i64 %31, %32
%34 = trunc i64 %33 to i32
%35 = tail call i32 @strbuf_write(%struct.strbuf* %0, i8* %24, i32 %34)
%36 = load i8, i8* %29
%37 = icmp eq i8 %36, 0
br i1 %37, label %38, label %23
38: ; preds = %23, %7, %4
ret void
}