#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 */
struct stat {
  scalar_t__ st_size;
};
typedef int /*<<< orphan*/ inc;

/* Variables and functions */
int /*<<< orphan*/ ENOMEM;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ logger(int, int /*<<< orphan*/, char *, ...);
void *malloc(scalar_t__);
int open(char const *, int /*<<< orphan*/);
int read(int, char *, scalar_t__);
char *realloc(char *, scalar_t__);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
scalar_t__ stat(char const *, struct stat *);
scalar_t__ stat_file(char *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strlen(char const *);
char *strrchr(char const *, char);
int read_script(const char *fname, char *include, char **buf) {
  struct stat st;
  char *tmp, *p = NULL;
  int fd, len = 0;
  char *inc;
  if (!fname) {
    logger(-1, 0, "read_script: file name not specified");
    return -1;
  }
  if (include != NULL) {
    inc = ({
      void *p = malloc(strlen(fname) + strlen(include) + 1);
      if (!p)
        logger(-1, ENOMEM, "%s:%i: Can't allocate %lu bytes",
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/NeptunIDE/vzctl/refs/heads/"
               "NeptunIDE/src/lib/script.c",
               56, (unsigned long)strlen(fname) + strlen(include) + 1);
      p;
    });
    if (!inc)
      return -1;
    if ((p = strrchr(fname, '/')) != NULL) {
      snprintf(inc, p - fname + 2, "%s", fname);
      strcat(inc, include);
    } else {
      snprintf(inc, sizeof(inc), "%s", include);
    }
    if (stat_file(inc))
      len = read_script(inc, NULL, buf);
    free(inc);
    if (len < 0)
      return -1;
  }
  if (stat(fname, &st)) {
    logger(-1, 0, "file %s not found", fname);
    return -1;
  }
  if ((fd = open(fname, O_RDONLY)) < 0) {
    logger(-1, errno, "Unable to open %s", fname);
    goto err;
  }
  if (*buf != NULL) {
    tmp = realloc(*buf, st.st_size + len + 2);
    if (tmp == NULL)
      goto err;
    *buf = tmp;
    p = *buf + len;
  } else {
    *buf = malloc(st.st_size + 2);
    if (*buf == NULL)
      goto err;
    p = *buf;
  }
  if ((len = read(fd, p, st.st_size)) < 0) {
    logger(-1, errno, "Error reading %s", fname);
    goto err;
  }
  p += len;
  p[0] = '\n';
  p[1] = 0;
  close(fd);
  return len;
err:
  if (fd > 0)
    close(fd);
  if (*buf != NULL)
    free(*buf);
  return -1;
}


x86 assembly (clang, -O0):
<read_script>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x40(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    122f <read_script+0x4f>
mov    $0xffffffff,%edi
xor    %esi,%esi
lea    0xde4(%rip),%rdx
mov    $0x0,%al
call   10b0 <logger@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1557 <read_script+0x377>
cmpq   $0x0,-0x18(%rbp)
je     139d <read_script+0x1bd>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x60(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   10c0 <malloc@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    12bf <read_script+0xdf>
mov    0x2d62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x70(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x70(%rbp),%r9
mov    -0x64(%rbp),%esi
add    %rax,%r9
add    $0x1,%r9
mov    $0xffffffff,%edi
lea    0xd7a(%rip),%rdx
lea    0xd93(%rip),%rcx
mov    $0x38,%r8d
mov    $0x0,%al
call   10b0 <logger@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    12e6 <read_script+0x106>
movl   $0xffffffff,-0x4(%rbp)
jmp    1557 <read_script+0x377>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     1339 <read_script+0x159>
mov    -0x48(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x2,%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
lea    0xde5(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10f0 <strcat@plt>
jmp    1352 <read_script+0x172>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x8,%esi
lea    0xdba(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x48(%rbp),%rdi
call   1090 <stat_file@plt>
cmp    $0x0,%rax
je     1379 <read_script+0x199>
mov    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%esi
call   1100 <read_script@plt>
mov    %eax,-0x40(%rbp)
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x40(%rbp)
jge    1398 <read_script+0x1b8>
movl   $0xffffffff,-0x4(%rbp)
jmp    1557 <read_script+0x377>
jmp    139d <read_script+0x1bd>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   10a0 <stat@plt>
cmp    $0x0,%rax
je     13d9 <read_script+0x1f9>
mov    -0x10(%rbp),%rcx
mov    $0xffffffff,%edi
xor    %esi,%esi
lea    0xd0f(%rip),%rdx
mov    $0x0,%al
call   10b0 <logger@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1557 <read_script+0x377>
mov    -0x10(%rbp),%rdi
mov    0x2c04(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0x0,%eax
jge    141c <read_script+0x23c>
mov    0x2bd2(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rcx
mov    $0xffffffff,%edi
lea    0xcd7(%rip),%rdx
mov    $0x0,%al
call   10b0 <logger@plt>
jmp    1524 <read_script+0x344>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     147b <read_script+0x29b>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
movslq -0x40(%rbp),%rax
add    %rax,%rsi
add    $0x2,%rsi
call   10d0 <realloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1459 <read_script+0x279>
jmp    1524 <read_script+0x344>
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movslq -0x40(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
jmp    14b0 <read_script+0x2d0>
mov    -0x28(%rbp),%rdi
add    $0x2,%rdi
call   10c0 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    14a5 <read_script+0x2c5>
jmp    1524 <read_script+0x344>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1080 <read@plt>
mov    %eax,-0x40(%rbp)
cmp    $0x0,%eax
jge    14f1 <read_script+0x311>
mov    0x2afd(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rcx
mov    $0xffffffff,%edi
lea    0xc14(%rip),%rdx
mov    $0x0,%al
call   10b0 <logger@plt>
jmp    1524 <read_script+0x344>
mov    -0x40(%rbp),%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movb   $0xa,(%rax)
mov    -0x38(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x3c(%rbp),%edi
call   1070 <close@plt>
mov    -0x40(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1557 <read_script+0x377>
cmpl   $0x0,-0x3c(%rbp)
jle    1536 <read_script+0x356>
mov    -0x3c(%rbp),%edi
call   1070 <close@plt>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1550 <read_script+0x370>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_script>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1268 <read_script+0x88>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r13
xor    %r12d,%r12d
test   %rsi,%rsi
je     1310 <read_script+0x130>
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    %rax,%rbp
add    $0x1,%rbp
mov    %rbp,%rdi
call   10c0 <malloc@plt>
test   %rax,%rax
je     1287 <read_script+0xa7>
mov    %rax,%r15
mov    %r13,%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
je     12bd <read_script+0xdd>
sub    %r13d,%eax
add    $0x2,%eax
lea    0xeb9(%rip),%rdx
mov    %r15,%rdi
mov    %eax,%esi
mov    %r13,%rcx
call   1050 <snprintf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10f0 <strcat@plt>
jmp    12d4 <read_script+0xf4>
lea    0xd91(%rip),%rdx
mov    $0xffffffff,%ebx
mov    $0xffffffff,%edi
xor    %esi,%esi
xor    %eax,%eax
call   10b0 <logger@plt>
jmp    1425 <read_script+0x245>
mov    0x2d4a(%rip),%rax
mov    (%rax),%esi
lea    0xd8e(%rip),%rdx
lea    0xda7(%rip),%rcx
mov    $0xffffffff,%ebx
mov    $0xffffffff,%edi
mov    $0x38,%r8d
mov    %rbp,%r9
xor    %eax,%eax
call   10b0 <logger@plt>
jmp    1425 <read_script+0x245>
lea    0xe43(%rip),%rdx
mov    %r15,%rdi
mov    $0x8,%esi
mov    %rbx,%rcx
call   1050 <snprintf@plt>
mov    %r15,%rdi
call   1090 <stat_file@plt>
test   %rax,%rax
je     1308 <read_script+0x128>
mov    %r15,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1100 <read_script@plt>
mov    %eax,%r12d
mov    %r15,%rdi
call   1030 <free@plt>
test   %r12d,%r12d
jns    1310 <read_script+0x130>
mov    $0xffffffff,%ebx
jmp    1425 <read_script+0x245>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rsp,%rsi
mov    %r13,%rdi
call   10a0 <stat@plt>
test   %rax,%rax
je     1342 <read_script+0x162>
lea    0xdae(%rip),%rdx
mov    $0xffffffff,%ebx
mov    $0xffffffff,%edi
xor    %esi,%esi
mov    %r13,%rcx
xor    %eax,%eax
call   10b0 <logger@plt>
jmp    1425 <read_script+0x245>
mov    0x2c9f(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
call   10e0 <open@plt>
test   %eax,%eax
js     138b <read_script+0x1ab>
mov    %eax,%r15d
mov    (%r14),%rdi
mov    (%rsp),%rbx
test   %rdi,%rdi
je     13ac <read_script+0x1cc>
mov    %r12d,%ebp
lea    (%rbx,%rbp,1),%rsi
add    $0x2,%rsi
call   10d0 <realloc@plt>
test   %rax,%rax
je     1406 <read_script+0x226>
mov    %rax,(%r14)
add    %rax,%rbp
mov    (%rsp),%rbx
jmp    13c0 <read_script+0x1e0>
mov    0x2c3e(%rip),%rax
mov    (%rax),%esi
lea    0xd4c(%rip),%rdx
mov    $0xffffffff,%edi
mov    %r13,%rcx
xor    %eax,%eax
call   10b0 <logger@plt>
jmp    1413 <read_script+0x233>
lea    0x2(%rbx),%rdi
call   10c0 <malloc@plt>
mov    %rax,%rbp
mov    %rax,(%r14)
test   %rax,%rax
je     1406 <read_script+0x226>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1080 <read@plt>
test   %eax,%eax
js     13e7 <read_script+0x207>
mov    %eax,%ebx
mov    %eax,%eax
movw   $0xa,0x0(%rbp,%rax,1)
mov    %r15d,%edi
call   1070 <close@plt>
jmp    1425 <read_script+0x245>
mov    0x2be2(%rip),%rax
mov    (%rax),%esi
lea    0xd02(%rip),%rdx
mov    $0xffffffff,%edi
mov    %r13,%rcx
xor    %eax,%eax
call   10b0 <logger@plt>
test   %r15d,%r15d
je     1413 <read_script+0x233>
mov    %r15d,%edi
call   1070 <close@plt>
mov    (%r14),%rdi
mov    $0xffffffff,%ebx
test   %rdi,%rdi
je     1425 <read_script+0x245>
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [37 x i8] c"read_script: file name not specified\00"
@ENOMEM = global i32 0
@.str.1 = [32 x i8] c"%s:%i: Can't allocate %lu bytes\00"
@.str.2 = [144 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/NeptunIDE/vzctl/refs/heads/NeptunIDE/src/lib/script.c\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [18 x i8] c"file %s not found\00"
@O_RDONLY = global i32 0
@errno = global i32 0
@.str.5 = [18 x i8] c"Unable to open %s\00"
@.str.6 = [17 x i8] c"Error reading %s\00"
define i32 @read_script(i8* %0, i8* %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca %struct.stat
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
store i8* null, i8** %10
store i32 0, i32* %12
%16 = load i8*, i8** %5
%17 = icmp ne i8* %16, null
br i1 %17, label %20, label %18
18: ; preds = %3
%19 = call i32 (i32, i32, i8*, ...) @logger(i32 -1, i32 0, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %177
20: ; preds = %3
%21 = load i8*, i8** %6
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %85
23: ; preds = %20
%24 = load i8*, i8** %5
%25 = call i64 @strlen(i8* %24)
%26 = load i8*, i8** %6
%27 = call i64 @strlen(i8* %26)
%28 = add nsw i64 %25, %27
%29 = add nsw i64 %28, 1
%30 = call i8* @malloc(i64 %29)
store i8* %30, i8** %14
%31 = load i8*, i8** %14
%32 = icmp ne i8* %31, null
br i1 %32, label %42, label %33
33: ; preds = %23
%34 = load i32, i32* @ENOMEM
%35 = load i8*, i8** %5
%36 = call i64 @strlen(i8* %35)
%37 = load i8*, i8** %6
%38 = call i64 @strlen(i8* %37)
%39 = add i64 %36, %38
%40 = add i64 %39, 1
%41 = call i32 (i32, i32, i8*, ...) @logger(i32 -1, i32 %34, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.2, i64 0, i64 0), i32 56, i64 %40)
br label %42
42: ; preds = %33, %23
%43 = load i8*, i8** %14
store i8* %43, i8** %15
%44 = load i8*, i8** %15
store i8* %44, i8** %13
%45 = load i8*, i8** %13
%46 = icmp ne i8* %45, null
br i1 %46, label %48, label %47
47: ; preds = %42
store i32 -1, i32* %4
br label %177
48: ; preds = %42
%49 = load i8*, i8** %5
%50 = call i8* @strrchr(i8* %49, i8 signext 47)
store i8* %50, i8** %10
%51 = icmp ne i8* %50, null
br i1 %51, label %52, label %66
52: ; preds = %48
%53 = load i8*, i8** %13
%54 = load i8*, i8** %10
%55 = load i8*, i8** %5
%56 = ptrtoint i8* %54 to i64
%57 = ptrtoint i8* %55 to i64
%58 = sub i64 %56, %57
%59 = add nsw i64 %58, 2
%60 = trunc i64 %59 to i32
%61 = load i8*, i8** %5
%62 = call i32 @snprintf(i8* %53, i32 %60, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %61)
%63 = load i8*, i8** %13
%64 = load i8*, i8** %6
%65 = call i32 @strcat(i8* %63, i8* %64)
br label %70
66: ; preds = %48
%67 = load i8*, i8** %13
%68 = load i8*, i8** %6
%69 = call i32 @snprintf(i8* %67, i32 8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %68)
br label %70
70: ; preds = %66, %52
%71 = load i8*, i8** %13
%72 = call i64 @stat_file(i8* %71)
%73 = icmp ne i64 %72, 0
br i1 %73, label %74, label %78
74: ; preds = %70
%75 = load i8*, i8** %13
%76 = load i8**, i8*** %7
%77 = call i32 @read_script(i8* %75, i8* null, i8** %76)
store i32 %77, i32* %12
br label %78
78: ; preds = %74, %70
%79 = load i8*, i8** %13
%80 = call i32 @free(i8* %79)
%81 = load i32, i32* %12
%82 = icmp slt i32 %81, 0
br i1 %82, label %83, label %84
83: ; preds = %78
store i32 -1, i32* %4
br label %177
84: ; preds = %78
br label %85
85: ; preds = %84, %20
%86 = load i8*, i8** %5
%87 = call i64 @stat(i8* %86, %struct.stat* %8)
%88 = icmp ne i64 %87, 0
br i1 %88, label %89, label %92
89: ; preds = %85
%90 = load i8*, i8** %5
%91 = call i32 (i32, i32, i8*, ...) @logger(i32 -1, i32 0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %90)
store i32 -1, i32* %4
br label %177
92: ; preds = %85
%93 = load i8*, i8** %5
%94 = load i32, i32* @O_RDONLY
%95 = call i32 @open(i8* %93, i32 %94)
store i32 %95, i32* %11
%96 = icmp slt i32 %95, 0
br i1 %96, label %97, label %101
97: ; preds = %92
%98 = load i32, i32* @errno
%99 = load i8*, i8** %5
%100 = call i32 (i32, i32, i8*, ...) @logger(i32 -1, i32 %98, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %99)
br label %162
101: ; preds = %92
%102 = load i8**, i8*** %7
%103 = load i8*, i8** %102
%104 = icmp ne i8* %103, null
br i1 %104, label %105, label %126
105: ; preds = %101
%106 = load i8**, i8*** %7
%107 = load i8*, i8** %106
%108 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%109 = load i64, i64* %108
%110 = load i32, i32* %12
%111 = sext i32 %110 to i64
%112 = add nsw i64 %109, %111
%113 = add nsw i64 %112, 2
%114 = call i8* @realloc(i8* %107, i64 %113)
store i8* %114, i8** %9
%115 = load i8*, i8** %9
%116 = icmp eq i8* %115, null
br i1 %116, label %117, label %118
117: ; preds = %105
br label %162
118: ; preds = %105
%119 = load i8*, i8** %9
%120 = load i8**, i8*** %7
store i8* %119, i8** %120
%121 = load i8**, i8*** %7
%122 = load i8*, i8** %121
%123 = load i32, i32* %12
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds i8, i8* %122, i64 %124
store i8* %125, i8** %10
br label %139
126: ; preds = %101
%127 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%128 = load i64, i64* %127
%129 = add nsw i64 %128, 2
%130 = call i8* @malloc(i64 %129)
%131 = load i8**, i8*** %7
store i8* %130, i8** %131
%132 = load i8**, i8*** %7
%133 = load i8*, i8** %132
%134 = icmp eq i8* %133, null
br i1 %134, label %135, label %136
135: ; preds = %126
br label %162
136: ; preds = %126
%137 = load i8**, i8*** %7
%138 = load i8*, i8** %137
store i8* %138, i8** %10
br label %139
139: ; preds = %136, %118
%140 = load i32, i32* %11
%141 = load i8*, i8** %10
%142 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%143 = load i64, i64* %142
%144 = call i32 @read(i32 %140, i8* %141, i64 %143)
store i32 %144, i32* %12
%145 = icmp slt i32 %144, 0
br i1 %145, label %146, label %150
146: ; preds = %139
%147 = load i32, i32* @errno
%148 = load i8*, i8** %5
%149 = call i32 (i32, i32, i8*, ...) @logger(i32 -1, i32 %147, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %148)
br label %162
150: ; preds = %139
%151 = load i32, i32* %12
%152 = load i8*, i8** %10
%153 = sext i32 %151 to i64
%154 = getelementptr inbounds i8, i8* %152, i64 %153
store i8* %154, i8** %10
%155 = load i8*, i8** %10
%156 = getelementptr inbounds i8, i8* %155, i64 0
store i8 10, i8* %156
%157 = load i8*, i8** %10
%158 = getelementptr inbounds i8, i8* %157, i64 1
store i8 0, i8* %158
%159 = load i32, i32* %11
%160 = call i32 @close(i32 %159)
%161 = load i32, i32* %12
store i32 %161, i32* %4
br label %177
162: ; preds = %146, %135, %117, %97
%163 = load i32, i32* %11
%164 = icmp sgt i32 %163, 0
br i1 %164, label %165, label %168
165: ; preds = %162
%166 = load i32, i32* %11
%167 = call i32 @close(i32 %166)
br label %168
168: ; preds = %165, %162
%169 = load i8**, i8*** %7
%170 = load i8*, i8** %169
%171 = icmp ne i8* %170, null
br i1 %171, label %172, label %176
172: ; preds = %168
%173 = load i8**, i8*** %7
%174 = load i8*, i8** %173
%175 = call i32 @free(i8* %174)
br label %176
176: ; preds = %172, %168
store i32 -1, i32* %4
br label %177
177: ; preds = %176, %150, %89, %83, %47, %18
%178 = load i32, i32* %4
ret i32 %178
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [37 x i8] c"read_script: file name not specified\00"
@ENOMEM = global i32 0
@.str.1 = [32 x i8] c"%s:%i: Can't allocate %lu bytes\00"
@.str.2 = [144 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/NeptunIDE/vzctl/refs/heads/NeptunIDE/src/lib/script.c\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [18 x i8] c"file %s not found\00"
@O_RDONLY = global i32 0
@errno = global i32 0
@.str.5 = [18 x i8] c"Unable to open %s\00"
@.str.6 = [17 x i8] c"Error reading %s\00"
define i32 @read_script(i8* %0, i8* %1, i8** nocapture %2) {
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %4 to i8*
%6 = icmp eq i8* %0, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 (i32, i32, i8*, ...) @logger(i32 -1, i32 0, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %96
9: ; preds = %3
%10 = icmp eq i8* %1, null
br i1 %10, label %43, label %11
11: ; preds = %9
%12 = tail call i64 @strlen(i8* %0)
%13 = tail call i64 @strlen(i8* %1)
%14 = add i64 %12, 1
%15 = add i64 %14, %13
%16 = tail call i8* @malloc(i64 %15)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load i32, i32* @ENOMEM
%20 = tail call i32 (i32, i32, i8*, ...) @logger(i32 -1, i32 %19, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.2, i64 0, i64 0), i32 56, i64 %15)
br label %96
21: ; preds = %11
%22 = tail call i8* @strrchr(i8* %0, i8 signext 47)
%23 = icmp eq i8* %22, null
br i1 %23, label %32, label %24
24: ; preds = %21
%25 = ptrtoint i8* %22 to i64
%26 = ptrtoint i8* %0 to i64
%27 = sub i64 %25, %26
%28 = trunc i64 %27 to i32
%29 = add i32 %28, 2
%30 = tail call i32 @snprintf(i8* %16, i32 %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%31 = tail call i32 @strcat(i8* %16, i8* %1)
br label %34
32: ; preds = %21
%33 = tail call i32 @snprintf(i8* %16, i32 8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %1)
br label %34
34: ; preds = %32, %24
%35 = tail call i64 @stat_file(i8* %16)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = tail call i32 @free(i8* %16)
br label %43
39: ; preds = %34
%40 = tail call i32 @read_script(i8* %16, i8* null, i8** %2)
%41 = tail call i32 @free(i8* %16)
%42 = icmp slt i32 %40, 0
br i1 %42, label %96, label %43
43: ; preds = %37, %39, %9
%44 = phi i32 [ %40, %39 ], [ 0, %9 ], [ 0, %37 ]
%45 = call i64 @stat(i8* %0, %struct.stat* %4)
%46 = icmp eq i64 %45, 0
br i1 %46, label %49, label %47
47: ; preds = %43
%48 = call i32 (i32, i32, i8*, ...) @logger(i32 -1, i32 0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %96
49: ; preds = %43
%50 = load i32, i32* @O_RDONLY
%51 = call i32 @open(i8* %0, i32 %50)
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = load i32, i32* @errno
%55 = call i32 (i32, i32, i8*, ...) @logger(i32 -1, i32 %54, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %0)
br label %91
56: ; preds = %49
%57 = load i8*, i8** %2
%58 = icmp eq i8* %57, null
%59 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%60 = load i64, i64* %59
br i1 %58, label %70, label %61
61: ; preds = %56
%62 = zext i32 %44 to i64
%63 = add nuw nsw i64 %62, 2
%64 = add i64 %63, %60
%65 = call i8* @realloc(i8* %57, i64 %64)
%66 = icmp eq i8* %65, null
br i1 %66, label %87, label %67
67: ; preds = %61
store i8* %65, i8** %2
%68 = getelementptr inbounds i8, i8* %65, i64 %62
%69 = load i64, i64* %59
br label %74
70: ; preds = %56
%71 = add nsw i64 %60, 2
%72 = call i8* @malloc(i64 %71)
store i8* %72, i8** %2
%73 = icmp eq i8* %72, null
br i1 %73, label %87, label %74
74: ; preds = %70, %67
%75 = phi i64 [ %69, %67 ], [ %60, %70 ]
%76 = phi i8* [ %68, %67 ], [ %72, %70 ]
%77 = call i32 @read(i32 %51, i8* %76, i64 %75)
%78 = icmp slt i32 %77, 0
br i1 %78, label %79, label %82
79: ; preds = %74
%80 = load i32, i32* @errno
%81 = call i32 (i32, i32, i8*, ...) @logger(i32 -1, i32 %80, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %0)
br label %87
82: ; preds = %74
%83 = zext i32 %77 to i64
%84 = getelementptr inbounds i8, i8* %76, i64 %83
store i8 10, i8* %84
%85 = getelementptr inbounds i8, i8* %84, i64 1
store i8 0, i8* %85
%86 = call i32 @close(i32 %51)
br label %96
87: ; preds = %70, %61, %79
%88 = icmp eq i32 %51, 0
br i1 %88, label %91, label %89
89: ; preds = %87
%90 = call i32 @close(i32 %51)
br label %91
91: ; preds = %53, %89, %87
%92 = load i8*, i8** %2
%93 = icmp eq i8* %92, null
br i1 %93, label %96, label %94
94: ; preds = %91
%95 = call i32 @free(i8* %92)
br label %96
96: ; preds = %18, %91, %94, %39, %82, %47, %7
%97 = phi i32 [ -1, %47 ], [ %77, %82 ], [ -1, %7 ], [ -1, %18 ], [ -1, %39 ], [ -1, %94 ], [ -1, %91 ]
ret i32 %97
}