#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*/ strcpy(char *, char *);
int strlen(char *);
int split_str(int start, int end, char *input, char *output) {
  int len = strlen(input);
  int i, j;
  char buffer[len + 1];
  j = 0;
  for (i = start; i <= end; i++) {
    buffer[j] = input[i];
    j++;
  }
  buffer[j] = '\0';
  strcpy(output, buffer);
  return 0;
}


x86 assembly (clang, -O0):
<split_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11b1 <split_str+0x91>
mov    -0x40(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x20(%rbp),%rdx
mov    (%rcx,%rdx,1),%dl
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1178 <split_str+0x58>
mov    -0x40(%rbp),%rsi
movslq -0x24(%rbp),%rax
movb   $0x0,(%rsi,%rax,1)
mov    -0x18(%rbp),%rdi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_str>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r12
mov    %esi,%r15d
mov    %edi,%r13d
mov    %rdx,%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
sub    %r13d,%r15d
jge    116f <split_str+0x3f>
xor    %eax,%eax
jmp    118a <split_str+0x5a>
movslq %r13d,%rax
add    %rax,%r12
add    $0x1,%r15
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1050 <memcpy@plt>
mov    %r15d,%eax
movb   $0x0,(%rbx,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @split_str(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%14 = load i8*, i8** %7
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %9
%16 = load i32, i32* %9
%17 = add nsw i32 %16, 1
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %12
%20 = alloca i8, i64 %18
store i64 %18, i64* %13
store i32 0, i32* %11
%21 = load i32, i32* %5
store i32 %21, i32* %10
br label %22
22: ; preds = %37, %4
%23 = load i32, i32* %10
%24 = load i32, i32* %6
%25 = icmp sle i32 %23, %24
br i1 %25, label %26, label %40
26: ; preds = %22
%27 = load i8*, i8** %7
%28 = load i32, i32* %10
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = load i32, i32* %11
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %20, i64 %33
store i8 %31, i8* %34
%35 = load i32, i32* %11
%36 = add nsw i32 %35, 1
store i32 %36, i32* %11
br label %37
37: ; preds = %26
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 1
store i32 %39, i32* %10
br label %22
40: ; preds = %22
%41 = load i32, i32* %11
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %20, i64 %42
store i8 0, i8* %43
%44 = load i8*, i8** %8
%45 = call i32 @strcpy(i8* %44, i8* %20)
%46 = load i8*, i8** %12
ret i32 0
}

LLVM IR (-O2):
define i32 @split_str(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = tail call i32 @strlen(i8* %2)
%6 = add nsw i32 %5, 1
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = icmp slt i32 %1, %0
br i1 %9, label %17, label %10
10: ; preds = %4
%11 = sext i32 %0 to i64
%12 = getelementptr i8, i8* %2, i64 %11
%13 = sub i32 %1, %0
%14 = zext i32 %13 to i64
%15 = add nuw nsw i64 %14, 1
%16 = and i64 %15, 4294967295
br label %17
17: ; preds = %10, %4
%18 = phi i64 [ 0, %4 ], [ %16, %10 ]
%19 = getelementptr inbounds i8, i8* %8, i64 %18
store i8 0, i8* %19
%20 = call i32 @strcpy(i8* %3, i8* %8)
ret i32 0
}