#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 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++) {
    printf("Element[%d] is %d \n", i, array[i]);
  }
}


x86 assembly (clang, -O0):
<slice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xed1(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xedf(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1185 <slice+0x75>
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xece(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114c <slice+0x3c>
add    $0x20,%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     1178 <slice+0x68>
movslq %ebp,%rax
add    $0x1,%r15d
lea    (%r14,%rax,4),%rbx
lea    0xeed(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rbx),%edx
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
add    $0x1,%ebp
add    $0x4,%rbx
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 i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = load i32, i32* %6
%10 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %9)
%11 = load i32, i32* %5
%12 = load i32, i32* %6
%13 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %12)
%14 = load i32, i32* %5
store i32 %14, i32* %7
br label %15
15: ; preds = %28, %3
%16 = load i32, i32* %7
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 1
%19 = icmp slt i32 %16, %18
br i1 %19, label %20, label %31
20: ; preds = %15
%21 = load i32, i32* %7
%22 = load i32*, i32** %4
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %21, i32 %26)
br label %28
28: ; preds = %20
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %15
31: ; preds = %15
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 %19, 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 ], [ %16, %10 ]
%12 = getelementptr inbounds i32, i32* %0, i64 %11
%13 = load i32, i32* %12
%14 = trunc i64 %11 to i32
%15 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 %13)
%16 = add nsw i64 %11, 1
%17 = trunc i64 %16 to i32
%18 = icmp eq i32 %9, %17
br i1 %18, label %19, label %10
19: ; preds = %10, %3
ret void
}