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


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

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%rsi
mov    $0x1,%edi
mov    $0x2,%edx
call   1040 <write@plt>
xor    %edi,%edi
mov    $0x8,%esi
call   1050 <realloc@plt>
mov    %rax,%r14
lea    0xea3(%rip),%rsi
mov    $0x1,%edi
mov    $0x2,%edx
call   1040 <write@plt>
xor    %edi,%edi
mov    $0x10,%esi
call   1050 <realloc@plt>
mov    %rax,%rbx
lea    0xe81(%rip),%rsi
mov    $0x1,%edi
mov    $0x2,%edx
call   1040 <write@plt>
movb   $0xa,(%rbx)
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xe63(%rip),%rsi
mov    $0x1,%edi
mov    $0x2,%edx
call   1040 <write@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"
@.str.3 = [3 x i8] c"D\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i32 @write(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%5 = call i8* @realloc(i32 0, i32 8)
store i8* %5, i8** %2
%6 = call i32 @write(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%7 = call i8* @realloc(i32 0, i32 16)
store i8* %7, i8** %3
%8 = call i32 @write(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%9 = load i8*, i8** %3
store i8 10, i8* %9
%10 = load i8*, i8** %2
%11 = call i32 @free(i8* %10)
%12 = call i32 @write(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
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"
@.str.3 = [3 x i8] c"D\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(i32 0, i32 8)
%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 i8* @realloc(i32 0, i32 16)
%5 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
store i8 10, i8* %4
%6 = tail call i32 @free(i8* %2)
%7 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
ret i32 0
}