#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *slice(char *s, int start, int end, int BYTES) {
  char *buff = (char *)malloc((end - start) + 2 + BYTES);
  strncpy(buff, s + start, (end - start) + 1);
  *(buff + (end - start) + 1) = '\0';
  return buff;
}


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    %ecx,-0x14(%rbp)
mov    -0x10(%rbp),%edi
sub    -0xc(%rbp),%edi
add    $0x2,%edi
add    -0x14(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0xc(%rbp),%rax
add    %rax,%rsi
mov    -0x10(%rbp),%edx
sub    -0xc(%rbp),%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    -0xc(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,0x1(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<slice>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%r15d
mov    %rdi,%r14
sub    %esi,%ebx
lea    (%rbx,%rcx,1),%edi
add    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,%rbp
movslq %r15d,%rsi
add    %r14,%rsi
lea    0x1(%rbx),%edx
mov    %rax,%rdi
call   1030 <strncpy@plt>
movslq %ebx,%rax
movb   $0x0,0x1(%rbp,%rax,1)
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @slice(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = sub nsw i32 %10, %11
%13 = add nsw i32 %12, 2
%14 = load i32, i32* %8
%15 = add nsw i32 %13, %14
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %9
%18 = load i8*, i8** %9
%19 = load i8*, i8** %5
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i32, i32* %7
%24 = load i32, i32* %6
%25 = sub nsw i32 %23, %24
%26 = add nsw i32 %25, 1
%27 = call i32 @strncpy(i8* %18, i8* %22, i32 %26)
%28 = load i8*, i8** %9
%29 = load i32, i32* %7
%30 = load i32, i32* %6
%31 = sub nsw i32 %29, %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %28, i64 %32
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8 0, i8* %34
%35 = load i8*, i8** %9
ret i8* %35
}

LLVM IR (-O2):
define i8* @slice(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = sub nsw i32 %2, %1
%6 = add nsw i32 %5, 2
%7 = add nsw i32 %6, %3
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = sext i32 %1 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = add nsw i32 %5, 1
%13 = tail call i32 @strncpy(i8* %9, i8* %11, i32 %12)
%14 = sext i32 %5 to i64
%15 = getelementptr inbounds i8, i8* %9, i64 %14
%16 = getelementptr inbounds i8, i8* %15, i64 1
store i8 0, i8* %16
ret i8* %9
}