#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 */
float *malloc(int);
int /*<<< orphan*/ printf(char *, int, int, int);
float *slice(float *buf, int n, int start, int end, int *new_n) {
  int i;
  float *new;
  *new_n = n - (start + ((n - 1) - end));
  printf("start=%d end=%d new_n=%d\n", start, end, *new_n);
  new = malloc(sizeof(float) * *new_n);
  for (i = 0; i < *new_n; i++) {
    new[i] = buf[start + i];
  }
  return new;
}


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    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
sub    -0x14(%rbp),%edx
add    %edx,%eax
sub    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jge    11c3 <slice+0xa3>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    -0x24(%rbp),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1187 <slice+0x67>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<slice>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8,%rbx
mov    %edx,%ebp
mov    %rdi,%r14
mov    %ecx,%eax
sub    %edx,%eax
add    $0x1,%eax
mov    %eax,(%r8)
lea    0xeb0(%rip),%rdi
mov    %edx,%esi
mov    %ecx,%edx
mov    %eax,%ecx
call   1030 <printf@plt>
mov    (%rbx),%ebx
lea    0x0(,%rbx,4),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
test   %ebx,%ebx
jle    1186 <slice+0x56>
movslq %ebp,%rax
lea    (%r14,%rax,4),%rsi
shl    $0x2,%rbx
mov    %r15,%rdi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [26 x i8] c"start=%d end=%d new_n=%d\0A\00"
define noalias float* @slice(float* nocapture %0, i32 %1, i32 %2, i32 %3, i32* nocapture %4) {
%6 = add i32 %3, 1
%7 = sub i32 %6, %2
store i32 %7, i32* %4
%8 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %3, i32 %7)
%9 = load i32, i32* %4
%10 = shl i32 %9, 2
%11 = tail call float* @malloc(i32 %10)
%12 = icmp sgt i32 %9, 0
br i1 %12, label %13, label %20
13: ; preds = %5
%14 = bitcast float* %11 to i8*
%15 = sext i32 %2 to i64
%16 = getelementptr float, float* %0, i64 %15
%17 = bitcast float* %16 to i8*
%18 = zext i32 %9 to i64
%19 = shl nuw nsw i64 %18, 2
br label %20
20: ; preds = %13, %5
ret float* %11
}