#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 */
int /*<<< orphan*/ free(char *);
char *malloc(int);
char *realloc(char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  char *x = (char *)0x10;
  char *y;
  char *z;
  write(1, "A\n", 2);
  z = realloc(x, 30);
  write(1, "B\n", 2);
  y = malloc(8);
  write(1, "C\n", 2);
  free(y);
  free(z);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x10,%eax
mov    %rax,-0x10(%rbp)
mov    $0x1,%edi
lea    0xe9c(%rip),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1e,%esi
call   1060 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x1,%edi
lea    0xe77(%rip),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x1,%edi
lea    0xe56(%rip),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rsi
mov    $0x1,%edi
mov    $0x2,%edx
call   1040 <write@plt>
mov    $0x10,%edi
mov    $0x1e,%esi
call   1060 <realloc@plt>
mov    %rax,%r14
lea    0xe90(%rip),%rsi
mov    $0x1,%edi
mov    $0x2,%edx
call   1040 <write@plt>
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe70(%rip),%rsi
mov    $0x1,%edi
mov    $0x2,%edx
call   1040 <write@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"A\0A\00"
@.str.1 = [3 x i8] c"B\0A\00"
@.str.2 = [3 x i8] c"C\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i32 0, i32* %1
store i8* inttoptr (i64 16 to i8*), i8** %2
%5 = call i32 @write(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%6 = load i8*, i8** %2
%7 = call i8* @realloc(i8* %6, i32 30)
store i8* %7, i8** %4
%8 = call i32 @write(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%9 = call i8* @malloc(i32 8)
store i8* %9, i8** %3
%10 = call i32 @write(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%11 = load i8*, i8** %3
%12 = call i32 @free(i8* %11)
%13 = load i8*, i8** %4
%14 = call i32 @free(i8* %13)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"A\0A\00"
@.str.1 = [3 x i8] c"B\0A\00"
@.str.2 = [3 x i8] c"C\0A\00"
define i32 @main() {
%1 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%2 = tail call i8* @realloc(i8* inttoptr (i64 16 to i8*), i32 30)
%3 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%4 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%5 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%6 = tail call i32 @free(i8* %4)
%7 = tail call i32 @free(i8* %2)
ret i32 0
}