#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 EXIT_SUCCESS;
void *calloc(int, int);
int /*<<< orphan*/ free(void *);
void *malloc(int);
int /*<<< orphan*/ memset(void *, char, int);
void *realloc(void *, int);
int main(int argc, char **argv, char **envp) {
  void *p1 = malloc(0x10);
  void *p2 = calloc(0x20, 1);
  memset(p1, 'A', 0x10);
  memset(p2, 'B', 0x20);
  p1 = realloc(p1, 0x30);
  free(p2);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x10,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x20,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x41,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    $0x42,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    $0x30,%esi
call   1070 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x10,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    $0x20,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x41,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    $0x42,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    %r14,%rdi
mov    $0x30,%esi
call   1070 <realloc@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%10 = call i8* @malloc(i32 16)
store i8* %10, i8** %8
%11 = call i8* @calloc(i32 32, i32 1)
store i8* %11, i8** %9
%12 = load i8*, i8** %8
%13 = call i32 @memset(i8* %12, i8 signext 65, i32 16)
%14 = load i8*, i8** %9
%15 = call i32 @memset(i8* %14, i8 signext 66, i32 32)
%16 = load i8*, i8** %8
%17 = call i8* @realloc(i8* %16, i32 48)
store i8* %17, i8** %8
%18 = load i8*, i8** %9
%19 = call i32 @free(i8* %18)
%20 = load i32, i32* @EXIT_SUCCESS
ret i32 %20
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture readnone %2) {
%4 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%5 = tail call dereferenceable_or_null(32) i8* @calloc(i32 32, i32 1)
%6 = tail call i32 @memset(i8* %4, i8 signext 65, i32 16)
%7 = tail call i32 @memset(i8* %5, i8 signext 66, i32 32)
%8 = tail call i8* @realloc(i8* %4, i32 48)
%9 = tail call i32 @free(i8* %5)
%10 = load i32, i32* @EXIT_SUCCESS
ret i32 %10
}