#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);
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);
  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    0xea5(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xeb3(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11d0 <slice+0xc0>
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   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1178 <slice+0x68>
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    0xeda(%rip),%rdi
call   1030 <printf@plt>
lea    0xeee(%rip),%rdi
mov    %ebp,%esi
mov    %r15d,%edx
call   1030 <printf@plt>
cmp    %r15d,%ebp
jg     1176 <slice+0x66>
movslq %ebp,%rax
lea    (%r14,%rax,4),%rbx
sub    %ebp,%r15d
add    $0x1,%r15d
xor    %ebp,%ebp
lea    0xee8(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    (%rbx,%rbp,4),%edx
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
add    $0x1,%rbp
cmp    %ebp,%r15d
jne    1160 <slice+0x50>
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 = [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 = load i32, i32* %5
store i32 %22, i32* %9
br label %23
23: ; preds = %49, %3
%24 = load i32, i32* %9
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
%27 = icmp slt i32 %24, %26
br i1 %27, label %28, label %52
28: ; preds = %23
%29 = load i32*, i32** %4
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = load i32, i32* %9
%35 = load i32, i32* %5
%36 = sub nsw i32 %34, %35
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %15, i64 %37
store i32 %33, i32* %38
%39 = load i32, i32* %9
%40 = load i32, i32* %5
%41 = sub nsw i32 %39, %40
%42 = load i32, i32* %9
%43 = load i32, i32* %5
%44 = sub nsw i32 %42, %43
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %15, i64 %45
%47 = load i32, i32* %46
%48 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %41, i32 %47)
br label %49
49: ; preds = %28
%50 = load i32, i32* %9
%51 = add nsw i32 %50, 1
store i32 %51, i32* %9
br label %23
52: ; preds = %23
%53 = 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 = [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 = icmp sgt i32 %1, %2
br i1 %6, label %20, label %7
7: ; preds = %3
%8 = sext i32 %1 to i64
%9 = add i32 %2, 1
br label %10
10: ; preds = %7, %10
%11 = phi i64 [ %8, %7 ], [ %17, %10 ]
%12 = getelementptr inbounds i32, i32* %0, i64 %11
%13 = load i32, i32* %12
%14 = trunc i64 %11 to i32
%15 = sub i32 %14, %1
%16 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %15, i32 %13)
%17 = add nsw i64 %11, 1
%18 = trunc i64 %17 to i32
%19 = icmp eq i32 %9, %18
br i1 %19, label %20, label %10
20: ; preds = %10, %3
ret void
}