#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 *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ realloc(char *, int);
int main() {
  char *mal = malloc(sizeof(char) * 10);
  memcpy(mal, "asdfasdfasdf", 5);
  char *addr = mal;
  for (int i = 0; i < 100; i++) {
    addr = (char *)realloc(addr, sizeof(char) * 15);
    for (int i = 5; i < 14; i++) {
      addr[i] = 'a' + i;
    }
    addr[14] = 0;
  }
  printf("%s\n", addr);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xa,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe98(%rip),%rsi
mov    $0x5,%edx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x64,-0x1c(%rbp)
jge    11e5 <main+0xa5>
mov    -0x18(%rbp),%rdi
mov    $0xf,%esi
call   1060 <realloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x5,-0x20(%rbp)
cmpl   $0xe,-0x20(%rbp)
jge    11cf <main+0x8f>
mov    -0x20(%rbp),%eax
add    $0x61,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11a4 <main+0x64>
mov    -0x18(%rbp),%rax
movb   $0x0,0xe(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1181 <main+0x41>
mov    -0x18(%rbp),%rsi
lea    0xe1d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0xa,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xea8(%rip),%rsi
mov    %rax,%rdi
mov    $0x5,%edx
call   1040 <memcpy@plt>
mov    $0x64,%ebp
movabs $0x6d6c6b6a69686766,%r14
6b 6c 6d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0xf,%esi
call   1060 <realloc@plt>
mov    %rax,%rbx
mov    %r14,0x5(%rax)
movw   $0x6e,0xd(%rax)
add    $0xffffffff,%ebp
jne    1180 <main+0x40>
lea    0xe67(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [13 x i8] c"asdfasdfasdf\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%2 = tail call i32 @memcpy(i8* %1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 5)
br label %6
3: ; preds = %6
%4 = inttoptr i64 %9 to i8*
%5 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %4)
ret i32 0
6: ; preds = %0, %6
%7 = phi i32 [ 0, %0 ], [ %21, %6 ]
%8 = phi i8* [ %1, %0 ], [ %10, %6 ]
%9 = tail call i64 @realloc(i8* %8, i32 15)
%10 = inttoptr i64 %9 to i8*
%11 = getelementptr inbounds i8, i8* %10, i64 5
store i8 102, i8* %11
%12 = getelementptr inbounds i8, i8* %10, i64 6
store i8 103, i8* %12
%13 = getelementptr inbounds i8, i8* %10, i64 7
store i8 104, i8* %13
%14 = getelementptr inbounds i8, i8* %10, i64 8
store i8 105, i8* %14
%15 = getelementptr inbounds i8, i8* %10, i64 9
store i8 106, i8* %15
%16 = getelementptr inbounds i8, i8* %10, i64 10
store i8 107, i8* %16
%17 = getelementptr inbounds i8, i8* %10, i64 11
store i8 108, i8* %17
%18 = getelementptr inbounds i8, i8* %10, i64 12
store i8 109, i8* %18
%19 = getelementptr inbounds i8, i8* %10, i64 13
store i8 110, i8* %19
%20 = getelementptr inbounds i8, i8* %10, i64 14
store i8 0, i8* %20
%21 = add nuw nsw i32 %7, 1
%22 = icmp eq i32 %21, 100
br i1 %22, label %3, label %6
}