#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);
int /*<<< orphan*/ memset(char *, char, int);
int main(int argc, const char *argv[]) {
  char *p = malloc(1024 - 8);
  char *p2 = malloc(1024 + 16 - 8);
  char *p3 = malloc(1024 - 8);
  char *p2_1;
  char *p2_2;
  memset(p, 'A', 1024 - 8);
  memset(p2, 'B', 1024 + 16 - 8);
  memset(p3, 'C', 1024 - 8);
  free(p2);
  p[1024 - 8] = '\0';
  p2_1 = malloc(512 - 8);
  memset(p2_1, 'B', 512 - 8);
  p2_2 = malloc(256 - 8);
  memset(p2_2, 'D', 256 - 8);
  free(p2_1);
  free(p3);
  p2 = malloc(2048);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x3f8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x408,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x3f8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x41,%esi
mov    $0x3f8,%edx
call   1040 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    $0x42,%esi
mov    $0x408,%edx
call   1040 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    $0x43,%esi
mov    $0x3f8,%edx
call   1040 <memset@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,0x3f8(%rax)
mov    $0x1f8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x42,%esi
mov    $0x1f8,%edx
call   1040 <memset@plt>
mov    $0xf8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x44,%esi
mov    $0xf8,%edx
call   1040 <memset@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    $0x800,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x3f8,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    $0x408,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    $0x3f8,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
mov    $0x41,%esi
mov    $0x3f8,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    $0x42,%esi
mov    $0x408,%edx
call   1040 <memset@plt>
mov    %r14,%rdi
mov    $0x43,%esi
mov    $0x3f8,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
movb   $0x0,0x3f8(%r15)
mov    $0x1f8,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x42,%esi
mov    $0x1f8,%edx
call   1040 <memset@plt>
mov    $0xf8,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
mov    $0x44,%esi
mov    $0xf8,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%10 = call i8* @malloc(i32 1016)
store i8* %10, i8** %5
%11 = call i8* @malloc(i32 1032)
store i8* %11, i8** %6
%12 = call i8* @malloc(i32 1016)
store i8* %12, i8** %7
%13 = load i8*, i8** %5
%14 = call i32 @memset(i8* %13, i8 signext 65, i32 1016)
%15 = load i8*, i8** %6
%16 = call i32 @memset(i8* %15, i8 signext 66, i32 1032)
%17 = load i8*, i8** %7
%18 = call i32 @memset(i8* %17, i8 signext 67, i32 1016)
%19 = load i8*, i8** %6
%20 = call i32 @free(i8* %19)
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i64 1016
store i8 0, i8* %22
%23 = call i8* @malloc(i32 504)
store i8* %23, i8** %8
%24 = load i8*, i8** %8
%25 = call i32 @memset(i8* %24, i8 signext 66, i32 504)
%26 = call i8* @malloc(i32 248)
store i8* %26, i8** %9
%27 = load i8*, i8** %9
%28 = call i32 @memset(i8* %27, i8 signext 68, i32 248)
%29 = load i8*, i8** %8
%30 = call i32 @free(i8* %29)
%31 = load i8*, i8** %7
%32 = call i32 @free(i8* %31)
%33 = call i8* @malloc(i32 2048)
store i8* %33, i8** %6
ret i32 0
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call dereferenceable_or_null(1016) i8* @malloc(i32 1016)
%4 = tail call dereferenceable_or_null(1032) i8* @malloc(i32 1032)
%5 = tail call dereferenceable_or_null(1016) i8* @malloc(i32 1016)
%6 = tail call i32 @memset(i8* %3, i8 signext 65, i32 1016)
%7 = tail call i32 @memset(i8* %4, i8 signext 66, i32 1032)
%8 = tail call i32 @memset(i8* %5, i8 signext 67, i32 1016)
%9 = tail call i32 @free(i8* %4)
%10 = getelementptr inbounds i8, i8* %3, i64 1016
store i8 0, i8* %10
%11 = tail call dereferenceable_or_null(504) i8* @malloc(i32 504)
%12 = tail call i32 @memset(i8* %11, i8 signext 66, i32 504)
%13 = tail call dereferenceable_or_null(248) i8* @malloc(i32 248)
%14 = tail call i32 @memset(i8* %13, i8 signext 68, i32 248)
%15 = tail call i32 @free(i8* %11)
%16 = tail call i32 @free(i8* %5)
ret i32 0
}