#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*/ EXIT_FAILURE;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int *realloc(int *, int);
int main(void) {
  int i;
  int *one;
  int *one_saved;
  int *two;
  int *two_saved;
  int *one_bigger;
  int *two_bigger;
  one = malloc(sizeof(int) * 1000);
  if (!one) {
    exit(EXIT_FAILURE);
  }
  one_saved = one;
  two = malloc(sizeof(int) * 1000);
  if (!two) {
    exit(EXIT_FAILURE);
  }
  two_saved = two;
  for (i = 0; i < 1000; ++i) {
    one[i] = i;
    two[i] = 1 + (2 * i);
  }
  for (i = 0; i < 1000; ++i) {
    assert(one[i] == i);
    assert(two[i] == (1 + (2 * i)));
  }
  one_bigger = realloc(one, sizeof(int) * 2 * 1000);
  two_bigger = realloc(two, sizeof(int) * 2 * 1000);
  printf("one_saved:  %p\none_bigger: %p\n", one_saved, one_bigger);
  printf("two_saved:  %p\ntwo_bigger: %p\n", two_saved, two_bigger);
  for (i = 0; i < 1000; ++i) {
    assert(one_bigger[i] == i);
    assert(two_bigger[i] == (1 + (2 * i)));
  }
  printf("storage larger, initial contents the same\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xfa0,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1186 <main+0x36>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0xfa0,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b5 <main+0x65>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    1201 <main+0xb1>
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%edx
shl    $0x1,%edx
add    $0x1,%edx
mov    -0x20(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11c4 <main+0x74>
movl   $0x0,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    1261 <main+0x111>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x8(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x20(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1208 <main+0xb8>
mov    -0x10(%rbp),%rdi
mov    $0x1f40,%esi
call   1060 <realloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x1f40,%esi
call   1060 <realloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    1311 <main+0x1c1>
mov    -0x30(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x8(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x38(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    12b8 <main+0x168>
lea    0xd26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    $0xfa0,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     135d <main+0x1fd>
mov    %rax,%r14
mov    $0xfa0,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     135d <main+0x1fd>
mov    %rax,%r13
movdqa 0xe63(%rip),%xmm1
mov    $0xc,%eax
movdqa 0xe65(%rip),%xmm8
movdqa 0xe6c(%rip),%xmm10
movdqa 0xe74(%rip),%xmm3
movdqa 0xe7c(%rip),%xmm4
movdqa 0xe83(%rip),%xmm9
movdqa 0xe8b(%rip),%xmm6
movdqa %xmm1,%xmm2
nopl   0x0(%rax)
movdqa %xmm1,%xmm0
paddd  %xmm8,%xmm0
movdqu %xmm1,-0x30(%r14,%rax,4)
movdqu %xmm0,-0x20(%r14,%rax,4)
movdqa %xmm2,%xmm0
paddd  %xmm2,%xmm0
movdqa %xmm0,%xmm5
por    %xmm10,%xmm5
paddd  %xmm3,%xmm0
movdqu %xmm5,-0x30(%r13,%rax,4)
movdqu %xmm0,-0x20(%r13,%rax,4)
cmp    $0x3ec,%rax
je     1278 <main+0x118>
movdqa %xmm2,%xmm0
paddd  %xmm4,%xmm0
movdqa %xmm1,%xmm5
paddd  %xmm4,%xmm5
movdqa %xmm1,%xmm7
paddd  %xmm9,%xmm7
movdqu %xmm5,-0x10(%r14,%rax,4)
movdqu %xmm7,(%r14,%rax,4)
paddd  %xmm0,%xmm0
movdqa %xmm0,%xmm5
por    %xmm10,%xmm5
paddd  %xmm3,%xmm0
movdqu %xmm5,-0x10(%r13,%rax,4)
movdqu %xmm0,0x0(%r13,%rax,4)
paddd  %xmm6,%xmm1
paddd  %xmm6,%xmm2
add    $0x10,%rax
jmp    11e0 <main+0x80>
mov    $0x1,%r15d
xor    %ebx,%ebx
mov    (%r14,%rbx,4),%eax
xor    %edi,%edi
cmp    %rax,%rbx
sete   %dil
call   1050 <assert@plt>
mov    0x0(%r13,%rbx,4),%eax
xor    %edi,%edi
cmp    %rax,%r15
sete   %dil
call   1050 <assert@plt>
add    $0x1,%rbx
add    $0x2,%r15
cmp    $0x3e8,%rbx
jne    1280 <main+0x120>
mov    %r14,%rdi
mov    $0x1f40,%esi
call   1070 <realloc@plt>
mov    %rax,%r15
mov    %r13,%rdi
mov    $0x1f40,%esi
call   1070 <realloc@plt>
mov    %rax,%r12
lea    0xd93(%rip),%rdi
xor    %ebx,%ebx
mov    %r14,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd9c(%rip),%rdi
mov    %r13,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r14d
cs nopw 0x0(%rax,%rax,1)
mov    (%r15,%rbx,4),%eax
xor    %edi,%edi
cmp    %rax,%rbx
sete   %dil
call   1050 <assert@plt>
mov    (%r12,%rbx,4),%eax
xor    %edi,%edi
cmp    %rax,%r14
sete   %dil
call   1050 <assert@plt>
add    $0x1,%rbx
add    $0x2,%r14
cmp    $0x3e8,%rbx
jne    1310 <main+0x1b0>
lea    0xd62(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2c7c(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [31 x i8] c"one_saved: %p\0Aone_bigger: %p\0A\00"
@.str.1 = [31 x i8] c"two_saved: %p\0Atwo_bigger: %p\0A\00"
@.str.2 = [43 x i8] c"storage larger, initial contents the same\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
store i32 0, i32* %1
%9 = call i32* @malloc(i32 4000)
store i32* %9, i32** %3
%10 = load i32*, i32** %3
%11 = icmp ne i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %0
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %0
%16 = load i32*, i32** %3
store i32* %16, i32** %4
%17 = call i32* @malloc(i32 4000)
store i32* %17, i32** %5
%18 = load i32*, i32** %5
%19 = icmp ne i32* %18, null
br i1 %19, label %23, label %20
20: ; preds = %15
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %15
%24 = load i32*, i32** %5
store i32* %24, i32** %6
store i32 0, i32* %2
br label %25
25: ; preds = %41, %23
%26 = load i32, i32* %2
%27 = icmp slt i32 %26, 1000
br i1 %27, label %28, label %44
28: ; preds = %25
%29 = load i32, i32* %2
%30 = load i32*, i32** %3
%31 = load i32, i32* %2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
store i32 %29, i32* %33
%34 = load i32, i32* %2
%35 = mul nsw i32 2, %34
%36 = add nsw i32 1, %35
%37 = load i32*, i32** %5
%38 = load i32, i32* %2
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
store i32 %36, i32* %40
br label %41
41: ; preds = %28
%42 = load i32, i32* %2
%43 = add nsw i32 %42, 1
store i32 %43, i32* %2
br label %25
44: ; preds = %25
store i32 0, i32* %2
br label %45
45: ; preds = %69, %44
%46 = load i32, i32* %2
%47 = icmp slt i32 %46, 1000
br i1 %47, label %48, label %72
48: ; preds = %45
%49 = load i32*, i32** %3
%50 = load i32, i32* %2
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %49, i64 %51
%53 = load i32, i32* %52
%54 = load i32, i32* %2
%55 = icmp eq i32 %53, %54
%56 = zext i1 %55 to i32
%57 = call i32 @assert(i32 %56)
%58 = load i32*, i32** %5
%59 = load i32, i32* %2
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i32, i32* %58, i64 %60
%62 = load i32, i32* %61
%63 = load i32, i32* %2
%64 = mul nsw i32 2, %63
%65 = add nsw i32 1, %64
%66 = icmp eq i32 %62, %65
%67 = zext i1 %66 to i32
%68 = call i32 @assert(i32 %67)
br label %69
69: ; preds = %48
%70 = load i32, i32* %2
%71 = add nsw i32 %70, 1
store i32 %71, i32* %2
br label %45
72: ; preds = %45
%73 = load i32*, i32** %3
%74 = call i32* @realloc(i32* %73, i32 8000)
store i32* %74, i32** %7
%75 = load i32*, i32** %5
%76 = call i32* @realloc(i32* %75, i32 8000)
store i32* %76, i32** %8
%77 = load i32*, i32** %4
%78 = load i32*, i32** %7
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32* %77, i32* %78)
%80 = load i32*, i32** %6
%81 = load i32*, i32** %8
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32* %80, i32* %81)
store i32 0, i32* %2
br label %83
83: ; preds = %107, %72
%84 = load i32, i32* %2
%85 = icmp slt i32 %84, 1000
br i1 %85, label %86, label %110
86: ; preds = %83
%87 = load i32*, i32** %7
%88 = load i32, i32* %2
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i32, i32* %87, i64 %89
%91 = load i32, i32* %90
%92 = load i32, i32* %2
%93 = icmp eq i32 %91, %92
%94 = zext i1 %93 to i32
%95 = call i32 @assert(i32 %94)
%96 = load i32*, i32** %8
%97 = load i32, i32* %2
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i32, i32* %96, i64 %98
%100 = load i32, i32* %99
%101 = load i32, i32* %2
%102 = mul nsw i32 2, %101
%103 = add nsw i32 1, %102
%104 = icmp eq i32 %100, %103
%105 = zext i1 %104 to i32
%106 = call i32 @assert(i32 %105)
br label %107
107: ; preds = %86
%108 = load i32, i32* %2
%109 = add nsw i32 %108, 1
store i32 %109, i32* %2
br label %83
110: ; preds = %83
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [31 x i8] c"one_saved: %p\0Aone_bigger: %p\0A\00"
@.str.1 = [31 x i8] c"two_saved: %p\0Atwo_bigger: %p\0A\00"
@str = [42 x i8] c"storage larger, initial contents the same\00"
define i32 @main() {
%1 = tail call i32* @malloc(i32 4000)
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = load i32, i32* @EXIT_FAILURE
%5 = tail call i32 @exit(i32 %4)
unreachable
6: ; preds = %0
%7 = tail call i32* @malloc(i32 4000)
%8 = icmp eq i32* %7, null
br i1 %8, label %49, label %9
9: ; preds = %6, %30
%10 = phi i64 [ %46, %30 ], [ 0, %6 ]
%11 = phi <4 x i32> [ %47, %30 ], [ <i32 0, i32 1, i32 2, i32 3>, %6 ]
%12 = phi <4 x i32> [ %48, %30 ], [ <i32 0, i32 1, i32 2, i32 3>, %6 ]
%13 = add <4 x i32> %11, <i32 4, i32 4, i32 4, i32 4>
%14 = getelementptr inbounds i32, i32* %1, i64 %10
%15 = bitcast i32* %14 to <4 x i32>*
store <4 x i32> %11, <4 x i32>* %15
%16 = getelementptr inbounds i32, i32* %14, i64 4
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> %13, <4 x i32>* %17
%18 = getelementptr inbounds i32, i32* %7, i64 %10
%19 = shl <4 x i32> %12, <i32 1, i32 1, i32 1, i32 1>
%20 = shl <4 x i32> %12, <i32 1, i32 1, i32 1, i32 1>
%21 = add <4 x i32> %20, <i32 8, i32 8, i32 8, i32 8>
%22 = or <4 x i32> %19, <i32 1, i32 1, i32 1, i32 1>
%23 = or <4 x i32> %21, <i32 1, i32 1, i32 1, i32 1>
%24 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> %22, <4 x i32>* %24
%25 = getelementptr inbounds i32, i32* %18, i64 4
%26 = bitcast i32* %25 to <4 x i32>*
store <4 x i32> %23, <4 x i32>* %26
%27 = or i64 %10, 8
%28 = add <4 x i32> %12, <i32 8, i32 8, i32 8, i32 8>
%29 = icmp eq i64 %27, 1000
br i1 %29, label %52, label %30
30: ; preds = %9
%31 = add <4 x i32> %11, <i32 8, i32 8, i32 8, i32 8>
%32 = add <4 x i32> %11, <i32 12, i32 12, i32 12, i32 12>
%33 = getelementptr inbounds i32, i32* %1, i64 %27
%34 = bitcast i32* %33 to <4 x i32>*
store <4 x i32> %31, <4 x i32>* %34
%35 = getelementptr inbounds i32, i32* %33, i64 4
%36 = bitcast i32* %35 to <4 x i32>*
store <4 x i32> %32, <4 x i32>* %36
%37 = getelementptr inbounds i32, i32* %7, i64 %27
%38 = shl <4 x i32> %28, <i32 1, i32 1, i32 1, i32 1>
%39 = shl <4 x i32> %28, <i32 1, i32 1, i32 1, i32 1>
%40 = add <4 x i32> %39, <i32 8, i32 8, i32 8, i32 8>
%41 = or <4 x i32> %38, <i32 1, i32 1, i32 1, i32 1>
%42 = or <4 x i32> %40, <i32 1, i32 1, i32 1, i32 1>
%43 = bitcast i32* %37 to <4 x i32>*
store <4 x i32> %41, <4 x i32>* %43
%44 = getelementptr inbounds i32, i32* %37, i64 4
%45 = bitcast i32* %44 to <4 x i32>*
store <4 x i32> %42, <4 x i32>* %45
%46 = add nuw nsw i64 %10, 16
%47 = add <4 x i32> %11, <i32 16, i32 16, i32 16, i32 16>
%48 = add <4 x i32> %12, <i32 16, i32 16, i32 16, i32 16>
br label %9
49: ; preds = %6
%50 = load i32, i32* @EXIT_FAILURE
%51 = tail call i32 @exit(i32 %50)
unreachable
52: ; preds = %9, %52
%53 = phi i64 [ %68, %52 ], [ 0, %9 ]
%54 = getelementptr inbounds i32, i32* %1, i64 %53
%55 = load i32, i32* %54
%56 = zext i32 %55 to i64
%57 = icmp eq i64 %53, %56
%58 = zext i1 %57 to i32
%59 = tail call i32 @assert(i32 %58)
%60 = getelementptr inbounds i32, i32* %7, i64 %53
%61 = load i32, i32* %60
%62 = shl nuw nsw i64 %53, 1
%63 = or i64 %62, 1
%64 = zext i32 %61 to i64
%65 = icmp eq i64 %63, %64
%66 = zext i1 %65 to i32
%67 = tail call i32 @assert(i32 %66)
%68 = add nuw nsw i64 %53, 1
%69 = icmp eq i64 %68, 1000
br i1 %69, label %70, label %52
70: ; preds = %52
%71 = tail call i32* @realloc(i32* %1, i32 8000)
%72 = tail call i32* @realloc(i32* %7, i32 8000)
%73 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %71)
%74 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32* %7, i32* %72)
br label %75
75: ; preds = %70, %75
%76 = phi i64 [ 0, %70 ], [ %91, %75 ]
%77 = getelementptr inbounds i32, i32* %71, i64 %76
%78 = load i32, i32* %77
%79 = zext i32 %78 to i64
%80 = icmp eq i64 %76, %79
%81 = zext i1 %80 to i32
%82 = tail call i32 @assert(i32 %81)
%83 = getelementptr inbounds i32, i32* %72, i64 %76
%84 = load i32, i32* %83
%85 = shl nuw nsw i64 %76, 1
%86 = or i64 %85, 1
%87 = zext i32 %84 to i64
%88 = icmp eq i64 %86, %87
%89 = zext i1 %88 to i32
%90 = tail call i32 @assert(i32 %89)
%91 = add nuw nsw i64 %76, 1
%92 = icmp eq i64 %91, 1000
br i1 %92, label %93, label %75
93: ; preds = %75
%94 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
ret i32 0
}