#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*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ realloc(int *, int);
int main(void) {
  int n;
  int *arr;
  n = 10;
  arr = (int *)malloc(sizeof(int) * n);
  if (arr == NULL)
    return 0;
  for (int i = 0; i < n; i++) {
    arr[i] = i;
  }
  for (int i = 0; i < n; i++) {
    printf("%d,", arr[i]);
  }
  printf("\n");
  n = 20;
  arr = (int *)realloc(arr, sizeof(int) * n);
  for (int i = 10; i < n; i++) {
    arr[i] = i;
  }
  for (int i = 0; i < n; i++) {
    printf("%d,", arr[i]);
  }
  printf("\n");
  free(arr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x8(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1180 <main+0x40>
movl   $0x0,-0x4(%rbp)
jmp    129c <main+0x15c>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11af <main+0x6f>
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1187 <main+0x47>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e9 <main+0xa9>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b6 <main+0x76>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x14,-0x8(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   1060 <realloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0xa,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1244 <main+0x104>
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    121c <main+0xdc>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    127e <main+0x13e>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    124b <main+0x10b>
lea    0xd7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x28,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1368 <main+0x218>
mov    %rax,%rbx
movaps 0xe8f(%rip),%xmm0
movups %xmm0,(%rax)
movaps 0xe95(%rip),%xmm0
movups %xmm0,0x10(%rax)
movabs $0x900000008,%rax
mov    %rax,0x20(%rbx)
lea    0xeac(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x14(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x1c(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x20(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x24(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
mov    $0x50,%esi
call   1070 <realloc@plt>
mov    %rax,%rbx
movaps 0xdea(%rip),%xmm0
movups %xmm0,0x28(%rax)
movaps 0xdef(%rip),%xmm0
movups %xmm0,0x38(%rax)
movabs $0x1300000012,%rax
mov    %rax,0x48(%rbx)
mov    (%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x14(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x1c(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x20(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x24(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x28(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2c(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x30(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x34(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x38(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x3c(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x40(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x44(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x48(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4c(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d,\00"
@.str.1 = [2 x i8] c"\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
store i32 0, i32* %1
store i32 10, i32* %2
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = mul i64 4, %9
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %3
%14 = load i32*, i32** %3
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %0
store i32 0, i32* %1
br label %87
17: ; preds = %0
store i32 0, i32* %4
br label %18
18: ; preds = %28, %17
%19 = load i32, i32* %4
%20 = load i32, i32* %2
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %31
22: ; preds = %18
%23 = load i32, i32* %4
%24 = load i32*, i32** %3
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
store i32 %23, i32* %27
br label %28
28: ; preds = %22
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %18
31: ; preds = %18
store i32 0, i32* %5
br label %32
32: ; preds = %43, %31
%33 = load i32, i32* %5
%34 = load i32, i32* %2
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %46
36: ; preds = %32
%37 = load i32*, i32** %3
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %36
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %32
46: ; preds = %32
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 20, i32* %2
%48 = load i32*, i32** %3
%49 = load i32, i32* %2
%50 = sext i32 %49 to i64
%51 = mul i64 4, %50
%52 = trunc i64 %51 to i32
%53 = call i64 @realloc(i32* %48, i32 %52)
%54 = inttoptr i64 %53 to i32*
store i32* %54, i32** %3
store i32 10, i32* %6
br label %55
55: ; preds = %65, %46
%56 = load i32, i32* %6
%57 = load i32, i32* %2
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %68
59: ; preds = %55
%60 = load i32, i32* %6
%61 = load i32*, i32** %3
%62 = load i32, i32* %6
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32, i32* %61, i64 %63
store i32 %60, i32* %64
br label %65
65: ; preds = %59
%66 = load i32, i32* %6
%67 = add nsw i32 %66, 1
store i32 %67, i32* %6
br label %55
68: ; preds = %55
store i32 0, i32* %7
br label %69
69: ; preds = %80, %68
%70 = load i32, i32* %7
%71 = load i32, i32* %2
%72 = icmp slt i32 %70, %71
br i1 %72, label %73, label %83
73: ; preds = %69
%74 = load i32*, i32** %3
%75 = load i32, i32* %7
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i32, i32* %74, i64 %76
%78 = load i32, i32* %77
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %78)
br label %80
80: ; preds = %73
%81 = load i32, i32* %7
%82 = add nsw i32 %81, 1
store i32 %82, i32* %7
br label %69
83: ; preds = %69
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%85 = load i32*, i32** %3
%86 = call i32 @free(i32* %85)
store i32 0, i32* %1
br label %87
87: ; preds = %83, %16
%88 = load i32, i32* %1
ret i32 %88
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d,\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 40)
%2 = inttoptr i64 %1 to i32*
%3 = icmp eq i64 %1, 0
br i1 %3, label %101, label %4
4: ; preds = %0
%5 = getelementptr inbounds i32, i32* %2, i64 1
%6 = getelementptr inbounds i32, i32* %2, i64 2
%7 = getelementptr inbounds i32, i32* %2, i64 3
%8 = inttoptr i64 %1 to <4 x i32>*
store <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32>* %8
%9 = getelementptr inbounds i32, i32* %2, i64 4
%10 = getelementptr inbounds i32, i32* %2, i64 5
%11 = getelementptr inbounds i32, i32* %2, i64 6
%12 = getelementptr inbounds i32, i32* %2, i64 7
%13 = bitcast i32* %9 to <4 x i32>*
store <4 x i32> <i32 4, i32 5, i32 6, i32 7>, <4 x i32>* %13
%14 = getelementptr inbounds i32, i32* %2, i64 8
store i32 8, i32* %14
%15 = getelementptr inbounds i32, i32* %2, i64 9
store i32 9, i32* %15
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 0)
%17 = load i32, i32* %5
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %6
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %7
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %9
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %10
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %11
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %12
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %14
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %15
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %33)
%35 = tail call i32 @putchar(i32 10)
%36 = tail call i64 @realloc(i32* %2, i32 80)
%37 = inttoptr i64 %36 to i32*
%38 = getelementptr inbounds i32, i32* %37, i64 10
%39 = getelementptr inbounds i32, i32* %37, i64 11
%40 = getelementptr inbounds i32, i32* %37, i64 12
%41 = getelementptr inbounds i32, i32* %37, i64 13
%42 = bitcast i32* %38 to <4 x i32>*
store <4 x i32> <i32 10, i32 11, i32 12, i32 13>, <4 x i32>* %42
%43 = getelementptr inbounds i32, i32* %37, i64 14
%44 = getelementptr inbounds i32, i32* %37, i64 15
%45 = getelementptr inbounds i32, i32* %37, i64 16
%46 = getelementptr inbounds i32, i32* %37, i64 17
%47 = bitcast i32* %43 to <4 x i32>*
store <4 x i32> <i32 14, i32 15, i32 16, i32 17>, <4 x i32>* %47
%48 = getelementptr inbounds i32, i32* %37, i64 18
store i32 18, i32* %48
%49 = getelementptr inbounds i32, i32* %37, i64 19
store i32 19, i32* %49
%50 = load i32, i32* %37
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %50)
%52 = getelementptr inbounds i32, i32* %37, i64 1
%53 = load i32, i32* %52
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %53)
%55 = getelementptr inbounds i32, i32* %37, i64 2
%56 = load i32, i32* %55
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %56)
%58 = getelementptr inbounds i32, i32* %37, i64 3
%59 = load i32, i32* %58
%60 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %59)
%61 = getelementptr inbounds i32, i32* %37, i64 4
%62 = load i32, i32* %61
%63 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %62)
%64 = getelementptr inbounds i32, i32* %37, i64 5
%65 = load i32, i32* %64
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %65)
%67 = getelementptr inbounds i32, i32* %37, i64 6
%68 = load i32, i32* %67
%69 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %68)
%70 = getelementptr inbounds i32, i32* %37, i64 7
%71 = load i32, i32* %70
%72 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %71)
%73 = getelementptr inbounds i32, i32* %37, i64 8
%74 = load i32, i32* %73
%75 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %74)
%76 = getelementptr inbounds i32, i32* %37, i64 9
%77 = load i32, i32* %76
%78 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %77)
%79 = load i32, i32* %38
%80 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %79)
%81 = load i32, i32* %39
%82 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %81)
%83 = load i32, i32* %40
%84 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %83)
%85 = load i32, i32* %41
%86 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %85)
%87 = load i32, i32* %43
%88 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %87)
%89 = load i32, i32* %44
%90 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %89)
%91 = load i32, i32* %45
%92 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %91)
%93 = load i32, i32* %46
%94 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %93)
%95 = load i32, i32* %48
%96 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %95)
%97 = load i32, i32* %49
%98 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %97)
%99 = tail call i32 @putchar(i32 10)
%100 = tail call i32 @free(i32* %37)
br label %101
101: ; preds = %0, %4
ret i32 0
}