#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*/ libcgi_error(int, char *, char *, int);
scalar_t__ malloc(int const);
int /*<<< orphan*/ strncpy(char *, char *, int const);
char *substr(char *src, const int start, const int count) {
  char *tmp;
  tmp = (char *)malloc(count + 1);
  if (tmp == NULL) {
    libcgi_error(4, "%s, line %s",
                 "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                 "outputs/2022-01-22/02-19-57/repos/LeSpocky/libcgi/refs/heads/"
                 "master/src/string.c",
                 264);
    return NULL;
  }
  strncpy(tmp, src + start, count);
  tmp[count] = '\0';
  return tmp;
}


x86 assembly (clang, -O0):
<substr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1186 <substr+0x56>
mov    $0x4,%edi
lea    0xe98(%rip),%rsi
lea    0xe9d(%rip),%rdx
mov    $0x108,%ecx
call   1040 <libcgi_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    11b1 <substr+0x81>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    -0x18(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<substr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
lea    0x1(%r14),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     116d <substr+0x3d>
mov    %rax,%rbx
movslq %ebp,%rax
add    %rax,%r15
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <strncpy@plt>
movslq %r14d,%rax
movb   $0x0,(%rbx,%rax,1)
jmp    118c <substr+0x5c>
lea    0xe8c(%rip),%rsi
lea    0xe91(%rip),%rdx
mov    $0x4,%edi
mov    $0x108,%ecx
call   1040 <libcgi_error@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%s, line %s\00"
@.str.1 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/LeSpocky/libcgi/refs/heads/master/src/string.c\00"
define i8* @substr(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 = add nsw i32 %9, 1
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %8
%13 = load i8*, i8** %8
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 @libcgi_error(i32 4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 264)
store i8* null, i8** %4
br label %30
17: ; preds = %3
%18 = load i8*, i8** %8
%19 = load i8*, i8** %5
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i32, i32* %7
%24 = call i32 @strncpy(i8* %18, i8* %22, i32 %23)
%25 = load i8*, i8** %8
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 0, i8* %28
%29 = load i8*, i8** %8
store i8* %29, i8** %4
br label %30
30: ; preds = %17, %15
%31 = load i8*, i8** %4
ret i8* %31
}

LLVM IR (-O2):
@.str = [12 x i8] c"%s, line %s\00"
@.str.1 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/LeSpocky/libcgi/refs/heads/master/src/string.c\00"
define i8* @substr(i8* %0, i32 %1, i32 %2) {
%4 = add nsw i32 %2, 1
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @libcgi_error(i32 4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 264)
br label %16
10: ; preds = %3
%11 = sext i32 %1 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = tail call i32 @strncpy(i8* %6, i8* %12, i32 %2)
%14 = sext i32 %2 to i64
%15 = getelementptr inbounds i8, i8* %6, i64 %14
store i8 0, i8* %15
br label %16
16: ; preds = %10, %8
%17 = phi i8* [ null, %8 ], [ %6, %10 ]
ret i8* %17
}