#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
char *strdup(char const *);
char *sliced_string(const char *str, int start, int end) {
  if (start >= end) {
    printf("start index must be smaller than end index while slicing\n");
    exit(EXIT_FAILURE);
  }
  char *s = strdup(str);
  s += start;
  *(s + (end - start)) = '\0';
  return s;
}


x86 assembly (clang, -O0):
<sliced_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jl     1168 <sliced_string+0x38>
lea    0xeab(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    -0xc(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sliced_string>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebx
sub    %esi,%ebx
jle    1154 <sliced_string+0x24>
mov    %esi,%ebp
call   1050 <strdup@plt>
movslq %ebp,%rcx
add    %rcx,%rax
movslq %ebx,%rcx
movb   $0x0,(%rcx,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [58 x i8] c"start index must be smaller than end index while slicing\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @sliced_string(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = load i32, i32* %6
%10 = icmp sge i32 %8, %9
br i1 %10, label %11, label %15
11: ; preds = %3
%12 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %3
%16 = load i8*, i8** %4
%17 = call i8* @strdup(i8* %16)
store i8* %17, i8** %7
%18 = load i32, i32* %5
%19 = load i8*, i8** %7
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds i8, i8* %19, i64 %20
store i8* %21, i8** %7
%22 = load i8*, i8** %7
%23 = load i32, i32* %6
%24 = load i32, i32* %5
%25 = sub nsw i32 %23, %24
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %22, i64 %26
store i8 0, i8* %27
%28 = load i8*, i8** %7
ret i8* %28
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@str = [57 x i8] c"start index must be smaller than end index while slicing\00"
define noalias i8* @sliced_string(i8* nocapture %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %2, %1
br i1 %4, label %9, label %5
5: ; preds = %3
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %3
%10 = tail call i8* @strdup(i8* %0)
%11 = sext i32 %1 to i64
%12 = getelementptr inbounds i8, i8* %10, i64 %11
%13 = sub nsw i32 %2, %1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
store i8 0, i8* %15
ret i8* %12
}