#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 */
unsigned int strlen(char *);
int IndexCopy(char *sin, char *sout, unsigned int start, unsigned int stop) {
  unsigned int i, j = 0;
  sout[0] = '\0';
  if (strlen(sin) < stop)
    return (0);
  for (i = start; i <= stop; i++) {
    sout[j] = sin[i];
    j++;
    sout[j] = '\0';
  }
  return (1);
}


x86 assembly (clang, -O0):
<IndexCopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    -0x20(%rbp),%eax
jae    1152 <IndexCopy+0x42>
movl   $0x0,-0x4(%rbp)
jmp    11a1 <IndexCopy+0x91>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
ja     119a <IndexCopy+0x8a>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1158 <IndexCopy+0x48>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IndexCopy>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r12d
mov    %edx,%r15d
mov    %rsi,%rbp
mov    %rdi,%r14
movb   $0x0,(%rsi)
call   1030 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %r12d,%ecx
jb     116f <IndexCopy+0x5f>
mov    $0x1,%eax
cmp    %r12d,%r15d
ja     116f <IndexCopy+0x5f>
mov    %r15d,%ecx
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%rcx,%rdx,1),%esi
movzbl (%r14,%rsi,1),%ebx
mov    %bl,0x0(%rbp,%rdx,1)
add    $0x1,%rdx
mov    %edx,%esi
movb   $0x0,0x0(%rbp,%rsi,1)
lea    (%rcx,%rdx,1),%esi
cmp    %r12d,%esi
jbe    1150 <IndexCopy+0x40>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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