#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 */
char *calloc(int, int);
scalar_t__ strlen(char *);
char *__imlib_copystr(char *str, int start, int end) {
  int i = 0;
  char *rstr = calloc(1024, sizeof(char));
  if (start <= end && end < (int)strlen(str)) {
    for (i = start; i <= end; i++)
      rstr[i - start] = str[i];
    return rstr;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<__imlib_copystr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x400,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     11bd <__imlib_copystr+0x9d>
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jge    11bd <__imlib_copystr+0x9d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     11b0 <__imlib_copystr+0x90>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    -0x14(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117b <__imlib_copystr+0x5b>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c5 <__imlib_copystr+0xa5>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__imlib_copystr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %esi,%r15d
mov    %rdi,%r14
mov    $0x400,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %ebx,%ebp
sub    %r15d,%ebp
jl     117f <__imlib_copystr+0x4f>
mov    %rax,%r12
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    %ebx,%eax
jle    117f <__imlib_copystr+0x4f>
movslq %r15d,%rax
add    %rax,%r14
add    $0x1,%rbp
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
call   1050 <memcpy@plt>
jmp    1182 <__imlib_copystr+0x52>
xor    %r12d,%r12d
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define noalias i8* @__imlib_copystr(i8* nocapture %0, i32 %1, i32 %2) {
%4 = tail call dereferenceable_or_null(1024) i8* @calloc(i32 1024, i32 1)
%5 = icmp slt i32 %2, %1
br i1 %5, label %16, label %6
6: ; preds = %3
%7 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%8 = trunc i64 %7 to i32
%9 = icmp sgt i32 %8, %2
br i1 %9, label %10, label %16
10: ; preds = %6
%11 = sext i32 %1 to i64
%12 = getelementptr i8, i8* %0, i64 %11
%13 = sub i32 %2, %1
%14 = zext i32 %13 to i64
%15 = add nuw nsw i64 %14, 1
br label %16
16: ; preds = %10, %3, %6
%17 = phi i8* [ null, %6 ], [ null, %3 ], [ %4, %10 ]
ret i8* %17
}