#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, int);
int /*<<< orphan*/ puts(char *);
void slice(int array[], int first, int last) {
  int retarray[last - first];
  int i;
  printf("Getting slice[%d:%d] of array \n", first, last);
  printf("(Elements %d to %d of array.) \n", first, last);
  puts("Here is the slice array... ");
  for (i = first; i < last + 1; i++) {
    retarray[i - first] = array[i];
    printf("Element[%d] is %d \n", i - first, retarray[i - first]);
  }
}


x86 assembly (clang, -O0):
<slice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    %ecx,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xea3(%rip),%rdi
call   1040 <printf@plt>
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11ec <slice+0xcc>
mov    -0x30(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x24(%rbp),%rdx
mov    (%rcx,%rdx,4),%edx
mov    -0x24(%rbp),%ecx
sub    -0xc(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%esi
sub    -0xc(%rbp),%esi
mov    -0x24(%rbp),%ecx
sub    -0xc(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe83(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1194 <slice+0x74>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<slice>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xeca(%rip),%rdi
call   1040 <printf@plt>
lea    0xede(%rip),%rdi
mov    %ebp,%esi
mov    %r15d,%edx
call   1040 <printf@plt>
lea    0xeed(%rip),%rdi
call   1030 <puts@plt>
cmp    %r15d,%ebp
jg     1196 <slice+0x76>
movslq %ebp,%rax
lea    (%r14,%rax,4),%rbx
sub    %ebp,%r15d
add    $0x1,%r15d
xor    %ebp,%ebp
lea    0xee8(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rbx,%rbp,4),%edx
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %ebp,%r15d
jne    1180 <slice+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Getting slice[%d:%d] of array \0A\00"
@.str.1 = [32 x i8] c"(Elements %d to %d of array.) \0A\00"
@.str.2 = [28 x i8] c"Here is the slice array... \00"
@.str.3 = [20 x i8] c"Element[%d] is %d \0A\00"
define void @slice(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %6
%11 = load i32, i32* %5
%12 = sub nsw i32 %10, %11
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %7
%15 = alloca i32, i64 %13
store i64 %13, i64* %8
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %17)
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %20)
%22 = call i32 @puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* %5
store i32 %23, i32* %9
br label %24
24: ; preds = %50, %3
%25 = load i32, i32* %9
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
%28 = icmp slt i32 %25, %27
br i1 %28, label %29, label %53
29: ; preds = %24
%30 = load i32*, i32** %4
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32, i32* %33
%35 = load i32, i32* %9
%36 = load i32, i32* %5
%37 = sub nsw i32 %35, %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %15, i64 %38
store i32 %34, i32* %39
%40 = load i32, i32* %9
%41 = load i32, i32* %5
%42 = sub nsw i32 %40, %41
%43 = load i32, i32* %9
%44 = load i32, i32* %5
%45 = sub nsw i32 %43, %44
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %15, i64 %46
%48 = load i32, i32* %47
%49 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %42, i32 %48)
br label %50
50: ; preds = %29
%51 = load i32, i32* %9
%52 = add nsw i32 %51, 1
store i32 %52, i32* %9
br label %24
53: ; preds = %24
%54 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
@.str = [32 x i8] c"Getting slice[%d:%d] of array \0A\00"
@.str.1 = [32 x i8] c"(Elements %d to %d of array.) \0A\00"
@.str.2 = [28 x i8] c"Here is the slice array... \00"
@.str.3 = [20 x i8] c"Element[%d] is %d \0A\00"
define void @slice(i32* nocapture %0, i32 %1, i32 %2) {
%4 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 %2)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%7 = icmp sgt i32 %1, %2
br i1 %7, label %21, label %8
8: ; preds = %3
%9 = sext i32 %1 to i64
%10 = add i32 %2, 1
br label %11
11: ; preds = %8, %11
%12 = phi i64 [ %9, %8 ], [ %18, %11 ]
%13 = getelementptr inbounds i32, i32* %0, i64 %12
%14 = load i32, i32* %13
%15 = trunc i64 %12 to i32
%16 = sub i32 %15, %1
%17 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %16, i32 %14)
%18 = add nsw i64 %12, 1
%19 = trunc i64 %18 to i32
%20 = icmp eq i32 %10, %19
br i1 %20, label %21, label %11
21: ; preds = %11, %3
ret void
}