#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 *calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
char *realloc(char *, int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcpy(char *, char *);
int main(void) {
  char *name = calloc(sizeof(char), 5);
  if (name == NULL) {
    exit(1);
  }
  strcpy(name, "Adam");
  fprintf(stdout, "name: %s\n", name);
  char *tmp = realloc(name, sizeof(char) * 17);
  if (tmp == NULL) {
    free(name);
    exit(1);
  }
  name = tmp;
  strcpy(name, "Kenny McCormick");
  fprintf(stdout, "name: %s\n", name);
  free(name);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1,%edi
mov    $0x5,%esi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1197 <main+0x37>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1040 <strcpy@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe4a(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x11,%esi
call   1070 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f0 <main+0x90>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe0c(%rip),%rsi
call   1040 <strcpy@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xde9(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x1,%edi
mov    $0x5,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     11ea <main+0x8a>
mov    %rax,%r14
lea    0xe7d(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    0x2e4e(%rip),%r15
mov    (%r15),%edi
lea    0xe69(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    %r14,%rdi
mov    $0x11,%esi
call   1070 <realloc@plt>
test   %rax,%rax
je     11f4 <main+0x94>
mov    %rax,%rbx
lea    0xe4f(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    (%r15),%edi
lea    0xe33(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"Adam\00"
@stdout = global i32 0
@.str.1 = [10 x i8] c"name: %s\0A\00"
@.str.2 = [16 x i8] c"Kenny McCormick\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i8* @calloc(i32 1, i32 5)
store i8* %4, i8** %2
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = load i8*, i8** %2
%11 = call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @stdout
%13 = load i8*, i8** %2
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %2
%16 = call i8* @realloc(i8* %15, i32 17)
store i8* %16, i8** %3
%17 = load i8*, i8** %3
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %23
19: ; preds = %9
%20 = load i8*, i8** %2
%21 = call i32 @free(i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %9
%24 = load i8*, i8** %3
store i8* %24, i8** %2
%25 = load i8*, i8** %2
%26 = call i32 @strcpy(i8* %25, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* @stdout
%28 = load i8*, i8** %2
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = load i8*, i8** %2
%31 = call i32 @free(i8* %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"Adam\00"
@stdout = global i32 0
@.str.1 = [10 x i8] c"name: %s\0A\00"
@.str.2 = [16 x i8] c"Kenny McCormick\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(5) i8* @calloc(i32 1, i32 5)
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @exit(i32 1)
unreachable
5: ; preds = %0
%6 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stdout
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%9 = tail call i8* @realloc(i8* %1, i32 17)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %5
%12 = tail call i32 @free(i8* %1)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %5
%15 = tail call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%16 = load i32, i32* @stdout
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%18 = tail call i32 @free(i8* %9)
ret i32 0
}