#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);
  memset(p, 'A', 1024 - 8);
  memset(p2, 'B', 1024 + 16 - 8);
  memset(p3, 'C', 1024 - 8);
  free(p2);
  p[1024 - 8] = '\0';
  p2 = malloc(512 - 8);
  memset(p2, 'B', 512 - 8);
  free(p3);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x42,%esi
mov    $0x1f8,%edx
call   1040 <memset@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%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,%rdi
mov    $0x42,%esi
mov    $0x1f8,%edx
call   1040 <memset@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*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = call i8* @malloc(i32 1016)
store i8* %8, i8** %5
%9 = call i8* @malloc(i32 1032)
store i8* %9, i8** %6
%10 = call i8* @malloc(i32 1016)
store i8* %10, i8** %7
%11 = load i8*, i8** %5
%12 = call i32 @memset(i8* %11, i8 signext 65, i32 1016)
%13 = load i8*, i8** %6
%14 = call i32 @memset(i8* %13, i8 signext 66, i32 1032)
%15 = load i8*, i8** %7
%16 = call i32 @memset(i8* %15, i8 signext 67, i32 1016)
%17 = load i8*, i8** %6
%18 = call i32 @free(i8* %17)
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 1016
store i8 0, i8* %20
%21 = call i8* @malloc(i32 504)
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = call i32 @memset(i8* %22, i8 signext 66, i32 504)
%24 = load i8*, i8** %7
%25 = call i32 @free(i8* %24)
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 i32 @free(i8* %5)
ret i32 0
}