#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int i, length, number, position;
  printf("Enter the length of the array: ");
  scanf("%d", &length);
  int arr[length + 1];
  printf("Enter %d elements of the array\n", length);
  for (i = 0; i < length; i++)
    scanf("%d", &arr[i]);
  printf("Enter the number and the position to insert: \n");
  scanf("%d %d", &number, &position);
  printf("The initial array: \n{");
  for (i = 0; i < length; i++)
    printf(" %d", arr[i]);
  printf("}\n");
  for (i = length; i >= position; i--)
    arr[i] = arr[i - 1];
  arr[position] = number;
  printf("\nThe final array: \n{");
  for (i = 0; i <= length; i++)
    printf(" %d", arr[i]);
  printf("}\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x31(%rbp)
call   1030 <printf@plt>
mov    -0x31(%rbp),%al
lea    0xf28(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11cc <main+0xac>
mov    -0x30(%rbp),%rsi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1195 <main+0x75>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8e(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1238 <main+0x118>
mov    -0x30(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1205 <main+0xe5>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     127d <main+0x15d>
mov    -0x30(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
movslq -0x8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    124c <main+0x12c>
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%edx
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     12d3 <main+0x1b3>
mov    -0x30(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    12a0 <main+0x180>
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeb8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeed(%rip),%rdi
lea    -0x2c(%rbp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %rsp,%r15
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    -0x2c(%rbp),%esi
lea    0xe97(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    11ce <main+0x9e>
lea    0xea6(%rip),%r14
mov    %r12,%r13
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
add    $0x4,%r13
cmp    %rax,%rbx
jl     11b0 <main+0x80>
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
lea    0xe5f(%rip),%rdi
lea    -0x34(%rbp),%rsi
lea    -0x30(%rbp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xe4f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    122b <main+0xfb>
lea    0xe37(%rip),%r14
xor    %ebx,%ebx
nopl   (%rax)
mov    (%r12,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
cmp    %rax,%rbx
jl     1210 <main+0xe0>
lea    0xe6d(%rip),%rdi
call   1030 <puts@plt>
movslq -0x2c(%rbp),%rcx
movslq -0x30(%rbp),%rax
cmp    %eax,%ecx
jl     12a5 <main+0x175>
mov    %ecx,%edi
sub    %eax,%edi
add    $0x1,%edi
mov    %rcx,%rsi
sub    %rax,%rsi
and    $0x3,%rdi
je     127e <main+0x14e>
cs nopw 0x0(%rax,%rax,1)
lea    -0x1(%rcx),%rdx
mov    -0x4(%r12,%rcx,4),%ebx
mov    %ebx,(%r12,%rcx,4)
mov    %rdx,%rcx
add    $0xffffffffffffffff,%rdi
jne    1260 <main+0x130>
cmp    $0x3,%rsi
jae    1287 <main+0x157>
jmp    12a5 <main+0x175>
mov    %rcx,%rdx
cmp    $0x3,%rsi
jb     12a5 <main+0x175>
add    $0x1,%rdx
nopl   0x0(%rax,%rax,1)
movups -0x14(%r12,%rdx,4),%xmm0
movups %xmm0,-0x10(%r12,%rdx,4)
add    $0xfffffffffffffffc,%rdx
cmp    %rax,%rdx
jg     1290 <main+0x160>
mov    -0x34(%rbp),%ecx
mov    %ecx,(%r12,%rax,4)
lea    0xda9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,-0x2c(%rbp)
js     12ec <main+0x1bc>
mov    $0xffffffffffffffff,%rbx
lea    0xd74(%rip),%r14
xchg   %ax,%ax
mov    0x4(%r12,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movslq -0x2c(%rbp),%rax
add    $0x1,%rbx
cmp    %rax,%rbx
jl     12d0 <main+0x1a0>
lea    0xdac(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Enter the length of the array: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [32 x i8] c"Enter %d elements of the array\0A\00"
@.str.3 = [47 x i8] c"Enter the number and the position to insert: \0A\00"
@.str.4 = [6 x i8] c"%d %d\00"
@.str.5 = [22 x i8] c"The initial array: \0A{\00"
@.str.6 = [4 x i8] c" %d\00"
@.str.7 = [3 x i8] c"}\0A\00"
@.str.8 = [21 x i8] c"\0AThe final array: \0A{\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 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* %3)
%10 = load i32, i32* %3
%11 = add nsw i32 %10, 1
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %6
%14 = alloca i32, i64 %12
store i64 %12, i64* %7
%15 = load i32, i32* %3
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %15)
store i32 0, i32* %2
br label %17
17: ; preds = %26, %0
%18 = load i32, i32* %2
%19 = load i32, i32* %3
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %29
21: ; preds = %17
%22 = load i32, i32* %2
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %14, i64 %23
%25 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %24)
br label %26
26: ; preds = %21
%27 = load i32, i32* %2
%28 = add nsw i32 %27, 1
store i32 %28, i32* %2
br label %17
29: ; preds = %17
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %4, i32* %5)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %2
br label %33
33: ; preds = %43, %29
%34 = load i32, i32* %2
%35 = load i32, i32* %3
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %46
37: ; preds = %33
%38 = load i32, i32* %2
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %14, i64 %39
%41 = load i32, i32* %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %37
%44 = load i32, i32* %2
%45 = add nsw i32 %44, 1
store i32 %45, i32* %2
br label %33
46: ; preds = %33
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%48 = load i32, i32* %3
store i32 %48, i32* %2
br label %49
49: ; preds = %62, %46
%50 = load i32, i32* %2
%51 = load i32, i32* %5
%52 = icmp sge i32 %50, %51
br i1 %52, label %53, label %65
53: ; preds = %49
%54 = load i32, i32* %2
%55 = sub nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %14, i64 %56
%58 = load i32, i32* %57
%59 = load i32, i32* %2
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i32, i32* %14, i64 %60
store i32 %58, i32* %61
br label %62
62: ; preds = %53
%63 = load i32, i32* %2
%64 = add nsw i32 %63, -1
store i32 %64, i32* %2
br label %49
65: ; preds = %49
%66 = load i32, i32* %4
%67 = load i32, i32* %5
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i32, i32* %14, i64 %68
store i32 %66, i32* %69
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %2
br label %71
71: ; preds = %81, %65
%72 = load i32, i32* %2
%73 = load i32, i32* %3
%74 = icmp sle i32 %72, %73
br i1 %74, label %75, label %84
75: ; preds = %71
%76 = load i32, i32* %2
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i32, i32* %14, i64 %77
%79 = load i32, i32* %78
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %79)
br label %81
81: ; preds = %75
%82 = load i32, i32* %2
%83 = add nsw i32 %82, 1
store i32 %83, i32* %2
br label %71
84: ; preds = %71
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%86 = load i8*, i8** %6
%87 = load i32, i32* %1
ret i32 %87
}

LLVM IR (-O2):
@.str = [32 x i8] c"Enter the length of the array: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [32 x i8] c"Enter %d elements of the array\0A\00"
@.str.4 = [6 x i8] c"%d %d\00"
@.str.5 = [22 x i8] c"The initial array: \0A{\00"
@.str.6 = [4 x i8] c" %d\00"
@.str.8 = [21 x i8] c"\0AThe final array: \0A{\00"
@str = [46 x i8] c"Enter the number and the position to insert: \00"
@str.10 = [2 x i8] c"}\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 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* %1)
%9 = load i32, i32* %1
%10 = add nsw i32 %9, 1
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
%13 = alloca i32, i64 %11
%14 = load i32, i32* %1
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %1
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %0, %18
%19 = phi i64 [ %22, %18 ], [ 0, %0 ]
%20 = getelementptr inbounds i32, i32* %13, i64 %19
%21 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %20)
%22 = add nuw nsw i64 %19, 1
%23 = load i32, i32* %1
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %22, %24
br i1 %25, label %18, label %26
26: ; preds = %18, %0
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
%28 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %2, i32* %3)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%30 = load i32, i32* %1
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %41
32: ; preds = %26, %32
%33 = phi i64 [ %37, %32 ], [ 0, %26 ]
%34 = getelementptr inbounds i32, i32* %13, i64 %33
%35 = load i32, i32* %34
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %35)
%37 = add nuw nsw i64 %33, 1
%38 = load i32, i32* %1
%39 = sext i32 %38 to i64
%40 = icmp slt i64 %37, %39
br i1 %40, label %32, label %41
41: ; preds = %32, %26
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.10, i64 0, i64 0))
%43 = load i32, i32* %1
%44 = load i32, i32* %3
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = sext i32 %44 to i64
br label %87
48: ; preds = %41
%49 = sext i32 %43 to i64
%50 = sext i32 %44 to i64
%51 = add nsw i64 %49, 1
%52 = sub nsw i64 %51, %50
%53 = sub nsw i64 %49, %50
%54 = and i64 %52, 3
%55 = icmp eq i64 %54, 0
br i1 %55, label %65, label %56
56: ; preds = %48, %56
%57 = phi i64 [ %59, %56 ], [ %49, %48 ]
%58 = phi i64 [ %63, %56 ], [ 0, %48 ]
%59 = add nsw i64 %57, -1
%60 = getelementptr inbounds i32, i32* %13, i64 %59
%61 = load i32, i32* %60
%62 = getelementptr inbounds i32, i32* %13, i64 %57
store i32 %61, i32* %62
%63 = add i64 %58, 1
%64 = icmp eq i64 %63, %54
br i1 %64, label %65, label %56
65: ; preds = %56, %48
%66 = phi i64 [ %49, %48 ], [ %59, %56 ]
%67 = icmp ult i64 %53, 3
br i1 %67, label %87, label %68
68: ; preds = %65, %68
%69 = phi i64 [ %82, %68 ], [ %66, %65 ]
%70 = add nsw i64 %69, -1
%71 = getelementptr inbounds i32, i32* %13, i64 %70
%72 = load i32, i32* %71
%73 = getelementptr inbounds i32, i32* %13, i64 %69
store i32 %72, i32* %73
%74 = add nsw i64 %69, -2
%75 = getelementptr inbounds i32, i32* %13, i64 %74
%76 = load i32, i32* %75
%77 = getelementptr inbounds i32, i32* %13, i64 %70
store i32 %76, i32* %77
%78 = add nsw i64 %69, -3
%79 = getelementptr inbounds i32, i32* %13, i64 %78
%80 = load i32, i32* %79
%81 = getelementptr inbounds i32, i32* %13, i64 %74
store i32 %80, i32* %81
%82 = add nsw i64 %69, -4
%83 = getelementptr inbounds i32, i32* %13, i64 %82
%84 = load i32, i32* %83
%85 = getelementptr inbounds i32, i32* %13, i64 %78
store i32 %84, i32* %85
%86 = icmp sgt i64 %78, %50
br i1 %86, label %68, label %87
87: ; preds = %65, %68, %46
%88 = phi i64 [ %47, %46 ], [ %50, %68 ], [ %50, %65 ]
%89 = load i32, i32* %2
%90 = getelementptr inbounds i32, i32* %13, i64 %88
store i32 %89, i32* %90
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%92 = load i32, i32* %1
%93 = icmp slt i32 %92, 0
br i1 %93, label %103, label %94
94: ; preds = %87, %94
%95 = phi i64 [ %99, %94 ], [ 0, %87 ]
%96 = getelementptr inbounds i32, i32* %13, i64 %95
%97 = load i32, i32* %96
%98 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %97)
%99 = add nuw nsw i64 %95, 1
%100 = load i32, i32* %1
%101 = sext i32 %100 to i64
%102 = icmp slt i64 %95, %101
br i1 %102, label %94, label %103
103: ; preds = %94, %87
%104 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.10, i64 0, i64 0))
ret i32 0
}