#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*/ del(int *, int, int);
int /*<<< orphan*/ free(int *);
int *init_array(int);
int /*<<< orphan*/ insert(int *, int, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *, ...);
int /*<<< orphan*/ show(int *, int);
int main() {
  int n, *arr;
  int data, pos;
  printf("Enter number of elements: ");
  scanf("%d", &n);
  arr = init_array(n);
  int ch = 0;
  while (ch != 4) {
    printf("\n\n\n1. Insert an element.");
    printf("\n2. Delete an element.");
    printf("\n3. Show elements.");
    printf("\n4. Exit.");
    printf("\n\nEnter your choice (1-4): ");
    scanf("%d", &ch);
    switch (ch) {
    case 1:
      printf("Enter a value and its position: ");
      scanf("%d %d", &data, &pos);
      insert(arr, n, pos, data);
      show(arr, n);
      break;
    case 2:
      printf("Enter position of the item to delete: ");
      scanf("%d", &pos);
      del(arr, n, pos);
      show(arr, n);
      break;
    case 3:
      show(arr, n);
      break;
    case 4:
      break;
    default:
      printf("Invalid Choice!");
    }
  }
  free(arr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
call   1040 <printf@plt>
lea    0xf26(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x8(%rbp),%edi
call   1050 <init_array@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
je     12db <main+0x16b>
lea    0xe6a(%rip),%rdi
call   1040 <printf@plt>
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
lea    0xe87(%rip),%rdi
call   1040 <printf@plt>
lea    0xebb(%rip),%rdi
xor    %eax,%eax
lea    -0x1c(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x3,%eax
ja     12ca <main+0x15a>
mov    -0x28(%rbp),%rax
lea    0xdd8(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
lea    0xe71(%rip),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1080 <insert@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1060 <show@plt>
jmp    12d6 <main+0x166>
lea    0xe3e(%rip),%rdi
call   1040 <printf@plt>
lea    0xe2f(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1090 <del@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1060 <show@plt>
jmp    12d6 <main+0x166>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1060 <show@plt>
jmp    12d6 <main+0x166>
jmp    12d6 <main+0x166>
lea    0xe11(%rip),%rdi
call   1040 <printf@plt>
jmp    11b0 <main+0x40>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe8b(%rip),%rdi
call   1040 <printf@plt>
lea    0xf27(%rip),%r14
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x8(%rsp),%edi
call   1050 <init_array@plt>
mov    %rax,%rbx
movl   $0x0,0xc(%rsp)
lea    0xeb3(%rip),%rbp
lea    0xeb6(%rip),%r15
lea    0xc(%rsp),%r12
lea    0xe32(%rip),%r13
jmp    1212 <main+0xa2>
lea    0xee4(%rip),%rdi
call   1040 <printf@plt>
mov    %r14,%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x8(%rsp),%esi
mov    0x10(%rsp),%edx
mov    %rbx,%rdi
call   1090 <del@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
call   1060 <show@plt>
cmpl   $0x4,0xc(%rsp)
je     12c7 <main+0x157>
lea    0xe12(%rip),%rdi
call   1040 <printf@plt>
lea    0xe1f(%rip),%rdi
call   1040 <printf@plt>
lea    0xe2a(%rip),%rdi
call   1040 <printf@plt>
mov    %rbp,%rdi
call   1040 <printf@plt>
mov    %r15,%rdi
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0xc(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x3,%eax
ja     12b0 <main+0x140>
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
lea    0xe24(%rip),%rdi
call   1040 <printf@plt>
lea    0xe39(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x8(%rsp),%esi
mov    0x10(%rsp),%edx
mov    0x14(%rsp),%ecx
mov    %rbx,%rdi
call   1080 <insert@plt>
jmp    11fb <main+0x8b>
cs nopw 0x0(%rax,%rax,1)
lea    0xe2b(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x4,0xc(%rsp)
jne    1212 <main+0xa2>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Enter number of elements: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [25 x i8] c"\0A\0A\0A1. Insert an element.\00"
@.str.3 = [23 x i8] c"\0A2. Delete an element.\00"
@.str.4 = [19 x i8] c"\0A3. Show elements.\00"
@.str.5 = [10 x i8] c"\0A4. Exit.\00"
@.str.6 = [28 x i8] c"\0A\0AEnter your choice (1-4): \00"
@.str.7 = [33 x i8] c"Enter a value and its position: \00"
@.str.8 = [6 x i8] c"%d %d\00"
@.str.9 = [39 x i8] c"Enter position of the item to delete: \00"
@.str.10 = [16 x i8] c"Invalid Choice!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = call i32* @init_array(i32 %9)
store i32* %10, i32** %3
store i32 0, i32* %6
br label %11
11: ; preds = %50, %0
%12 = load i32, i32* %6
%13 = icmp ne i32 %12, 4
br i1 %13, label %14, label %51
14: ; preds = %11
%15 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%19 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%20 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%21 = load i32, i32* %6
switch i32 %21, label %48 [
i32 1, label %22
i32 2, label %33
i32 3, label %43
i32 4, label %47
]
22: ; preds = %14
%23 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
%24 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32* %4, i32* %5)
%25 = load i32*, i32** %3
%26 = load i32, i32* %2
%27 = load i32, i32* %5
%28 = load i32, i32* %4
%29 = call i32 @insert(i32* %25, i32 %26, i32 %27, i32 %28)
%30 = load i32*, i32** %3
%31 = load i32, i32* %2
%32 = call i32 @show(i32* %30, i32 %31)
br label %50
33: ; preds = %14
%34 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.9, i64 0, i64 0))
%35 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%36 = load i32*, i32** %3
%37 = load i32, i32* %2
%38 = load i32, i32* %5
%39 = call i32 @del(i32* %36, i32 %37, i32 %38)
%40 = load i32*, i32** %3
%41 = load i32, i32* %2
%42 = call i32 @show(i32* %40, i32 %41)
br label %50
43: ; preds = %14
%44 = load i32*, i32** %3
%45 = load i32, i32* %2
%46 = call i32 @show(i32* %44, i32 %45)
br label %50
47: ; preds = %14
br label %50
48: ; preds = %14
%49 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
br label %50
50: ; preds = %48, %47, %43, %33, %22
br label %11
51: ; preds = %11
%52 = load i32*, i32** %3
%53 = call i32 @free(i32* %52)
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"Enter number of elements: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [25 x i8] c"\0A\0A\0A1. Insert an element.\00"
@.str.3 = [23 x i8] c"\0A2. Delete an element.\00"
@.str.4 = [19 x i8] c"\0A3. Show elements.\00"
@.str.5 = [10 x i8] c"\0A4. Exit.\00"
@.str.6 = [28 x i8] c"\0A\0AEnter your choice (1-4): \00"
@.str.7 = [33 x i8] c"Enter a value and its position: \00"
@.str.8 = [6 x i8] c"%d %d\00"
@.str.9 = [39 x i8] c"Enter position of the item to delete: \00"
@.str.10 = [16 x i8] c"Invalid Choice!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%10 = load i32, i32* %1
%11 = call i32* @init_array(i32 %10)
%12 = bitcast i32* %4 to i8*
store i32 0, i32* %4
br label %13
13: ; preds = %0, %43
%14 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%18 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%19 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%20 = load i32, i32* %4
switch i32 %20, label %41 [
i32 1, label %21
i32 2, label %30
i32 3, label %38
i32 4, label %46
]
21: ; preds = %13
%22 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
%23 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32* %2, i32* %3)
%24 = load i32, i32* %1
%25 = load i32, i32* %3
%26 = load i32, i32* %2
%27 = call i32 @insert(i32* %11, i32 %24, i32 %25, i32 %26)
%28 = load i32, i32* %1
%29 = call i32 @show(i32* %11, i32 %28)
br label %43
30: ; preds = %13
%31 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.9, i64 0, i64 0))
%32 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%33 = load i32, i32* %1
%34 = load i32, i32* %3
%35 = call i32 @del(i32* %11, i32 %33, i32 %34)
%36 = load i32, i32* %1
%37 = call i32 @show(i32* %11, i32 %36)
br label %43
38: ; preds = %13
%39 = load i32, i32* %1
%40 = call i32 @show(i32* %11, i32 %39)
br label %43
41: ; preds = %13
%42 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
br label %43
43: ; preds = %41, %38, %30, %21
%44 = load i32, i32* %4
%45 = icmp eq i32 %44, 4
br i1 %45, label %46, label %13
46: ; preds = %13, %43
%47 = call i32 @free(i32* %11)
ret i32 0
}