#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(int /*<<< orphan*/);
int /*<<< orphan*/ getchar();
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ realloc(int *, int);
int /*<<< orphan*/ scanf(char *, ...);
void main(void) {
  int range = 16;
  int *a = (int *)malloc(2 * sizeof(int));
  int i, counter, size;
  char command = 'i';
  counter = i = 0;
  size = 2;
  while (1) {
    printf("Enter the Command:\n");
    scanf("%c", &command);
    switch (command) {
    case 'i':
      if (counter < size) {
        printf("Enter The Element:\n");
        scanf("%d", a + counter);
        counter++;
      } else {
        size = size * 2;
        printf("New Size is: %d\n", size);
        a = (int *)realloc(a, size * sizeof(int));
        if (a == NULL) {
          printf("No Enough Memory in The Segment ! \n");
        } else {
          printf("Enter The Element(size changed %d):\n", size);
          scanf("%d", a + counter);
          counter++;
        }
      }
      break;
    case 's':
      for (i = 0; i < counter; ++i) {
        printf("%d\n", a[i]);
      }
      break;
    case 'q':
      exit(0);
      break;
    default:;
    }
    getchar();
  }
  return;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x10,-0x4(%rbp)
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movb   $0x69,-0x1d(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x2,-0x1c(%rbp)
lea    0xe63(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x25(%rbp)
call   1030 <printf@plt>
mov    -0x25(%rbp),%al
lea    0xe63(%rip),%rdi
lea    -0x1d(%rbp),%rsi
call   1070 <scanf@plt>
movsbl -0x1d(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x69,%eax
je     11f1 <main+0x91>
jmp    11cf <main+0x6f>
mov    -0x24(%rbp),%eax
sub    $0x71,%eax
je     1305 <main+0x1a5>
jmp    11e0 <main+0x80>
mov    -0x24(%rbp),%eax
sub    $0x73,%eax
je     12c6 <main+0x166>
jmp    130c <main+0x1ac>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1236 <main+0xd6>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12c1 <main+0x161>
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   1060 <realloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1285 <main+0x125>
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12bc <main+0x15c>
mov    -0x1c(%rbp),%esi
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xd7f(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12c1 <main+0x161>
jmp    1311 <main+0x1b1>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1300 <main+0x1a0>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12cd <main+0x16d>
jmp    1311 <main+0x1b1>
xor    %edi,%edi
call   1080 <exit@plt>
jmp    1311 <main+0x1b1>
mov    $0x0,%al
call   1040 <getchar@plt>
jmp    1196 <main+0x36>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
movb   $0x69,0xf(%rsp)
mov    $0x2,%eax
mov    %rax,0x10(%rsp)
lea    0xe9b(%rip),%r14
lea    0xe58(%rip),%rbp
lea    0xf(%rsp),%rbx
lea    0xe5f(%rip),%r13
xor    %r15d,%r15d
jmp    11d0 <main+0x60>
nopl   0x0(%rax)
cmp    $0x71,%eax
je     12e5 <main+0x175>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
movsbl 0xf(%rsp),%eax
cmp    $0x69,%eax
je     1230 <main+0xc0>
cmp    $0x73,%eax
jne    11c0 <main+0x50>
test   %r15d,%r15d
jle    11c9 <main+0x59>
mov    %r15d,%ebx
xor    %ebp,%ebp
xchg   %ax,%ax
mov    (%r12,%rbp,4),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1200 <main+0x90>
lea    0xde2(%rip),%rbp
lea    0xf(%rsp),%rbx
jmp    11c9 <main+0x59>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x10(%rsp),%rax
cmp    %eax,%r15d
jge    1264 <main+0xf4>
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
movslq %r15d,%rax
lea    (%r12,%rax,4),%rsi
lea    0xdaf(%rip),%rdi
xor    %eax,%eax
call   1080 <scanf@plt>
add    $0x1,%r15d
jmp    11c9 <main+0x59>
lea    (%rax,%rax,1),%r14d
lea    0xd97(%rip),%rdi
mov    %rax,%rbx
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
shl    $0x3,%ebx
mov    %r12,%rdi
mov    %ebx,%esi
call   1070 <realloc@plt>
test   %rax,%rax
je     12bd <main+0x14d>
mov    %rax,%r12
lea    0xd7f(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movslq %r15d,%rax
lea    (%r12,%rax,4),%rsi
lea    0xd53(%rip),%rdi
xor    %eax,%eax
call   1080 <scanf@plt>
add    $0x1,%r15d
jmp    12cc <main+0x15c>
lea    0xd8b(%rip),%rdi
call   1030 <puts@plt>
xor    %r12d,%r12d
mov    %r14d,%eax
mov    %rax,0x10(%rsp)
lea    0xd61(%rip),%r14
lea    0xf(%rsp),%rbx
jmp    11c9 <main+0x59>
xor    %edi,%edi
call   1090 <exit@plt>

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

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%c\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [17 x i8] c"New Size is: %d\0A\00"
@.str.6 = [37 x i8] c"Enter The Element(size changed %d):\0A\00"
@.str.7 = [4 x i8] c"%d\0A\00"
@str = [19 x i8] c"Enter the Command:\00"
@str.8 = [35 x i8] c"No Enough Memory in The Segment ! \00"
@str.9 = [19 x i8] c"Enter The Element:\00"
define void @main() {
%1 = alloca i8
%2 = tail call i64 @malloc(i32 8)
%3 = inttoptr i64 %2 to i32*
store i8 105, i8* %1
br label %4
4: ; preds = %48, %0
%5 = phi i32* [ %3, %0 ], [ %49, %48 ]
%6 = phi i32 [ 0, %0 ], [ %50, %48 ]
%7 = phi i32 [ 2, %0 ], [ %51, %48 ]
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%10 = load i8, i8* %1
%11 = sext i8 %10 to i32
switch i32 %11, label %48 [
i32 105, label %16
i32 115, label %12
i32 113, label %46
]
12: ; preds = %4
%13 = icmp sgt i32 %6, 0
br i1 %13, label %14, label %48
14: ; preds = %12
%15 = zext i32 %6 to i64
br label %39
16: ; preds = %4
%17 = icmp slt i32 %6, %7
br i1 %17, label %18, label %24
18: ; preds = %16
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.9, i64 0, i64 0))
%20 = sext i32 %6 to i64
%21 = getelementptr inbounds i32, i32* %5, i64 %20
%22 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %21)
%23 = add nsw i32 %6, 1
br label %48
24: ; preds = %16
%25 = shl nsw i32 %7, 1
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%27 = shl i32 %7, 3
%28 = call i64 @realloc(i32* %5, i32 %27)
%29 = inttoptr i64 %28 to i32*
%30 = icmp eq i64 %28, 0
br i1 %30, label %31, label %33
31: ; preds = %24
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.8, i64 0, i64 0))
br label %48
33: ; preds = %24
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0), i32 %25)
%35 = sext i32 %6 to i64
%36 = getelementptr inbounds i32, i32* %29, i64 %35
%37 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %36)
%38 = add nsw i32 %6, 1
br label %48
39: ; preds = %14, %39
%40 = phi i64 [ 0, %14 ], [ %44, %39 ]
%41 = getelementptr inbounds i32, i32* %5, i64 %40
%42 = load i32, i32* %41
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %42)
%44 = add nuw nsw i64 %40, 1
%45 = icmp eq i64 %44, %15
br i1 %45, label %48, label %39
46: ; preds = %4
%47 = call i32 @exit(i32 0)
unreachable
48: ; preds = %39, %12, %4, %18, %33, %31
%49 = phi i32* [ %5, %4 ], [ %5, %18 ], [ null, %31 ], [ %29, %33 ], [ %5, %12 ], [ %5, %39 ]
%50 = phi i32 [ %6, %4 ], [ %23, %18 ], [ %6, %31 ], [ %38, %33 ], [ %6, %12 ], [ %6, %39 ]
%51 = phi i32 [ %7, %4 ], [ %7, %18 ], [ %25, %31 ], [ %25, %33 ], [ %7, %12 ], [ %7, %39 ]
%52 = call i32 (...) @getchar()
br label %4
}