#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*/ abort();
int backtrace(void **, int);
scalar_t__ backtrace_symbols(void **, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *, char *,
                           int, char *);
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ simple_now_iso8601(char *);
scalar_t__ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stderr;
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ va_list_print(char *, char *);
int simple_string_substr(const char *src, int begin_index, int end_index,
                         char new_str[]) {
  if (!(strlen(src) >= end_index)) {
    char __log_time__[64] = {0};
    simple_now_iso8601(__log_time__);
    char __buffer_stack__[1024];
    void *__array__[10];
    char **__strframe__ = NULL;
    int __i__, __idx__ = 0, __n__ = backtrace(__array__, 10);
    __strframe__ = (char **)backtrace_symbols(__array__, __n__);
    for (__i__ = 0; __i__ < __n__; __i__++)
      __idx__ += snprintf(__idx__ + __buffer_stack__, 256, "%s\n",
                          __strframe__[__i__]);
    free(__strframe__);
    char __log_message__[512] = {0};
    va_list_print(__log_message__, "end_index out of range.");
    fprintf(stderr, "%s, Assert fail ! %s\t[%s:%d]\n%s\n", (__log_time__),
            (__log_message__),
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/red-chen/lemon/refs/heads/master/src/"
            "string_tool.c",
            146, __buffer_stack__);
    abort();
  };
  int size = (end_index - begin_index);
  if (size < 0 && (strlen(src) - 1) < end_index) {
    return -1;
  }
  char *tmp = (char *)(src + begin_index);
  strncpy(new_str, tmp, size);
  return 0;
}


x86 assembly (clang, -O0):
<simple_string_substr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x6f0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
cmp    -0x18(%rbp),%eax
jge    1322 <simple_string_substr+0x172>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   10a0 <memset@plt>
lea    -0x60(%rbp),%rdi
call   10b0 <simple_now_iso8601@plt>
movq   $0x0,-0x4b8(%rbp)
movl   $0x0,-0x4c0(%rbp)
lea    -0x4b0(%rbp),%rdi
mov    $0xa,%esi
call   1080 <backtrace@plt>
mov    %eax,-0x4c4(%rbp)
lea    -0x4b0(%rbp),%rdi
mov    -0x4c4(%rbp),%esi
call   1060 <backtrace_symbols@plt>
mov    %rax,-0x4b8(%rbp)
movl   $0x0,-0x4bc(%rbp)
mov    -0x4bc(%rbp),%eax
cmp    -0x4c4(%rbp),%eax
jge    12b1 <simple_string_substr+0x101>
mov    -0x4c0(%rbp),%eax
lea    -0x460(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x4b8(%rbp),%rax
movslq -0x4bc(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    $0x100,%esi
lea    0xdb0(%rip),%rdx
call   1090 <snprintf@plt>
mov    %rax,%rcx
movslq -0x4c0(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4c0(%rbp)
mov    -0x4bc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4bc(%rbp)
jmp    1243 <simple_string_substr+0x93>
mov    -0x4b8(%rbp),%rdi
call   1030 <free@plt>
lea    -0x6d0(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   10a0 <memset@plt>
lea    -0x6d0(%rbp),%rdi
lea    0xd22(%rip),%rsi
call   10d0 <va_list_print@plt>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rdx
lea    -0x6d0(%rbp),%rcx
lea    -0x460(%rbp),%rax
lea    0xd13(%rip),%rsi
lea    0xd2d(%rip),%r8
mov    $0x92,%r9d
mov    %rax,(%rsp)
call   10c0 <fprintf@plt>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x6d4(%rbp)
cmpl   $0x0,-0x6d4(%rbp)
jge    135c <simple_string_substr+0x1ac>
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
sub    $0x1,%eax
cmp    -0x18(%rbp),%eax
jge    135c <simple_string_substr+0x1ac>
movl   $0xffffffff,-0x4(%rbp)
jmp    138b <simple_string_substr+0x1db>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x6e0(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x6e0(%rbp),%rsi
mov    -0x6d4(%rbp),%edx
call   1050 <strncpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x6f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simple_string_substr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x6a0,%rsp
mov    %rcx,%r14
mov    %edx,%r12d
mov    %esi,%r15d
mov    %rdi,%rbx
call   1070 <strlen@plt>
cmp    %r12d,%eax
jl     1216 <simple_string_substr+0x66>
mov    %r12d,%ebp
sub    %r15d,%ebp
jns    11f1 <simple_string_substr+0x41>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %r12d,%ecx
jle    1206 <simple_string_substr+0x56>
movslq %r15d,%rax
add    %rax,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1050 <strncpy@plt>
xor    %eax,%eax
add    $0x6a0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rdi
call   10b0 <simple_now_iso8601@plt>
lea    0x50(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1080 <backtrace@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <backtrace_symbols@plt>
mov    %rax,%r15
test   %ebp,%ebp
jle    129b <simple_string_substr+0xeb>
mov    %ebp,%r12d
xor    %ebx,%ebx
lea    0xdcd(%rip),%r14
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
movslq %eax,%rbp
lea    (%rsp,%rbp,1),%rdi
add    $0x2a0,%rdi
mov    (%r15,%rbx,8),%rcx
mov    $0x100,%esi
mov    %r14,%rdx
call   1090 <snprintf@plt>
add    %rbp,%rax
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1270 <simple_string_substr+0xc0>
mov    %r15,%rdi
call   1030 <free@plt>
lea    0xa0(%rsp),%rbx
mov    $0x200,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <memset@plt>
lea    0xd3f(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <va_list_print@plt>
mov    0x2d10(%rip),%rax
mov    (%rax),%edi
lea    0x2a0(%rsp),%rax
mov    %rax,(%rsp)
lea    0xd33(%rip),%rsi
lea    0xd4d(%rip),%r8
lea    0x10(%rsp),%rdx
mov    %rbx,%rcx
mov    $0x92,%r9d
call   10c0 <fprintf@plt>
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [24 x i8] c"end_index out of range.\00"
@stderr = global i32 0
@.str.2 = [33 x i8] c"%s, Assert fail ! %s\09[%s:%d]\0A%s\0A\00"
@.str.3 = [141 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/red-chen/lemon/refs/heads/master/src/string_tool.c\00"
define i32 @simple_string_substr(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca [64 x i8]
%11 = alloca [1024 x i8]
%12 = alloca [10 x i8*]
%13 = alloca i8**
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca [512 x i8]
%18 = alloca i32
%19 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%20 = load i8*, i8** %6
%21 = call i32 @strlen(i8* %20)
%22 = load i32, i32* %8
%23 = icmp sge i32 %21, %22
br i1 %23, label %68, label %24
24: ; preds = %4
%25 = bitcast [64 x i8]* %10 to i8*
%26 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%27 = call i32 @simple_now_iso8601(i8* %26)
store i8** null, i8*** %13
store i32 0, i32* %15
%28 = getelementptr inbounds [10 x i8*], [10 x i8*]* %12, i64 0, i64 0
%29 = call i32 @backtrace(i8** %28, i32 10)
store i32 %29, i32* %16
%30 = getelementptr inbounds [10 x i8*], [10 x i8*]* %12, i64 0, i64 0
%31 = load i32, i32* %16
%32 = call i64 @backtrace_symbols(i8** %30, i32 %31)
%33 = inttoptr i64 %32 to i8**
store i8** %33, i8*** %13
store i32 0, i32* %14
br label %34
34: ; preds = %53, %24
%35 = load i32, i32* %14
%36 = load i32, i32* %16
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %56
38: ; preds = %34
%39 = load i32, i32* %15
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%41 = sext i32 %39 to i64
%42 = getelementptr inbounds i8, i8* %40, i64 %41
%43 = load i8**, i8*** %13
%44 = load i32, i32* %14
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
%47 = load i8*, i8** %46
%48 = call i64 @snprintf(i8* %42, i32 256, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %47)
%49 = load i32, i32* %15
%50 = sext i32 %49 to i64
%51 = add nsw i64 %50, %48
%52 = trunc i64 %51 to i32
store i32 %52, i32* %15
br label %53
53: ; preds = %38
%54 = load i32, i32* %14
%55 = add nsw i32 %54, 1
store i32 %55, i32* %14
br label %34
56: ; preds = %34
%57 = load i8**, i8*** %13
%58 = call i32 @free(i8** %57)
%59 = bitcast [512 x i8]* %17 to i8*
%60 = getelementptr inbounds [512 x i8], [512 x i8]* %17, i64 0, i64 0
%61 = call i32 @va_list_print(i8* %60, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%62 = load i32, i32* @stderr
%63 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%64 = getelementptr inbounds [512 x i8], [512 x i8]* %17, i64 0, i64 0
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%66 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %63, i8* %64, i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.3, i64 0, i64 0), i32 146, i8* %65)
%67 = call i32 (...) @abort()
unreachable
68: ; preds = %4
%69 = load i32, i32* %8
%70 = load i32, i32* %7
%71 = sub nsw i32 %69, %70
store i32 %71, i32* %18
%72 = load i32, i32* %18
%73 = icmp slt i32 %72, 0
br i1 %73, label %74, label %81
74: ; preds = %68
%75 = load i8*, i8** %6
%76 = call i32 @strlen(i8* %75)
%77 = sub nsw i32 %76, 1
%78 = load i32, i32* %8
%79 = icmp slt i32 %77, %78
br i1 %79, label %80, label %81
80: ; preds = %74
store i32 -1, i32* %5
br label %90
81: ; preds = %74, %68
%82 = load i8*, i8** %6
%83 = load i32, i32* %7
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8, i8* %82, i64 %84
store i8* %85, i8** %19
%86 = load i8*, i8** %9
%87 = load i8*, i8** %19
%88 = load i32, i32* %18
%89 = call i32 @strncpy(i8* %86, i8* %87, i32 %88)
store i32 0, i32* %5
br label %90
90: ; preds = %81, %80
%91 = load i32, i32* %5
ret i32 %91
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [24 x i8] c"end_index out of range.\00"
@stderr = global i32 0
@.str.2 = [33 x i8] c"%s, Assert fail ! %s\09[%s:%d]\0A%s\0A\00"
@.str.3 = [141 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/red-chen/lemon/refs/heads/master/src/string_tool.c\00"
define i32 @simple_string_substr(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca [64 x i8]
%6 = alloca [1024 x i8]
%7 = alloca [10 x i8*]
%8 = alloca [512 x i8]
%9 = tail call i32 @strlen(i8* %0)
%10 = icmp slt i32 %9, %2
br i1 %10, label %11, label %42
11: ; preds = %4
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%13 = call i32 @simple_now_iso8601(i8* %12)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%15 = bitcast [10 x i8*]* %7 to i8*
%16 = getelementptr inbounds [10 x i8*], [10 x i8*]* %7, i64 0, i64 0
%17 = call i32 @backtrace(i8** %16, i32 10)
%18 = call i64 @backtrace_symbols(i8** %16, i32 %17)
%19 = inttoptr i64 %18 to i8**
%20 = icmp sgt i32 %17, 0
br i1 %20, label %21, label %35
21: ; preds = %11
%22 = zext i32 %17 to i64
br label %23
23: ; preds = %21, %23
%24 = phi i64 [ 0, %21 ], [ %33, %23 ]
%25 = phi i64 [ 0, %21 ], [ %32, %23 ]
%26 = shl i64 %25, 32
%27 = ashr exact i64 %26, 32
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %27
%29 = getelementptr inbounds i8*, i8** %19, i64 %24
%30 = load i8*, i8** %29
%31 = call i64 @snprintf(i8* %28, i32 256, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = add nsw i64 %31, %27
%33 = add nuw nsw i64 %24, 1
%34 = icmp eq i64 %33, %22
br i1 %34, label %35, label %23
35: ; preds = %23, %11
%36 = call i32 @free(i8** %19)
%37 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%38 = call i32 @va_list_print(i8* %37, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %12, i8* %37, i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.3, i64 0, i64 0), i32 146, i8* %14)
%41 = call i32 (...) @abort()
unreachable
42: ; preds = %4
%43 = sub nsw i32 %2, %1
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = tail call i32 @strlen(i8* %0)
%47 = icmp sgt i32 %46, %2
br i1 %47, label %48, label %52
48: ; preds = %45, %42
%49 = sext i32 %1 to i64
%50 = getelementptr inbounds i8, i8* %0, i64 %49
%51 = tail call i32 @strncpy(i8* %3, i8* %50, i32 %43)
br label %52
52: ; preds = %45, %48
%53 = phi i32 [ 0, %48 ], [ -1, %45 ]
ret i32 %53
}