#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 */
typedef scalar_t__ int32_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
char *malloc(scalar_t__);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, scalar_t__);
char *str_slice(char *str, int32_t start, int32_t end) {
  char *ret;
  int32_t len;
  len = strlen(str);
  assert(end > start);
  assert(start >= 0);
  assert(end <= len);
  ret = malloc((1 + end - start) * sizeof(*ret));
  strncpy(ret, str + start, end - start);
  return ret;
}


x86 assembly (clang, -O0):
<str_slice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
sub    -0x10(%rbp),%rdi
shl    $0x0,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
sub    -0x10(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_slice>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %rax,%r13
xor    %edi,%edi
mov    %r12,%rbp
sub    %r14,%rbp
setg   %dil
call   1050 <assert@plt>
mov    %r14,%rdi
shr    $0x3f,%rdi
xor    $0x1,%edi
call   1050 <assert@plt>
xor    %edi,%edi
cmp    %r12,%r13
setge  %dil
call   1050 <assert@plt>
lea    0x1(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
add    %r14,%r15
mov    %rax,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1030 <strncpy@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @str_slice(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %8
%11 = load i64, i64* %6
%12 = load i64, i64* %5
%13 = icmp sgt i64 %11, %12
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i64, i64* %5
%17 = icmp sge i64 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i64, i64* %6
%21 = load i64, i64* %8
%22 = icmp sle i64 %20, %21
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i64, i64* %6
%26 = add nsw i64 1, %25
%27 = load i64, i64* %5
%28 = sub nsw i64 %26, %27
%29 = mul i64 %28, 1
%30 = call i8* @malloc(i64 %29)
store i8* %30, i8** %7
%31 = load i8*, i8** %7
%32 = load i8*, i8** %4
%33 = load i64, i64* %5
%34 = getelementptr inbounds i8, i8* %32, i64 %33
%35 = load i64, i64* %6
%36 = load i64, i64* %5
%37 = sub nsw i64 %35, %36
%38 = call i32 @strncpy(i8* %31, i8* %34, i64 %37)
%39 = load i8*, i8** %7
ret i8* %39
}

LLVM IR (-O2):
define i8* @str_slice(i8* %0, i64 %1, i64 %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = icmp sgt i64 %2, %1
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = lshr i64 %1, 63
%9 = trunc i64 %8 to i32
%10 = xor i32 %9, 1
%11 = tail call i32 @assert(i32 %10)
%12 = icmp sge i64 %4, %2
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = sub i64 1, %1
%16 = add i64 %15, %2
%17 = tail call i8* @malloc(i64 %16)
%18 = getelementptr inbounds i8, i8* %0, i64 %1
%19 = sub nsw i64 %2, %1
%20 = tail call i32 @strncpy(i8* %17, i8* %18, i64 %19)
ret i8* %17
}