#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__ moveArray(int *, int, int);
scalar_t__ moveArrayWithExtraMem(int *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, const char *argv[]) {
  int array[100] = {0};
  int array2[100] = {0};
  int amount, offset;
  printf("Input the amount of array: ");
  scanf("%d", &amount);
  printf("\n");
  printf("Input the offset to move: ");
  scanf("%d", &offset);
  printf("\n");
  printf("Input the array: ");
  for (int i = 0; i < amount; ++i) {
    scanf("%d", array + i);
  }
  printf("\n");
  for (int i = 0; i < amount; ++i) {
    array2[i] = array[i];
  }
  if (moveArray(array, amount, offset) == 0) {
    printf("Move array without extra memory: \n");
    for (int i = 0; i < amount; ++i) {
      printf("%d ", array[i]);
    }
    printf("\n");
  } else {
    printf("Input invalid\n");
  }
  if (moveArrayWithExtraMem(array2, amount, offset) == 0) {
    printf("Move array with extra memory: \n");
    for (int i = 0; i < amount; ++i) {
      printf("%d ", array2[i]);
    }
    printf("\n");
  } else {
    printf("Input invalid 2\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x190,%edx
call   1050 <memset@plt>
lea    -0x330(%rbp),%rdi
xor    %esi,%esi
mov    $0x190,%edx
call   1050 <memset@plt>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe78(%rip),%rdi
lea    -0x334(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xee9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe49(%rip),%rdi
lea    -0x338(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x33c(%rbp)
mov    -0x33c(%rbp),%eax
cmp    -0x334(%rbp),%eax
jge    124c <main+0xfc>
lea    -0x1a0(%rbp),%rsi
movslq -0x33c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xde9(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x33c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x33c(%rbp)
jmp    1205 <main+0xb5>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x340(%rbp)
mov    -0x340(%rbp),%eax
cmp    -0x334(%rbp),%eax
jge    12a6 <main+0x156>
movslq -0x340(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%ecx
movslq -0x340(%rbp),%rax
mov    %ecx,-0x330(%rbp,%rax,4)
mov    -0x340(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x340(%rbp)
jmp    1264 <main+0x114>
lea    -0x1a0(%rbp),%rdi
mov    -0x334(%rbp),%esi
mov    -0x338(%rbp),%edx
call   1070 <moveArray@plt>
cmp    $0x0,%rax
jne    1335 <main+0x1e5>
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x344(%rbp)
mov    -0x344(%rbp),%eax
cmp    -0x334(%rbp),%eax
jge    1322 <main+0x1d2>
movslq -0x344(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%esi
lea    0xd68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x344(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x344(%rbp)
jmp    12e0 <main+0x190>
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1343 <main+0x1f3>
lea    0xd37(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x330(%rbp),%rdi
mov    -0x334(%rbp),%esi
mov    -0x338(%rbp),%edx
call   1030 <moveArrayWithExtraMem@plt>
cmp    $0x0,%rax
jne    13d2 <main+0x282>
lea    0xd16(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x348(%rbp)
mov    -0x348(%rbp),%eax
cmp    -0x334(%rbp),%eax
jge    13bf <main+0x26f>
movslq -0x348(%rbp),%rax
mov    -0x330(%rbp,%rax,4),%esi
lea    0xccb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x348(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x348(%rbp)
jmp    137d <main+0x22d>
lea    0xcda(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    13e0 <main+0x290>
lea    0xcc9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x330,%rsp
lea    0x1a0(%rsp),%r15
mov    $0x190,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
lea    0x10(%rsp),%rdi
mov    $0x190,%edx
xor    %esi,%esi
call   1070 <memset@plt>
lea    0xe45(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe53(%rip),%r14
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1090 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe38(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xc(%rsp),%rsi
mov    %r14,%rdi
call   1090 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe2e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmpl   $0x0,0x8(%rsp)
jle    124d <main+0xcd>
xor    %ebx,%ebx
lea    0xdf9(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1090 <scanf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     1230 <main+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%ebx
test   %ebx,%ebx
jle    1279 <main+0xf9>
lea    0x0(,%rbx,4),%rdx
lea    0x10(%rsp),%rdi
lea    0x1a0(%rsp),%rsi
call   1080 <memcpy@plt>
mov    0xc(%rsp),%edx
lea    0x1a0(%rsp),%rdi
mov    %ebx,%esi
call   10a0 <moveArray@plt>
test   %rax,%rax
je     129f <main+0x11f>
lea    0xdb8(%rip),%rdi
call   1040 <puts@plt>
jmp    12e9 <main+0x169>
lea    0xde7(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,0x8(%rsp)
jle    12df <main+0x15f>
lea    0xd93(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    0x1a0(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
cmp    %rax,%rbx
jl     12c0 <main+0x140>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0x10(%rsp),%rdi
call   1050 <moveArrayWithExtraMem@plt>
test   %rax,%rax
je     130e <main+0x18e>
lea    0xd57(%rip),%rdi
call   1040 <puts@plt>
jmp    1356 <main+0x1d6>
lea    0xd59(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,0x8(%rsp)
jle    134c <main+0x1cc>
lea    0xd24(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
cmp    %rax,%rbx
jl     1330 <main+0x1b0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x330,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Input the amount of array: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [27 x i8] c"Input the offset to move: \00"
@.str.4 = [18 x i8] c"Input the array: \00"
@.str.5 = [35 x i8] c"Move array without extra memory: \0A\00"
@.str.6 = [4 x i8] c"%d \00"
@.str.7 = [15 x i8] c"Input invalid\0A\00"
@.str.8 = [32 x i8] c"Move array with extra memory: \0A\00"
@.str.9 = [17 x i8] c"Input invalid 2\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i32]
%7 = alloca [100 x i32]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = bitcast [100 x i32]* %6 to i8*
%15 = bitcast [100 x i32]* %7 to i8*
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %9)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %10
br label %23
23: ; preds = %33, %2
%24 = load i32, i32* %10
%25 = load i32, i32* %8
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %36
27: ; preds = %23
%28 = getelementptr inbounds [100 x i32], [100 x i32]* %6, i64 0, i64 0
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %31)
br label %33
33: ; preds = %27
%34 = load i32, i32* %10
%35 = add nsw i32 %34, 1
store i32 %35, i32* %10
br label %23
36: ; preds = %23
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %11
br label %38
38: ; preds = %50, %36
%39 = load i32, i32* %11
%40 = load i32, i32* %8
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %53
42: ; preds = %38
%43 = load i32, i32* %11
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [100 x i32], [100 x i32]* %6, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = load i32, i32* %11
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [100 x i32], [100 x i32]* %7, i64 0, i64 %48
store i32 %46, i32* %49
br label %50
50: ; preds = %42
%51 = load i32, i32* %11
%52 = add nsw i32 %51, 1
store i32 %52, i32* %11
br label %38
53: ; preds = %38
%54 = getelementptr inbounds [100 x i32], [100 x i32]* %6, i64 0, i64 0
%55 = load i32, i32* %8
%56 = load i32, i32* %9
%57 = call i64 @moveArray(i32* %54, i32 %55, i32 %56)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %76
59: ; preds = %53
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %12
br label %61
61: ; preds = %71, %59
%62 = load i32, i32* %12
%63 = load i32, i32* %8
%64 = icmp slt i32 %62, %63
br i1 %64, label %65, label %74
65: ; preds = %61
%66 = load i32, i32* %12
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [100 x i32], [100 x i32]* %6, i64 0, i64 %67
%69 = load i32, i32* %68
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %69)
br label %71
71: ; preds = %65
%72 = load i32, i32* %12
%73 = add nsw i32 %72, 1
store i32 %73, i32* %12
br label %61
74: ; preds = %61
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %78
76: ; preds = %53
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
br label %78
78: ; preds = %76, %74
%79 = getelementptr inbounds [100 x i32], [100 x i32]* %7, i64 0, i64 0
%80 = load i32, i32* %8
%81 = load i32, i32* %9
%82 = call i64 @moveArrayWithExtraMem(i32* %79, i32 %80, i32 %81)
%83 = icmp eq i64 %82, 0
br i1 %83, label %84, label %101
84: ; preds = %78
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %13
br label %86
86: ; preds = %96, %84
%87 = load i32, i32* %13
%88 = load i32, i32* %8
%89 = icmp slt i32 %87, %88
br i1 %89, label %90, label %99
90: ; preds = %86
%91 = load i32, i32* %13
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds [100 x i32], [100 x i32]* %7, i64 0, i64 %92
%94 = load i32, i32* %93
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %94)
br label %96
96: ; preds = %90
%97 = load i32, i32* %13
%98 = add nsw i32 %97, 1
store i32 %98, i32* %13
br label %86
99: ; preds = %86
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %103
101: ; preds = %78
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
br label %103
103: ; preds = %101, %99
ret i32 0
}

LLVM IR (-O2):
@.str = [28 x i8] c"Input the amount of array: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [27 x i8] c"Input the offset to move: \00"
@.str.4 = [18 x i8] c"Input the array: \00"
@.str.6 = [4 x i8] c"%d \00"
@str = [14 x i8] c"Input invalid\00"
@str.10 = [16 x i8] c"Input invalid 2\00"
@str.11 = [31 x i8] c"Move array with extra memory: \00"
@str.12 = [34 x i8] c"Move array without extra memory: \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [100 x i32]
%4 = bitcast [100 x i32]* %3 to i8*
%5 = alloca [100 x i32]
%6 = bitcast [100 x i32]* %5 to i8*
%7 = alloca i32
%8 = alloca i32
%9 = bitcast i32* %7 to i8*
%10 = bitcast i32* %8 to i8*
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%13 = call i32 @putchar(i32 10)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%16 = call i32 @putchar(i32 10)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%18 = load i32, i32* %7
%19 = icmp sgt i32 %18, 0
br i1 %19, label %27, label %20
20: ; preds = %27, %2
%21 = call i32 @putchar(i32 10)
%22 = load i32, i32* %7
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %35
24: ; preds = %20
%25 = zext i32 %22 to i64
%26 = shl nuw nsw i64 %25, 2
br label %35
27: ; preds = %2, %27
%28 = phi i64 [ %31, %27 ], [ 0, %2 ]
%29 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %28
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %29)
%31 = add nuw nsw i64 %28, 1
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = icmp slt i64 %31, %33
br i1 %34, label %27, label %20
35: ; preds = %24, %20
%36 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%37 = load i32, i32* %8
%38 = call i64 @moveArray(i32* %36, i32 %22, i32 %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %55
40: ; preds = %35
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.12, i64 0, i64 0))
%42 = load i32, i32* %7
%43 = icmp sgt i32 %42, 0
br i1 %43, label %46, label %44
44: ; preds = %46, %40
%45 = call i32 @putchar(i32 10)
br label %57
46: ; preds = %40, %46
%47 = phi i64 [ %51, %46 ], [ 0, %40 ]
%48 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %47
%49 = load i32, i32* %48
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %49)
%51 = add nuw nsw i64 %47, 1
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = icmp slt i64 %51, %53
br i1 %54, label %46, label %44
55: ; preds = %35
%56 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %57
57: ; preds = %55, %44
%58 = getelementptr inbounds [100 x i32], [100 x i32]* %5, i64 0, i64 0
%59 = load i32, i32* %7
%60 = load i32, i32* %8
%61 = call i64 @moveArrayWithExtraMem(i32* %58, i32 %59, i32 %60)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %78
63: ; preds = %57
%64 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.11, i64 0, i64 0))
%65 = load i32, i32* %7
%66 = icmp sgt i32 %65, 0
br i1 %66, label %69, label %67
67: ; preds = %69, %63
%68 = call i32 @putchar(i32 10)
br label %80
69: ; preds = %63, %69
%70 = phi i64 [ %74, %69 ], [ 0, %63 ]
%71 = getelementptr inbounds [100 x i32], [100 x i32]* %5, i64 0, i64 %70
%72 = load i32, i32* %71
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %72)
%74 = add nuw nsw i64 %70, 1
%75 = load i32, i32* %7
%76 = sext i32 %75 to i64
%77 = icmp slt i64 %74, %76
br i1 %77, label %69, label %67
78: ; preds = %57
%79 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.10, i64 0, i64 0))
br label %80
80: ; preds = %78, %67
ret i32 0
}