#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 */
typedef int int64_t;

/* Variables and functions */
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
int *malloc(int);
char *realloc(int *, int);
int main(void) {
  int64_t *m = malloc(1000);
  m[0] = 1;
  m[10] = m[1];
  char *c = calloc(1, 2000);
  for (int i = 0; i < 1000; i++) {
    c[i + 1000] = c[i];
  }
  char *r = realloc(m, 3000);
  for (int i = 0; i < 500; i++) {
    r[i + 2000] = 99;
  }
  free(c);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x3e8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x28(%rax)
mov    $0x1,%edi
mov    $0x7d0,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3e8,-0x1c(%rbp)
jge    11c8 <main+0x88>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x3e8,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118f <main+0x4f>
mov    -0x10(%rbp),%rdi
mov    $0xbb8,%esi
call   1060 <realloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x1f4,-0x2c(%rbp)
jge    1210 <main+0xd0>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x7d0,%ecx
movslq %ecx,%rcx
movb   $0x63,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11e1 <main+0xa1>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x3e8,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
movl   $0x1,(%rax)
mov    0x4(%rax),%eax
mov    %eax,0x28(%r14)
mov    $0x1,%edi
mov    $0x7d0,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
movb   $0x0,0x3e8(%rax)
mov    $0x3f9,%eax
nopl   0x0(%rax)
movups -0x3f8(%rbx,%rax,1),%xmm0
ff
movups -0x3e8(%rbx,%rax,1),%xmm1
ff
movups %xmm0,-0x10(%rbx,%rax,1)
movups %xmm1,(%rbx,%rax,1)
add    $0x20,%rax
cmp    $0x7d9,%rax
jne    1190 <main+0x40>
mov    0x3e1(%rbx),%al
mov    %al,0x7c9(%rbx)
movzwl 0x3e2(%rbx),%eax
mov    %ax,0x7ca(%rbx)
mov    0x3e4(%rbx),%eax
mov    %eax,0x7cc(%rbx)
mov    %r14,%rdi
mov    $0xbb8,%esi
call   1070 <realloc@plt>
lea    0x7d0(%rax),%rdi
mov    $0x1f4,%edx
mov    $0x63,%esi
call   1040 <memset@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i32* @malloc(i32 1000)
store i32 1, i32* %1
%2 = getelementptr inbounds i32, i32* %1, i64 1
%3 = load i32, i32* %2
%4 = getelementptr inbounds i32, i32* %1, i64 10
store i32 %3, i32* %4
%5 = tail call dereferenceable_or_null(2000) i8* @calloc(i32 1, i32 2000)
%6 = getelementptr inbounds i8, i8* %5, i64 1000
store i8 0, i8* %6
br label %7
7: ; preds = %7, %0
%8 = phi i64 [ 0, %0 ], [ %23, %7 ]
%9 = or i64 %8, 1
%10 = getelementptr inbounds i8, i8* %5, i64 %9
%11 = bitcast i8* %10 to <16 x i8>*
%12 = load <16 x i8>, <16 x i8>* %11
%13 = add nuw nsw i64 %8, 1001
%14 = getelementptr inbounds i8, i8* %5, i64 %13
%15 = bitcast i8* %14 to <16 x i8>*
store <16 x i8> %12, <16 x i8>* %15
%16 = or i64 %8, 17
%17 = getelementptr inbounds i8, i8* %5, i64 %16
%18 = bitcast i8* %17 to <16 x i8>*
%19 = load <16 x i8>, <16 x i8>* %18
%20 = add nuw nsw i64 %8, 1017
%21 = getelementptr inbounds i8, i8* %5, i64 %20
%22 = bitcast i8* %21 to <16 x i8>*
store <16 x i8> %19, <16 x i8>* %22
%23 = add nuw nsw i64 %8, 32
%24 = icmp eq i64 %23, 992
br i1 %24, label %25, label %7
25: ; preds = %7
%26 = getelementptr inbounds i8, i8* %5, i64 993
%27 = load i8, i8* %26
%28 = getelementptr inbounds i8, i8* %5, i64 1993
store i8 %27, i8* %28
%29 = getelementptr inbounds i8, i8* %5, i64 994
%30 = load i8, i8* %29
%31 = getelementptr inbounds i8, i8* %5, i64 1994
store i8 %30, i8* %31
%32 = getelementptr inbounds i8, i8* %5, i64 995
%33 = load i8, i8* %32
%34 = getelementptr inbounds i8, i8* %5, i64 1995
store i8 %33, i8* %34
%35 = getelementptr inbounds i8, i8* %5, i64 996
%36 = load i8, i8* %35
%37 = getelementptr inbounds i8, i8* %5, i64 1996
store i8 %36, i8* %37
%38 = getelementptr inbounds i8, i8* %5, i64 997
%39 = load i8, i8* %38
%40 = getelementptr inbounds i8, i8* %5, i64 1997
store i8 %39, i8* %40
%41 = getelementptr inbounds i8, i8* %5, i64 998
%42 = load i8, i8* %41
%43 = getelementptr inbounds i8, i8* %5, i64 1998
store i8 %42, i8* %43
%44 = getelementptr inbounds i8, i8* %5, i64 999
%45 = load i8, i8* %44
%46 = getelementptr inbounds i8, i8* %5, i64 1999
store i8 %45, i8* %46
%47 = tail call i8* @realloc(i32* %1, i32 3000)
%48 = getelementptr i8, i8* %47, i64 2000
%49 = tail call i32 @free(i8* %5)
ret i32 0
}