#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*/ free(char *);
char *sr_indent_except_first_line(char const *, int);
int /*<<< orphan*/ sr_strbuf_append_char(struct sr_strbuf *, char);
int /*<<< orphan*/ sr_strbuf_append_str(struct sr_strbuf *, char *);
char *sr_strbuf_free_nobuf(struct sr_strbuf *);
struct sr_strbuf *sr_strbuf_new();
char *sr_indent(const char *input, int spaces) {
  struct sr_strbuf *strbuf = sr_strbuf_new();
  if (*input) {
    for (int i = 0; i < spaces; ++i)
      sr_strbuf_append_char(strbuf, ' ');
  }
  char *indented = sr_indent_except_first_line(input, spaces);
  sr_strbuf_append_str(strbuf, indented);
  free(indented);
  return sr_strbuf_free_nobuf(strbuf);
}


x86 assembly (clang, -O0):
<sr_indent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1080 <sr_strbuf_new@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11bb <sr_indent+0x5b>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b6 <sr_indent+0x56>
mov    -0x18(%rbp),%rdi
mov    $0x20,%esi
call   1070 <sr_strbuf_append_char@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118e <sr_indent+0x2e>
jmp    11bb <sr_indent+0x5b>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <sr_indent_except_first_line@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <sr_strbuf_append_str@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1050 <sr_strbuf_free_nobuf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sr_indent>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
xor    %eax,%eax
call   1080 <sr_strbuf_new@plt>
mov    %rax,%rbx
cmpb   $0x0,(%r14)
je     11a2 <sr_indent+0x42>
test   %r15d,%r15d
jle    11a2 <sr_indent+0x42>
mov    %r15d,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    $0x20,%esi
call   1070 <sr_strbuf_append_char@plt>
add    $0xffffffff,%ebp
jne    1190 <sr_indent+0x30>
mov    %r14,%rdi
mov    %r15d,%esi
call   1060 <sr_indent_except_first_line@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <sr_strbuf_append_str@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <sr_strbuf_free_nobuf@plt>

LLVM IR (-O0):
%struct.sr_strbuf = type { i32 }
define i8* @sr_indent(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.sr_strbuf*
%6 = alloca i32
%7 = alloca i8*
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
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %12, label %24
12: ; preds = %2
store i32 0, i32* %6
br label %13
13: ; preds = %20, %12
%14 = load i32, i32* %6
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load %struct.sr_strbuf*, %struct.sr_strbuf** %5
%19 = call i32 @sr_strbuf_append_char(%struct.sr_strbuf* %18, i8 signext 32)
br label %20
20: ; preds = %17
%21 = load i32, i32* %6
%22 = add nsw i32 %21, 1
store i32 %22, i32* %6
br label %13
23: ; preds = %13
br label %24
24: ; preds = %23, %2
%25 = load i8*, i8** %3
%26 = load i32, i32* %4
%27 = call i8* @sr_indent_except_first_line(i8* %25, i32 %26)
store i8* %27, i8** %7
%28 = load %struct.sr_strbuf*, %struct.sr_strbuf** %5
%29 = load i8*, i8** %7
%30 = call i32 @sr_strbuf_append_str(%struct.sr_strbuf* %28, i8* %29)
%31 = load i8*, i8** %7
%32 = call i32 @free(i8* %31)
%33 = load %struct.sr_strbuf*, %struct.sr_strbuf** %5
%34 = call i8* @sr_strbuf_free_nobuf(%struct.sr_strbuf* %33)
ret i8* %34
}

LLVM IR (-O2):
%struct.sr_strbuf = type { i32 }
define i8* @sr_indent(i8* %0, i32 %1) {
%3 = tail call %struct.sr_strbuf* (...) @sr_strbuf_new()
%4 = load i8, i8* %0
%5 = icmp ne i8 %4, 0
%6 = icmp sgt i32 %1, 0
%7 = and i1 %5, %6
br i1 %7, label %8, label %13
8: ; preds = %2, %8
%9 = phi i32 [ %11, %8 ], [ 0, %2 ]
%10 = tail call i32 @sr_strbuf_append_char(%struct.sr_strbuf* %3, i8 signext 32)
%11 = add nuw nsw i32 %9, 1
%12 = icmp eq i32 %11, %1
br i1 %12, label %13, label %8
13: ; preds = %8, %2
%14 = tail call i8* @sr_indent_except_first_line(i8* %0, i32 %1)
%15 = tail call i32 @sr_strbuf_append_str(%struct.sr_strbuf* %3, i8* %14)
%16 = tail call i32 @free(i8* %14)
%17 = tail call i8* @sr_strbuf_free_nobuf(%struct.sr_strbuf* %3)
ret i8* %17
}