#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 /*<<< orphan*/ scanf(char *, int *);
int main() {
  int i, n1 = 0, n2 = 0;
  int *a1;
  printf("Enter array size: ");
  scanf("%d", &n1);
  a1 = (int *)malloc(n1 * sizeof(int));
  for (i = 0; i < n1; i++) {
    *(a1 + i) = 55;
  }
  printf("Enter new array size: ");
  scanf("%d", &n2);
  a1 = (int *)realloc(a1, n2 * sizeof(int));
  if (n2 > n1) {
    for (i = n1; i < n2; i++) {
      a1[i] = 0;
    }
  }
  for (i = 0; i < n2; i++)
    printf("%d ", *(a1 + i));
  printf("\n");
  free(a1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe91(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1070 <scanf@plt>
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ce <main+0x7e>
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movl   $0x37,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a5 <main+0x55>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe30(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x18(%rbp),%rdi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   1060 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1243 <main+0xf3>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    123e <main+0xee>
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1215 <main+0xc5>
jmp    1243 <main+0xf3>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    127d <main+0x12d>
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    124a <main+0xfa>
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%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   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xe80(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe85(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1080 <scanf@plt>
mov    0xc(%rsp),%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
cmpl   $0x0,0xc(%rsp)
jle    11c5 <main+0x65>
xor    %eax,%eax
movl   $0x37,(%rbx,%rax,4)
add    $0x1,%rax
movslq 0xc(%rsp),%rcx
cmp    %rcx,%rax
jl     11b0 <main+0x50>
lea    0xe4a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe39(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1080 <scanf@plt>
mov    0x8(%rsp),%esi
shl    $0x2,%esi
mov    %rbx,%rdi
call   1070 <realloc@plt>
mov    %rax,%r15
mov    0x8(%rsp),%ecx
movslq 0xc(%rsp),%rax
cmp    %ecx,%eax
jge    1226 <main+0xc6>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movl   $0x0,(%r15,%rax,4)
add    $0x1,%rax
movslq 0x8(%rsp),%rcx
cmp    %rcx,%rax
jl     1210 <main+0xb0>
test   %ecx,%ecx
jle    125c <main+0xfc>
lea    0xdfc(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
cmp    %rax,%rbx
jl     1240 <main+0xe0>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Enter array size: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"Enter new array size: \00"
@.str.3 = [4 x i8] c"%d \00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 4
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %5
store i32 0, i32* %2
br label %14
14: ; preds = %23, %0
%15 = load i32, i32* %2
%16 = load i32, i32* %3
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %26
18: ; preds = %14
%19 = load i32*, i32** %5
%20 = load i32, i32* %2
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
store i32 55, i32* %22
br label %23
23: ; preds = %18
%24 = load i32, i32* %2
%25 = add nsw i32 %24, 1
store i32 %25, i32* %2
br label %14
26: ; preds = %14
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%29 = load i32*, i32** %5
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = mul i64 %31, 4
%33 = trunc i64 %32 to i32
%34 = call i64 @realloc(i32* %29, i32 %33)
%35 = inttoptr i64 %34 to i32*
store i32* %35, i32** %5
%36 = load i32, i32* %4
%37 = load i32, i32* %3
%38 = icmp sgt i32 %36, %37
br i1 %38, label %39, label %54
39: ; preds = %26
%40 = load i32, i32* %3
store i32 %40, i32* %2
br label %41
41: ; preds = %50, %39
%42 = load i32, i32* %2
%43 = load i32, i32* %4
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %53
45: ; preds = %41
%46 = load i32*, i32** %5
%47 = load i32, i32* %2
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %46, i64 %48
store i32 0, i32* %49
br label %50
50: ; preds = %45
%51 = load i32, i32* %2
%52 = add nsw i32 %51, 1
store i32 %52, i32* %2
br label %41
53: ; preds = %41
br label %54
54: ; preds = %53, %26
store i32 0, i32* %2
br label %55
55: ; preds = %66, %54
%56 = load i32, i32* %2
%57 = load i32, i32* %4
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %69
59: ; preds = %55
%60 = load i32*, i32** %5
%61 = load i32, i32* %2
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %60, i64 %62
%64 = load i32, i32* %63
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %64)
br label %66
66: ; preds = %59
%67 = load i32, i32* %2
%68 = add nsw i32 %67, 1
store i32 %68, i32* %2
br label %55
69: ; preds = %55
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%71 = load i32*, i32** %5
%72 = call i32 @free(i32* %71)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"Enter array size: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"Enter new array size: \00"
@.str.3 = [4 x i8] c"%d \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = shl i32 %7, 2
%9 = call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i32*
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %0, %13
%14 = phi i64 [ %16, %13 ], [ 0, %0 ]
%15 = getelementptr inbounds i32, i32* %10, i64 %14
store i32 55, i32* %15
%16 = add nuw nsw i64 %14, 1
%17 = load i32, i32* %1
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %16, %18
br i1 %19, label %13, label %20
20: ; preds = %13, %0
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%23 = load i32, i32* %2
%24 = shl i32 %23, 2
%25 = call i64 @realloc(i32* %10, i32 %24)
%26 = inttoptr i64 %25 to i32*
%27 = load i32, i32* %2
%28 = load i32, i32* %1
%29 = icmp slt i32 %28, %27
br i1 %29, label %30, label %39
30: ; preds = %20
%31 = sext i32 %28 to i64
br label %32
32: ; preds = %30, %32
%33 = phi i64 [ %31, %30 ], [ %35, %32 ]
%34 = getelementptr inbounds i32, i32* %26, i64 %33
store i32 0, i32* %34
%35 = add nsw i64 %33, 1
%36 = load i32, i32* %2
%37 = sext i32 %36 to i64
%38 = icmp slt i64 %35, %37
br i1 %38, label %32, label %39
39: ; preds = %32, %20
%40 = phi i32 [ %27, %20 ], [ %36, %32 ]
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %51
42: ; preds = %39, %42
%43 = phi i64 [ %47, %42 ], [ 0, %39 ]
%44 = getelementptr inbounds i32, i32* %26, i64 %43
%45 = load i32, i32* %44
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %45)
%47 = add nuw nsw i64 %43, 1
%48 = load i32, i32* %2
%49 = sext i32 %48 to i64
%50 = icmp slt i64 %47, %49
br i1 %50, label %42, label %51
51: ; preds = %42, %39
%52 = call i32 @putchar(i32 10)
%53 = call i32 @free(i32* %26)
ret i32 0
}