#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 *ft_strdup(char *);
int /*<<< orphan*/ ft_strncpy(char *, char const *, size_t);
scalar_t__ malloc(int);
char *ft_strsub(char const *s, unsigned int start, size_t len) {
  char *str;
  if (s && len > 0) {
    str = (char *)malloc(sizeof(char) * (len + 1));
    ft_strncpy(str, s + start, len);
    str[len] = 0;
    return (str);
  }
  return (ft_strdup(""));
}


x86 assembly (clang, -O0):
<ft_strsub>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a0 <ft_strsub+0x70>
cmpq   $0x0,-0x20(%rbp)
jbe    11a0 <ft_strsub+0x70>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%eax
add    %rax,%rsi
mov    -0x20(%rbp),%rdx
call   1050 <ft_strncpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b0 <ft_strsub+0x80>
lea    0xe59(%rip),%rdi
call   1030 <ft_strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_strsub>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     117e <ft_strsub+0x4e>
mov    %rdx,%r14
test   %rdx,%rdx
je     117e <ft_strsub+0x4e>
mov    %esi,%r15d
mov    %rdi,%rbx
lea    0x1(%r14),%edi
call   1040 <malloc@plt>
mov    %rax,%rbp
mov    %r15d,%eax
add    %rax,%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <ft_strncpy@plt>
movb   $0x0,0x0(%rbp,%r14,1)
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe7b(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <ft_strdup@plt>

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

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @ft_strsub(i8* %0, i32 %1, i64 %2) {
%4 = icmp ne i8* %0, null
%5 = icmp ne i64 %2, 0
%6 = and i1 %4, %5
br i1 %6, label %7, label %16
7: ; preds = %3
%8 = trunc i64 %2 to i32
%9 = add i32 %8, 1
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
%12 = zext i32 %1 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = tail call i32 @ft_strncpy(i8* %11, i8* %13, i64 %2)
%15 = getelementptr inbounds i8, i8* %11, i64 %2
store i8 0, i8* %15
br label %18
16: ; preds = %3
%17 = tail call i8* @ft_strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %7
%19 = phi i8* [ %11, %7 ], [ %17, %16 ]
ret i8* %19
}