#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, char);
int /*<<< orphan*/ puts(char *);
void slice2(char array[], int first, int last) {
  char 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 %c \n", i - first, retarray[i - first]);
  }
}


x86 assembly (clang, -O0):
<slice2>:
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)
mov    %rax,%rdx
add    $0xf,%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),%eax
lea    0xe96(%rip),%rdi
movsbl %al,%edx
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%eax
lea    0xea1(%rip),%rdi
movsbl %al,%edx
call   1040 <printf@plt>
lea    0xeb2(%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    11f2 <slice2+0xd2>
mov    -0x30(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x24(%rbp),%rdx
mov    (%rcx,%rdx,1),%dl
mov    -0x24(%rbp),%ecx
sub    -0xc(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%esi
sub    -0xc(%rbp),%esi
mov    -0x24(%rbp),%ecx
sub    -0xc(%rbp),%ecx
movslq %ecx,%rcx
lea    0xe81(%rip),%rdi
movsbl (%rax,%rcx,1),%edx
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1199 <slice2+0x79>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<slice2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%ebp
mov    %rdi,%r14
movsbl %bl,%r15d
lea    0xec7(%rip),%rdi
mov    %r15d,%edx
call   1040 <printf@plt>
lea    0xed8(%rip),%rdi
mov    %ebp,%esi
mov    %r15d,%edx
call   1040 <printf@plt>
lea    0xee7(%rip),%rdi
call   1030 <puts@plt>
cmp    %ebx,%ebp
jg     1197 <slice2+0x77>
movslq %ebp,%rax
add    %rax,%r14
sub    %ebp,%ebx
add    $0x1,%ebx
xor    %ebp,%ebp
lea    0xee6(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
movsbl (%r14,%rbp,1),%edx
mov    %r15,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %ebp,%ebx
jne    1180 <slice2+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 %c \0A\00"
define void @slice2(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i8* %0, i8** %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 i8, i64 %13
store i64 %13, i64* %8
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = trunc i32 %17 to i8
%19 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %16, i8 signext %18)
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = trunc i32 %21 to i8
%23 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %20, i8 signext %22)
%24 = call i32 @puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* %5
store i32 %25, i32* %9
br label %26
26: ; preds = %52, %3
%27 = load i32, i32* %9
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
%30 = icmp slt i32 %27, %29
br i1 %30, label %31, label %55
31: ; preds = %26
%32 = load i8*, i8** %4
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = load i32, i32* %9
%38 = load i32, i32* %5
%39 = sub nsw i32 %37, %38
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %15, i64 %40
store i8 %36, i8* %41
%42 = load i32, i32* %9
%43 = load i32, i32* %5
%44 = sub nsw i32 %42, %43
%45 = load i32, i32* %9
%46 = load i32, i32* %5
%47 = sub nsw i32 %45, %46
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %15, i64 %48
%50 = load i8, i8* %49
%51 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %44, i8 signext %50)
br label %52
52: ; preds = %31
%53 = load i32, i32* %9
%54 = add nsw i32 %53, 1
store i32 %54, i32* %9
br label %26
55: ; preds = %26
%56 = 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 %c \0A\00"
define void @slice2(i8* nocapture %0, i32 %1, i32 %2) {
%4 = trunc i32 %2 to i8
%5 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %1, i8 signext %4)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %1, i8 signext %4)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp sgt i32 %1, %2
br i1 %8, label %22, label %9
9: ; preds = %3
%10 = sext i32 %1 to i64
%11 = add i32 %2, 1
br label %12
12: ; preds = %9, %12
%13 = phi i64 [ %10, %9 ], [ %19, %12 ]
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = trunc i64 %13 to i32
%17 = sub i32 %16, %1
%18 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %17, i8 signext %15)
%19 = add nsw i64 %13, 1
%20 = trunc i64 %19 to i32
%21 = icmp eq i32 %11, %20
br i1 %21, label %22, label %12
22: ; preds = %12, %3
ret void
}