#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
scalar_t__ realloc(int *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int arraySize, n;
  int *dataPtr;
  int *resizedArray = NULL;
  printf("Enter size of array: ");
  scanf("%d", &arraySize);
  dataPtr = (int *)calloc(arraySize, sizeof(int));
  if (dataPtr == NULL)
    exit(1);
  for (n = 0; n < arraySize; n++) {
    printf("Enter number #%d: ", n + 1);
    scanf("%d", &dataPtr[n]);
  }
  printf("Original Array Contents: \n");
  for (n = 0; n < arraySize; n++)
    printf("%d ", dataPtr[n]);
  printf("\n");
  resizedArray = (int *)realloc(dataPtr, (arraySize / 2) * sizeof(int));
  if (dataPtr != NULL) {
    dataPtr = resizedArray;
    resizedArray = NULL;
  } else {
    free(dataPtr);
    puts("Error reallocating memory");
    exit(1);
  }
  printf("Resized Array Contents: \n");
  for (n = 0; n < (arraySize / 2); n++)
    printf("%d ", dataPtr[n]);
  printf("\n");
  free(dataPtr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe7a(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1080 <scanf@plt>
mov    -0x8(%rbp),%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11cb <main+0x5b>
mov    $0x1,%edi
call   1090 <exit@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    121b <main+0xab>
mov    -0xc(%rbp),%esi
add    $0x1,%esi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe0e(%rip),%rdi
call   1080 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d2 <main+0x62>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1263 <main+0xf3>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1230 <main+0xc0>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cltq
shl    $0x2,%rax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12b1 <main+0x141>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
jmp    12d0 <main+0x160>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xd8a(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    132a <main+0x1ba>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd32(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    12e5 <main+0x175>
lea    0xd4c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe6c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe74(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1090 <scanf@plt>
mov    0xc(%rsp),%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
test   %rax,%rax
je     12d9 <main+0x159>
mov    %rax,%r12
cmpl   $0x0,0xc(%rsp)
jle    1209 <main+0x89>
lea    0xe45(%rip),%r14
lea    0xe3b(%rip),%r15
mov    %r12,%r13
xor    %ebx,%ebx
add    $0x1,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1090 <scanf@plt>
movslq 0xc(%rsp),%rax
add    $0x4,%r13
cmp    %rax,%rbx
jl     11e0 <main+0x60>
lea    0xe20(%rip),%rdi
call   1050 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    124c <main+0xcc>
lea    0xe09(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r12,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1230 <main+0xb0>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    0xc(%rsp),%eax
mov    %eax,%esi
shr    $0x1f,%esi
add    %eax,%esi
add    %esi,%esi
and    $0xfffffffc,%esi
mov    %r12,%rdi
call   1080 <realloc@plt>
mov    %rax,%r15
lea    0xdd2(%rip),%rdi
call   1050 <puts@plt>
cmpl   $0x2,0xc(%rsp)
jl     12b7 <main+0x137>
lea    0xda1(%rip),%r14
xor    %ebx,%ebx
nopl   (%rax)
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
mov    0xc(%rsp),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
movslq %ecx,%rax
cmp    %rax,%rbx
jl     1290 <main+0x110>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    $0x1,%edi
call   10a0 <exit@plt>

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

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