#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *substr2(char *str, int start, int end) {
  if ((end - start) < 1)
    return 0;
  char *t = (char *)malloc((end - start + 1) * sizeof(char));
  strncpy(t, str + start, (end - start));
  return t;
}


x86 assembly (clang, -O0):
<substr2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
cmp    $0x1,%eax
jge    114e <substr2+0x2e>
movq   $0x0,-0x8(%rbp)
jmp    118a <substr2+0x6a>
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    -0x18(%rbp),%edx
sub    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<substr2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
sub    %esi,%ebx
jle    1152 <substr2+0x32>
mov    %esi,%ebp
mov    %rdi,%r14
lea    0x1(%rbx),%edi
call   1040 <malloc@plt>
mov    %rax,%r15
movslq %ebp,%rax
add    %rax,%r14
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
jmp    1155 <substr2+0x35>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @substr2(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %7
%10 = load i32, i32* %6
%11 = sub nsw i32 %9, %10
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %3
store i8* null, i8** %4
br label %34
14: ; preds = %3
%15 = load i32, i32* %7
%16 = load i32, i32* %6
%17 = sub nsw i32 %15, %16
%18 = add nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 1
%21 = trunc i64 %20 to i32
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %8
%24 = load i8*, i8** %8
%25 = load i8*, i8** %5
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i32, i32* %7
%30 = load i32, i32* %6
%31 = sub nsw i32 %29, %30
%32 = call i32 @strncpy(i8* %24, i8* %28, i32 %31)
%33 = load i8*, i8** %8
store i8* %33, i8** %4
br label %34
34: ; preds = %14, %13
%35 = load i8*, i8** %4
ret i8* %35
}

LLVM IR (-O2):
define i8* @substr2(i8* %0, i32 %1, i32 %2) {
%4 = sub nsw i32 %2, %1
%5 = icmp slt i32 %4, 1
br i1 %5, label %13, label %6
6: ; preds = %3
%7 = add nuw nsw i32 %4, 1
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = sext i32 %1 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = tail call i32 @strncpy(i8* %9, i8* %11, i32 %4)
br label %13
13: ; preds = %3, %6
%14 = phi i8* [ %9, %6 ], [ null, %3 ]
ret i8* %14
}