#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 */
char *calloc(int, int);
int /*<<< orphan*/ free(void *);
char *malloc(int);
char *realloc(char *, int);
int main(void) {
  char *p = malloc(10);
  for (int i = 0; i < 10; i++) {
    p[i] = '0' + i;
  }
  p = realloc(p, 1000);
  for (int i = 0; i < 1000; i++) {
    p[i] = i ^ 0xff;
  }
  p = calloc(60, 50);
  malloc(0);
  calloc(0, 0);
  free(p);
  free(p);
  free((void *)0xdeadbeef);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xa,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    118f <main+0x4f>
mov    -0x14(%rbp),%eax
add    $0x30,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1164 <main+0x24>
mov    -0x10(%rbp),%rdi
mov    $0x3e8,%esi
call   1060 <realloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3e8,-0x18(%rbp)
jge    11d8 <main+0x98>
mov    -0x18(%rbp),%eax
xor    $0xff,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a8 <main+0x68>
mov    $0x3c,%edi
mov    $0x32,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
xor    %edi,%edi
call   1050 <malloc@plt>
xor    %esi,%esi
mov    %esi,%edi
call   1040 <calloc@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0xdeadbeef,%edi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0xa,%edi
call   1050 <malloc@plt>
movabs $0x3736353433323130,%rcx
35 36 37
mov    %rcx,(%rax)
movw   $0x3938,0x8(%rax)
mov    %rax,%rdi
mov    $0x3e8,%esi
call   1060 <realloc@plt>
movdqa 0xe8d(%rip),%xmm0
mov    $0x10,%ecx
pcmpeqd %xmm1,%xmm1
movdqa 0xe8c(%rip),%xmm2
movdqa 0xe94(%rip),%xmm3
nopl   0x0(%rax)
movdqa %xmm0,%xmm4
pxor   %xmm1,%xmm4
movdqu %xmm4,-0x10(%rax,%rcx,1)
movdqa %xmm2,%xmm4
psubb  %xmm0,%xmm4
movdqu %xmm4,(%rax,%rcx,1)
paddb  %xmm3,%xmm0
add    $0x20,%rcx
cmp    $0x3f0,%rcx
jne    1190 <main+0x50>
movabs $0x18191a1b1c1d1e1f,%rcx
1a 19 18
mov    %rcx,0x3e0(%rax)
mov    $0x3c,%edi
mov    $0x32,%esi
call   1040 <calloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0xdeadbeef,%edi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i8* @malloc(i32 10)
store i8* %5, i8** %2
store i32 0, i32* %3
br label %6
6: ; preds = %17, %0
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 10
br i1 %8, label %9, label %20
9: ; preds = %6
%10 = load i32, i32* %3
%11 = add nsw i32 48, %10
%12 = trunc i32 %11 to i8
%13 = load i8*, i8** %2
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
store i8 %12, i8* %16
br label %17
17: ; preds = %9
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %6
20: ; preds = %6
%21 = load i8*, i8** %2
%22 = call i8* @realloc(i8* %21, i32 1000)
store i8* %22, i8** %2
store i32 0, i32* %4
br label %23
23: ; preds = %34, %20
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 1000
br i1 %25, label %26, label %37
26: ; preds = %23
%27 = load i32, i32* %4
%28 = xor i32 %27, 255
%29 = trunc i32 %28 to i8
%30 = load i8*, i8** %2
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 %29, i8* %33
br label %34
34: ; preds = %26
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %23
37: ; preds = %23
%38 = call i8* @calloc(i32 60, i32 50)
store i8* %38, i8** %2
%39 = call i8* @malloc(i32 0)
%40 = call i8* @calloc(i32 0, i32 0)
%41 = load i8*, i8** %2
%42 = call i32 @free(i8* %41)
%43 = load i8*, i8** %2
%44 = call i32 @free(i8* %43)
%45 = call i32 @free(i8* inttoptr (i64 3735928559 to i8*))
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
store i8 48, i8* %1
%2 = getelementptr inbounds i8, i8* %1, i64 1
store i8 49, i8* %2
%3 = getelementptr inbounds i8, i8* %1, i64 2
store i8 50, i8* %3
%4 = getelementptr inbounds i8, i8* %1, i64 3
store i8 51, i8* %4
%5 = getelementptr inbounds i8, i8* %1, i64 4
store i8 52, i8* %5
%6 = getelementptr inbounds i8, i8* %1, i64 5
store i8 53, i8* %6
%7 = getelementptr inbounds i8, i8* %1, i64 6
store i8 54, i8* %7
%8 = getelementptr inbounds i8, i8* %1, i64 7
store i8 55, i8* %8
%9 = getelementptr inbounds i8, i8* %1, i64 8
store i8 56, i8* %9
%10 = getelementptr inbounds i8, i8* %1, i64 9
store i8 57, i8* %10
%11 = tail call i8* @realloc(i8* %1, i32 1000)
br label %12
12: ; preds = %12, %0
%13 = phi i64 [ 0, %0 ], [ %22, %12 ]
%14 = phi <16 x i8> [ <i8 0, i8 1, i8 2, i8 3, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15>, %0 ], [ %23, %12 ]
%15 = xor <16 x i8> %14, <i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1>
%16 = getelementptr inbounds i8, i8* %11, i64 %13
%17 = bitcast i8* %16 to <16 x i8>*
store <16 x i8> %15, <16 x i8>* %17
%18 = or i64 %13, 16
%19 = sub <16 x i8> <i8 -17, i8 -17, i8 -17, i8 -17, i8 -17, i8 -17, i8 -17, i8 -17, i8 -17, i8 -17, i8 -17, i8 -17, i8 -17, i8 -17, i8 -17, i8 -17>, %14
%20 = getelementptr inbounds i8, i8* %11, i64 %18
%21 = bitcast i8* %20 to <16 x i8>*
store <16 x i8> %19, <16 x i8>* %21
%22 = add nuw nsw i64 %13, 32
%23 = add <16 x i8> %14, <i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32>
%24 = icmp eq i64 %22, 992
br i1 %24, label %25, label %12
25: ; preds = %12
%26 = getelementptr inbounds i8, i8* %11, i64 992
store i8 31, i8* %26
%27 = getelementptr inbounds i8, i8* %11, i64 993
store i8 30, i8* %27
%28 = getelementptr inbounds i8, i8* %11, i64 994
store i8 29, i8* %28
%29 = getelementptr inbounds i8, i8* %11, i64 995
store i8 28, i8* %29
%30 = getelementptr inbounds i8, i8* %11, i64 996
store i8 27, i8* %30
%31 = getelementptr inbounds i8, i8* %11, i64 997
store i8 26, i8* %31
%32 = getelementptr inbounds i8, i8* %11, i64 998
store i8 25, i8* %32
%33 = getelementptr inbounds i8, i8* %11, i64 999
store i8 24, i8* %33
%34 = tail call dereferenceable_or_null(3000) i8* @calloc(i32 60, i32 50)
%35 = tail call i32 @free(i8* %34)
%36 = tail call i32 @free(i8* %34)
%37 = tail call i32 @free(i8* inttoptr (i64 3735928559 to i8*))
ret i32 0
}