#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 sr_strbuf {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ sr_strbuf_append_char(struct sr_strbuf *, char const);
char *sr_strbuf_free_nobuf(struct sr_strbuf *);
struct sr_strbuf *sr_strbuf_new();
char *sr_indent_except_first_line(const char *input, int spaces) {
  struct sr_strbuf *strbuf = sr_strbuf_new();
  const char *c = input;
  while (*c) {
    if (*c == '\n') {
      sr_strbuf_append_char(strbuf, '\n');
      if (*++c) {
        for (int i = 0; i < spaces; ++i)
          sr_strbuf_append_char(strbuf, ' ');
      }
      continue;
    } else
      sr_strbuf_append_char(strbuf, *c);
    ++c;
  }
  return sr_strbuf_free_nobuf(strbuf);
}


x86 assembly (clang, -O0):
<sr_indent_except_first_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1050 <sr_strbuf_new@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11f0 <sr_indent_except_first_line+0xc0>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11cf <sr_indent_except_first_line+0x9f>
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   1040 <sr_strbuf_append_char@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
cmpb   $0x0,0x1(%rax)
je     11ca <sr_indent_except_first_line+0x9a>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c5 <sr_indent_except_first_line+0x95>
mov    -0x18(%rbp),%rdi
mov    $0x20,%esi
call   1040 <sr_strbuf_append_char@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119d <sr_indent_except_first_line+0x6d>
jmp    11ca <sr_indent_except_first_line+0x9a>
jmp    1152 <sr_indent_except_first_line+0x22>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
movsbl (%rax),%esi
call   1040 <sr_strbuf_append_char@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1152 <sr_indent_except_first_line+0x22>
mov    -0x18(%rbp),%rdi
call   1030 <sr_strbuf_free_nobuf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sr_indent_except_first_line>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbp
xor    %eax,%eax
call   1050 <sr_strbuf_new@plt>
mov    %rax,%rbx
nopw   0x0(%rax,%rax,1)
mov    0x0(%rbp),%al
cmp    $0xa,%al
je     1170 <sr_indent_except_first_line+0x40>
test   %al,%al
je     11b7 <sr_indent_except_first_line+0x87>
movsbl %al,%esi
mov    %rbx,%rdi
call   1040 <sr_strbuf_append_char@plt>
add    $0x1,%rbp
jmp    1150 <sr_indent_except_first_line+0x20>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <sr_strbuf_append_char@plt>
lea    0x1(%rbp),%r15
cmpb   $0x0,0x1(%rbp)
mov    %r15,%rbp
je     1150 <sr_indent_except_first_line+0x20>
mov    %r15,%rbp
test   %r14d,%r14d
jle    1150 <sr_indent_except_first_line+0x20>
mov    %r14d,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <sr_strbuf_append_char@plt>
add    $0xffffffff,%ebp
jne    11a0 <sr_indent_except_first_line+0x70>
mov    %r15,%rbp
jmp    1150 <sr_indent_except_first_line+0x20>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <sr_strbuf_free_nobuf@plt>

LLVM IR (-O0):
%struct.sr_strbuf = type { i32 }
define i8* @sr_indent_except_first_line(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.sr_strbuf*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = call %struct.sr_strbuf* (...) @sr_strbuf_new()
store %struct.sr_strbuf* %8, %struct.sr_strbuf** %5
%9 = load i8*, i8** %3
store i8* %9, i8** %6
br label %10
10: ; preds = %44, %38, %2
%11 = load i8*, i8** %6
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %47
14: ; preds = %10
%15 = load i8*, i8** %6
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 10
br i1 %18, label %19, label %39
19: ; preds = %14
%20 = load %struct.sr_strbuf*, %struct.sr_strbuf** %5
%21 = call i32 @sr_strbuf_append_char(%struct.sr_strbuf* %20, i8 signext 10)
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %6
%24 = load i8, i8* %23
%25 = icmp ne i8 %24, 0
br i1 %25, label %26, label %38
26: ; preds = %19
store i32 0, i32* %7
br label %27
27: ; preds = %34, %26
%28 = load i32, i32* %7
%29 = load i32, i32* %4
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %37
31: ; preds = %27
%32 = load %struct.sr_strbuf*, %struct.sr_strbuf** %5
%33 = call i32 @sr_strbuf_append_char(%struct.sr_strbuf* %32, i8 signext 32)
br label %34
34: ; preds = %31
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %27
37: ; preds = %27
br label %38
38: ; preds = %37, %19
br label %10
39: ; preds = %14
%40 = load %struct.sr_strbuf*, %struct.sr_strbuf** %5
%41 = load i8*, i8** %6
%42 = load i8, i8* %41
%43 = call i32 @sr_strbuf_append_char(%struct.sr_strbuf* %40, i8 signext %42)
br label %44
44: ; preds = %39
%45 = load i8*, i8** %6
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %6
br label %10
47: ; preds = %10
%48 = load %struct.sr_strbuf*, %struct.sr_strbuf** %5
%49 = call i8* @sr_strbuf_free_nobuf(%struct.sr_strbuf* %48)
ret i8* %49
}

LLVM IR (-O2):
%struct.sr_strbuf = type { i32 }
define i8* @sr_indent_except_first_line(i8* nocapture %0, i32 %1) {
%3 = tail call %struct.sr_strbuf* (...) @sr_strbuf_new()
%4 = icmp slt i32 %1, 1
br label %5
5: ; preds = %14, %2
%6 = phi i8* [ %0, %2 ], [ %15, %14 ]
%7 = load i8, i8* %6
switch i8 %7, label %21 [
i8 0, label %24
i8 10, label %8
]
8: ; preds = %5
%9 = tail call i32 @sr_strbuf_append_char(%struct.sr_strbuf* %3, i8 signext 10)
%10 = getelementptr inbounds i8, i8* %6, i64 1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
%13 = or i1 %12, %4
br i1 %13, label %14, label %16
14: ; preds = %16, %8, %21
%15 = phi i8* [ %23, %21 ], [ %10, %8 ], [ %10, %16 ]
br label %5
16: ; preds = %8, %16
%17 = phi i32 [ %19, %16 ], [ 0, %8 ]
%18 = tail call i32 @sr_strbuf_append_char(%struct.sr_strbuf* %3, i8 signext 32)
%19 = add nuw nsw i32 %17, 1
%20 = icmp eq i32 %19, %1
br i1 %20, label %14, label %16
21: ; preds = %5
%22 = tail call i32 @sr_strbuf_append_char(%struct.sr_strbuf* %3, i8 signext %7)
%23 = getelementptr inbounds i8, i8* %6, i64 1
br label %14
24: ; preds = %5
%25 = tail call i8* @sr_strbuf_free_nobuf(%struct.sr_strbuf* %3)
ret i8* %25
}