#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 */
char *addstr(char *, char *);
char *emptystr();
int /*<<< orphan*/ freestr(char *);
int /*<<< orphan*/ printf(char *, char *);
int main() {
  int i;
  char *dynstr;
  dynstr = emptystr();
  for (i = 0; i < 1000; i++)
    dynstr = addstr(dynstr, "123456789\n");
  printf("%s", dynstr);
  freestr(dynstr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <emptystr@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    1190 <main+0x50>
mov    -0x10(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1060 <addstr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1161 <main+0x21>
mov    -0x10(%rbp),%rsi
lea    0xe70(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <freestr@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1040 <emptystr@plt>
mov    %rax,%rbx
mov    $0x3e8,%ebp
lea    0xea6(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <addstr@plt>
mov    %rax,%rbx
add    $0xffffffff,%ebp
jne    1160 <main+0x20>
lea    0xe91(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <freestr@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"123456789\0A\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i8* (...) @emptystr()
store i8* %4, i8** %3
store i32 0, i32* %2
br label %5
5: ; preds = %11, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 1000
br i1 %7, label %8, label %14
8: ; preds = %5
%9 = load i8*, i8** %3
%10 = call i8* @addstr(i8* %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %3
br label %11
11: ; preds = %8
%12 = load i32, i32* %2
%13 = add nsw i32 %12, 1
store i32 %13, i32* %2
br label %5
14: ; preds = %5
%15 = load i8*, i8** %3
%16 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i8*, i8** %3
%18 = call i32 @freestr(i8* %17)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"123456789\0A\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = tail call i8* (...) @emptystr()
br label %2
2: ; preds = %0, %2
%3 = phi i8* [ %1, %0 ], [ %5, %2 ]
%4 = phi i32 [ 0, %0 ], [ %6, %2 ]
%5 = tail call i8* @addstr(i8* %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%6 = add nuw nsw i32 %4, 1
%7 = icmp eq i32 %6, 1000
br i1 %7, label %8, label %2
8: ; preds = %2
%9 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%10 = tail call i32 @freestr(i8* %5)
ret i32 0
}