#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*/ assert(int *);
int *calloc(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int *realloc(int *, int);
int /*<<< orphan*/ stderr;
int main(void) {
  int *r, *oldr, *a;
  fprintf(stderr, "test simple malloc/free:\n");
  a = malloc(10 * sizeof(int));
  assert(a);
  fprintf(stderr, "(should be malloc-filled)     a[4] = %x\n", a[4]);
  free(a);
  fprintf(stderr, "(should be free-filled)       a[5] = %x\n", a[5]);
  fprintf(stderr, "test realloc-larger:\n");
  r = malloc(30 * sizeof(int));
  assert(r);
  fprintf(stderr, "(should be malloc-filled)    r[25] = %x\n", r[25]);
  oldr = r;
  r = realloc(r, 40 * sizeof(int));
  assert(r);
  fprintf(stderr, "(should be free-filled)   oldr[26] = %x\n", oldr[26]);
  fprintf(stderr, "(should be malloc-filled)    r[35] = %x\n", r[35]);
  free(r);
  fprintf(stderr, "test realloc-smaller:\n");
  r = malloc(30 * sizeof(int));
  assert(r);
  fprintf(stderr, "(should be malloc-filled)    r[25] = %x\n", r[25]);
  oldr = r;
  r = realloc(r, 20 * sizeof(int));
  assert(r);
  fprintf(stderr, "(should be free-filled)   oldr[26] = %x\n", oldr[26]);
  free(r);
  fprintf(stderr, "test calloc:\n");
  a = calloc(100, sizeof(int));
  assert(r);
  fprintf(stderr, "(should be zero)             a[42] = %x\n", a[42]);
  free(a);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x28,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <assert@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%edx
lea    0xe66(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    0x14(%rax),%edx
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x78,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <assert@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x64(%rax),%edx
lea    0xe5b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xa0,%esi
call   1080 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <assert@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    0x68(%rax),%edx
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8c(%rax),%edx
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x78,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <assert@plt>
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x64(%rax),%edx
lea    0xda4(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x50,%esi
call   1080 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <assert@plt>
mov    0x2cd1(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    0x68(%rax),%edx
lea    0xd8c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    0x2caa(%rip),%rax
mov    (%rax),%edi
lea    0xdd5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x64,%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <assert@plt>
mov    0x2c77(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    0xa8(%rax),%edx
lea    0xda6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    0x2e70(%rip),%r13
mov    0x0(%r13),%edi
lea    0xe85(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x28,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <assert@plt>
mov    0x0(%r13),%edi
mov    0x10(%rbx),%edx
lea    0xe75(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x0(%r13),%edi
mov    0x14(%rbx),%edx
lea    0xe81(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xe98(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x78,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <assert@plt>
mov    0x0(%r13),%edi
mov    0x64(%rbx),%edx
lea    0xe84(%rip),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    $0xa0,%esi
call   1080 <realloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1050 <assert@plt>
mov    0x0(%r13),%edi
mov    0x68(%rbx),%edx
lea    0xe7d(%rip),%r15
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%r13),%edi
mov    0x8c(%r12),%edx
lea    0xe89(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x0(%r13),%edi
lea    0xe98(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x78,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <assert@plt>
mov    0x0(%r13),%edi
mov    0x64(%rbx),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    $0x50,%esi
call   1080 <realloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <assert@plt>
mov    0x0(%r13),%edi
mov    0x68(%rbx),%edx
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x0(%r13),%edi
lea    0xe46(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x64,%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <assert@plt>
mov    0x0(%r13),%edi
mov    0xa8(%rbx),%edx
lea    0xe22(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"test simple malloc/free:\0A\00"
@.str.1 = [41 x i8] c"(should be malloc-filled) a[4] = %x\0A\00"
@.str.2 = [41 x i8] c"(should be free-filled) a[5] = %x\0A\00"
@.str.3 = [22 x i8] c"test realloc-larger:\0A\00"
@.str.4 = [41 x i8] c"(should be malloc-filled) r[25] = %x\0A\00"
@.str.5 = [41 x i8] c"(should be free-filled) oldr[26] = %x\0A\00"
@.str.6 = [41 x i8] c"(should be malloc-filled) r[35] = %x\0A\00"
@.str.7 = [23 x i8] c"test realloc-smaller:\0A\00"
@.str.8 = [14 x i8] c"test calloc:\0A\00"
@.str.9 = [41 x i8] c"(should be zero) a[42] = %x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
store i32 0, i32* %1
%5 = load i32, i32* @stderr
%6 = call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%7 = call i32* @malloc(i32 40)
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = call i32 @assert(i32* %8)
%10 = load i32, i32* @stderr
%11 = load i32*, i32** %4
%12 = getelementptr inbounds i32, i32* %11, i64 4
%13 = load i32, i32* %12
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32*, i32** %4
%16 = call i32 @free(i32* %15)
%17 = load i32, i32* @stderr
%18 = load i32*, i32** %4
%19 = getelementptr inbounds i32, i32* %18, i64 5
%20 = load i32, i32* %19
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32* @malloc(i32 120)
store i32* %24, i32** %2
%25 = load i32*, i32** %2
%26 = call i32 @assert(i32* %25)
%27 = load i32, i32* @stderr
%28 = load i32*, i32** %2
%29 = getelementptr inbounds i32, i32* %28, i64 25
%30 = load i32, i32* %29
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %30)
%32 = load i32*, i32** %2
store i32* %32, i32** %3
%33 = load i32*, i32** %2
%34 = call i32* @realloc(i32* %33, i32 160)
store i32* %34, i32** %2
%35 = load i32*, i32** %2
%36 = call i32 @assert(i32* %35)
%37 = load i32, i32* @stderr
%38 = load i32*, i32** %3
%39 = getelementptr inbounds i32, i32* %38, i64 26
%40 = load i32, i32* %39
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 %40)
%42 = load i32, i32* @stderr
%43 = load i32*, i32** %2
%44 = getelementptr inbounds i32, i32* %43, i64 35
%45 = load i32, i32* %44
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i32 %45)
%47 = load i32*, i32** %2
%48 = call i32 @free(i32* %47)
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%51 = call i32* @malloc(i32 120)
store i32* %51, i32** %2
%52 = load i32*, i32** %2
%53 = call i32 @assert(i32* %52)
%54 = load i32, i32* @stderr
%55 = load i32*, i32** %2
%56 = getelementptr inbounds i32, i32* %55, i64 25
%57 = load i32, i32* %56
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %57)
%59 = load i32*, i32** %2
store i32* %59, i32** %3
%60 = load i32*, i32** %2
%61 = call i32* @realloc(i32* %60, i32 80)
store i32* %61, i32** %2
%62 = load i32*, i32** %2
%63 = call i32 @assert(i32* %62)
%64 = load i32, i32* @stderr
%65 = load i32*, i32** %3
%66 = getelementptr inbounds i32, i32* %65, i64 26
%67 = load i32, i32* %66
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 %67)
%69 = load i32*, i32** %2
%70 = call i32 @free(i32* %69)
%71 = load i32, i32* @stderr
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
%73 = call i32* @calloc(i32 100, i32 4)
store i32* %73, i32** %4
%74 = load i32*, i32** %2
%75 = call i32 @assert(i32* %74)
%76 = load i32, i32* @stderr
%77 = load i32*, i32** %4
%78 = getelementptr inbounds i32, i32* %77, i64 42
%79 = load i32, i32* %78
%80 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.9, i64 0, i64 0), i32 %79)
%81 = load i32*, i32** %4
%82 = call i32 @free(i32* %81)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"test simple malloc/free:\0A\00"
@.str.1 = [41 x i8] c"(should be malloc-filled) a[4] = %x\0A\00"
@.str.2 = [41 x i8] c"(should be free-filled) a[5] = %x\0A\00"
@.str.3 = [22 x i8] c"test realloc-larger:\0A\00"
@.str.4 = [41 x i8] c"(should be malloc-filled) r[25] = %x\0A\00"
@.str.5 = [41 x i8] c"(should be free-filled) oldr[26] = %x\0A\00"
@.str.6 = [41 x i8] c"(should be malloc-filled) r[35] = %x\0A\00"
@.str.7 = [23 x i8] c"test realloc-smaller:\0A\00"
@.str.8 = [14 x i8] c"test calloc:\0A\00"
@.str.9 = [41 x i8] c"(should be zero) a[42] = %x\0A\00"
define i32 @main() {
%1 = load i32, i32* @stderr
%2 = tail call i32 (i32, i8*, ...) @fprintf(i32 %1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32* @malloc(i32 40)
%4 = tail call i32 @assert(i32* %3)
%5 = load i32, i32* @stderr
%6 = getelementptr inbounds i32, i32* %3, i64 4
%7 = load i32, i32* %6
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = tail call i32 @free(i32* %3)
%10 = load i32, i32* @stderr
%11 = getelementptr inbounds i32, i32* %3, i64 5
%12 = load i32, i32* %11
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%16 = tail call i32* @malloc(i32 120)
%17 = tail call i32 @assert(i32* %16)
%18 = load i32, i32* @stderr
%19 = getelementptr inbounds i32, i32* %16, i64 25
%20 = load i32, i32* %19
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%22 = tail call i32* @realloc(i32* %16, i32 160)
%23 = tail call i32 @assert(i32* %22)
%24 = load i32, i32* @stderr
%25 = getelementptr inbounds i32, i32* %16, i64 26
%26 = load i32, i32* %25
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 %26)
%28 = load i32, i32* @stderr
%29 = getelementptr inbounds i32, i32* %22, i64 35
%30 = load i32, i32* %29
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i32 %30)
%32 = tail call i32 @free(i32* %22)
%33 = load i32, i32* @stderr
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%35 = tail call i32* @malloc(i32 120)
%36 = tail call i32 @assert(i32* %35)
%37 = load i32, i32* @stderr
%38 = getelementptr inbounds i32, i32* %35, i64 25
%39 = load i32, i32* %38
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %39)
%41 = tail call i32* @realloc(i32* %35, i32 80)
%42 = tail call i32 @assert(i32* %41)
%43 = load i32, i32* @stderr
%44 = getelementptr inbounds i32, i32* %35, i64 26
%45 = load i32, i32* %44
%46 = tail call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 %45)
%47 = tail call i32 @free(i32* %41)
%48 = load i32, i32* @stderr
%49 = tail call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
%50 = tail call i32* @calloc(i32 100, i32 4)
%51 = tail call i32 @assert(i32* %41)
%52 = load i32, i32* @stderr
%53 = getelementptr inbounds i32, i32* %50, i64 42
%54 = load i32, i32* %53
%55 = tail call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.9, i64 0, i64 0), i32 %54)
%56 = tail call i32 @free(i32* %50)
ret i32 0
}