#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 */
typedef int uint8_t;
typedef int /*<<< orphan*/ header;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
unsigned long fread(int *, int, unsigned long, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
unsigned long ftell(int /*<<< orphan*/ *);
unsigned long fwrite(int *, int, unsigned long, int /*<<< orphan*/ *);
int *malloc(unsigned long);
int /*<<< orphan*/ memcmp(int *, int *, int);
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  FILE *fp = NULL;
  uint8_t header[30] = {0x5d, 0x21, 0x51, 0x44, 0x4f, 0x53, 0x20, 0x46,
                        0x69, 0x6c, 0x65, 0x20, 0x48, 0x65, 0x61, 0x64,
                        0x65, 0x72, 0x00, 0x0f, 0x00, 0x01, 0x00, 0x00,
                        0x02, 0xa8, 0x00, 0x00, 0x00, 0x00};
  uint8_t *p_data = NULL;
  unsigned long size, bytes_read, bytes_written;
  int i;
  if (argc < 2 || !strcmp(argv[1], "--help")) {
    printf("Invocation: qlh <exec-file to be patched>\n\n");
    return -1;
  }
  fp = fopen(argv[1], "rb");
  if (fp == NULL) {
    fprintf(stderr, "Could not open file %s error!\n", argv[1]);
    return -1;
  }
  fseek(fp, 0L, SEEK_END);
  size = ftell(fp);
  fseek(fp, 0L, SEEK_SET);
  p_data = malloc(size + sizeof(header));
  if (p_data == NULL) {
    fprintf(
        stderr, "%s, %d: out of memory error!\n",
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/linneman/snake/refs/heads/master/addqlh.c",
        41);
    return -1;
  }
  bytes_read = fread(p_data + sizeof(header), sizeof(uint8_t), size, fp);
  fclose(fp);
  if (bytes_read != size) {
    fprintf(
        stderr, "%s, %d: error while reading file %s!\n",
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/linneman/snake/refs/heads/master/addqlh.c",
        49, argv[1]);
    return -1;
  }
  if (!memcmp(p_data + sizeof(header), header, sizeof(header))) {
    fprintf(stderr, "header already present, no patch needs to be applied!\n");
    return -1;
  }
  memcpy(p_data, header, sizeof(header));
  fp = fopen(argv[1], "wb");
  if (fp == NULL) {
    fprintf(stderr, "Could not open file %s error!\n", argv[1]);
    return -1;
  }
  bytes_written = fwrite(p_data, sizeof(uint8_t), size + sizeof(header), fp);
  if (bytes_written != size + sizeof(header)) {
    fprintf(
        stderr, "%s, %d: write error occured!\n",
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/linneman/snake/refs/heads/master/addqlh.c",
        70);
    return -1;
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x90(%rbp),%rdi
lea    0xe11(%rip),%rsi
mov    $0x78,%edx
call   10a0 <memcpy@plt>
movq   $0x0,-0x98(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     122b <main+0x6b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5b(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1243 <main+0x83>
lea    0xe4d(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14d1 <main+0x311>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe59(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1291 <main+0xd1>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14d1 <main+0x311>
mov    -0x18(%rbp),%rdi
mov    0x2d4c(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10c0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0xa0(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d0e(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10c0 <fseek@plt>
mov    -0xa0(%rbp),%rdi
add    $0x78,%rdi
call   10b0 <malloc@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jne    1321 <main+0x161>
mov    0x2cdf(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
lea    0xde2(%rip),%rdx
mov    $0x29,%ecx
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14d1 <main+0x311>
mov    -0x98(%rbp),%rdi
add    $0x1e0,%rdi
mov    -0xa0(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x4,%esi
call   1030 <fread@plt>
mov    %rax,-0xa8(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0xa8(%rbp),%rax
cmp    -0xa0(%rbp),%rax
je     139f <main+0x1df>
mov    0x2c69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r8
lea    0xdef(%rip),%rsi
lea    0xd64(%rip),%rdx
mov    $0x31,%ecx
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14d1 <main+0x311>
mov    -0x98(%rbp),%rdi
add    $0x1e0,%rdi
lea    -0x90(%rbp),%rsi
mov    $0x78,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%eax
jne    13ea <main+0x22a>
mov    0x2c0a(%rip),%rax
mov    (%rax),%edi
lea    0xdbe(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14d1 <main+0x311>
mov    -0x98(%rbp),%rdi
lea    -0x90(%rbp),%rsi
mov    $0x78,%edx
call   10a0 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdbb(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1450 <main+0x290>
mov    0x2bac(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xc71(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14d1 <main+0x311>
mov    -0x98(%rbp),%rdi
mov    -0xa0(%rbp),%rdx
add    $0x78,%rdx
mov    -0x18(%rbp),%rcx
mov    $0x4,%esi
call   10e0 <fwrite@plt>
mov    %rax,-0xb0(%rbp)
mov    -0xb0(%rbp),%rax
mov    -0xa0(%rbp),%rcx
add    $0x78,%rcx
cmp    %rcx,%rax
je     14c1 <main+0x301>
mov    0x2b3f(%rip),%rax
mov    (%rax),%edi
lea    0xd2d(%rip),%rsi
lea    0xc42(%rip),%rdx
mov    $0x46,%ecx
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14d1 <main+0x311>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    0xe98(%rip),%rax
mov    %rax,0x80(%rsp)
movaps 0xe79(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe5d(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xe41(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe25(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe09(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xded(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xdd1(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
cmp    $0x2,%edi
jl     1364 <main+0x1a4>
mov    %rsi,%r12
mov    0x8(%rsi),%rbx
lea    0xe2d(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     1364 <main+0x1a4>
lea    0xe1d(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1387 <main+0x1c7>
mov    %rax,%rbx
mov    0x2d6b(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    %rbx,%rdi
call   1090 <ftell@plt>
mov    %rax,%r13
mov    0x2d35(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
lea    0x78(%r13),%rbp
mov    %rbp,%rdi
call   10b0 <malloc@plt>
test   %rax,%rax
je     13a5 <main+0x1e5>
mov    %rax,%r15
mov    %rbp,0x8(%rsp)
lea    0x1e0(%rax),%rbp
mov    %rbp,%rdi
mov    $0x4,%esi
mov    %r13,%rdx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <fclose@plt>
cmp    %r13,%r14
jne    13ca <main+0x20a>
lea    0x10(%rsp),%rsi
mov    %rbp,%rdi
mov    $0x78,%edx
call   1060 <memcmp@plt>
test   %eax,%eax
je     13f7 <main+0x237>
lea    0x10(%rsp),%rsi
mov    %r15,%rdi
mov    $0x78,%edx
call   10a0 <memcpy@plt>
mov    0x8(%r12),%rdi
lea    0xe76(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1387 <main+0x1c7>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x4,%esi
mov    0x8(%rsp),%rbp
mov    %rbp,%rdx
mov    %rax,%rcx
call   10e0 <fwrite@plt>
cmp    %rbp,%rax
jne    1413 <main+0x253>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    1375 <main+0x1b5>
lea    0xe56(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c4a(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r12),%rdx
lea    0xce6(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1370 <main+0x1b0>
mov    0x2c2c(%rip),%rax
mov    (%rax),%edi
lea    0xcec(%rip),%rsi
lea    0xd03(%rip),%rdx
mov    $0x29,%ecx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1370 <main+0x1b0>
mov    0x2c07(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r12),%r8
lea    0xd64(%rip),%rsi
lea    0xcd9(%rip),%rdx
mov    $0x31,%ecx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1370 <main+0x1b0>
mov    0x2bda(%rip),%rax
mov    (%rax),%edi
lea    0xd62(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1370 <main+0x1b0>
mov    0x2bbe(%rip),%rax
mov    (%rax),%edi
lea    0xd80(%rip),%rsi
lea    0xc95(%rip),%rdx
mov    $0x46,%ecx
jmp    13c1 <main+0x201>

LLVM IR (-O0):
@__const.main.header = [30 x i32] [i32 93, i32 33, i32 81, i32 68, i32 79, i32 83, i32 32, i32 70, i32 105, i32 108, i32 101, i32 32, i32 72, i32 101, i32 97, i32 100, i32 101, i32 114, i32 0, i32 15, i32 0, i32 1, i32 0, i32 0, i32 2, i32 168, i32 0, i32 0, i32 0, i32 0]
@.str = [7 x i8] c"--help\00"
@.str.1 = [44 x i8] c"Invocation: qlh <exec-file to be patched>\0A\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.3 = [31 x i8] c"Could not open file %s error!\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [30 x i8] c"%s, %d: out of memory error!\0A\00"
@.str.5 = [132 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/linneman/snake/refs/heads/master/addqlh.c\00"
@.str.6 = [38 x i8] c"%s, %d: error while reading file %s!\0A\00"
@.str.7 = [55 x i8] c"header already present, no patch needs to be applied!\0A\00"
@.str.8 = [3 x i8] c"wb\00"
@.str.9 = [30 x i8] c"%s, %d: write error occured!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [30 x i32]
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
%13 = bitcast [30 x i32]* %7 to i8*
store i32* null, i32** %8
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %22, label %16
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @strcmp(i8* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %16, %2
%23 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %112
24: ; preds = %16
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %28, i32** %6
%29 = load i32*, i32** %6
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %37
31: ; preds = %24
%32 = load i32, i32* @stderr
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %35)
store i32 -1, i32* %3
br label %112
37: ; preds = %24
%38 = load i32*, i32** %6
%39 = load i32, i32* @SEEK_END
%40 = call i32 @fseek(i32* %38, i64 0, i32 %39)
%41 = load i32*, i32** %6
%42 = call i64 @ftell(i32* %41)
store i64 %42, i64* %9
%43 = load i32*, i32** %6
%44 = load i32, i32* @SEEK_SET
%45 = call i32 @fseek(i32* %43, i64 0, i32 %44)
%46 = load i64, i64* %9
%47 = add i64 %46, 120
%48 = call i32* @malloc(i64 %47)
store i32* %48, i32** %8
%49 = load i32*, i32** %8
%50 = icmp eq i32* %49, null
br i1 %50, label %51, label %54
51: ; preds = %37
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.5, i64 0, i64 0), i32 41)
store i32 -1, i32* %3
br label %112
54: ; preds = %37
%55 = load i32*, i32** %8
%56 = getelementptr inbounds i32, i32* %55, i64 120
%57 = load i64, i64* %9
%58 = load i32*, i32** %6
%59 = call i64 @fread(i32* %56, i32 4, i64 %57, i32* %58)
store i64 %59, i64* %10
%60 = load i32*, i32** %6
%61 = call i32 @fclose(i32* %60)
%62 = load i64, i64* %10
%63 = load i64, i64* %9
%64 = icmp ne i64 %62, %63
br i1 %64, label %65, label %71
65: ; preds = %54
%66 = load i32, i32* @stderr
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 1
%69 = load i8*, i8** %68
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.5, i64 0, i64 0), i32 49, i8* %69)
store i32 -1, i32* %3
br label %112
71: ; preds = %54
%72 = load i32*, i32** %8
%73 = getelementptr inbounds i32, i32* %72, i64 120
%74 = getelementptr inbounds [30 x i32], [30 x i32]* %7, i64 0, i64 0
%75 = call i32 @memcmp(i32* %73, i32* %74, i32 120)
%76 = icmp ne i32 %75, 0
br i1 %76, label %80, label %77
77: ; preds = %71
%78 = load i32, i32* @stderr
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %3
br label %112
80: ; preds = %71
%81 = load i32*, i32** %8
%82 = getelementptr inbounds [30 x i32], [30 x i32]* %7, i64 0, i64 0
%83 = call i32 @memcpy(i32* %81, i32* %82, i32 120)
%84 = load i8**, i8*** %5
%85 = getelementptr inbounds i8*, i8** %84, i64 1
%86 = load i8*, i8** %85
%87 = call i32* @fopen(i8* %86, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
store i32* %87, i32** %6
%88 = load i32*, i32** %6
%89 = icmp eq i32* %88, null
br i1 %89, label %90, label %96
90: ; preds = %80
%91 = load i32, i32* @stderr
%92 = load i8**, i8*** %5
%93 = getelementptr inbounds i8*, i8** %92, i64 1
%94 = load i8*, i8** %93
%95 = call i32 (i32, i8*, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %94)
store i32 -1, i32* %3
br label %112
96: ; preds = %80
%97 = load i32*, i32** %8
%98 = load i64, i64* %9
%99 = add i64 %98, 120
%100 = load i32*, i32** %6
%101 = call i64 @fwrite(i32* %97, i32 4, i64 %99, i32* %100)
store i64 %101, i64* %11
%102 = load i64, i64* %11
%103 = load i64, i64* %9
%104 = add i64 %103, 120
%105 = icmp ne i64 %102, %104
br i1 %105, label %106, label %109
106: ; preds = %96
%107 = load i32, i32* @stderr
%108 = call i32 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.5, i64 0, i64 0), i32 70)
store i32 -1, i32* %3
br label %112
109: ; preds = %96
%110 = load i32*, i32** %6
%111 = call i32 @fclose(i32* %110)
store i32 0, i32* %3
br label %112
112: ; preds = %109, %106, %90, %77, %65, %51, %31, %22
%113 = load i32, i32* %3
ret i32 %113
}

LLVM IR (-O2):
@__const.main.header = [30 x i32] [i32 93, i32 33, i32 81, i32 68, i32 79, i32 83, i32 32, i32 70, i32 105, i32 108, i32 101, i32 32, i32 72, i32 101, i32 97, i32 100, i32 101, i32 114, i32 0, i32 15, i32 0, i32 1, i32 0, i32 0, i32 2, i32 168, i32 0, i32 0, i32 0, i32 0]
@.str = [7 x i8] c"--help\00"
@.str.2 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.3 = [31 x i8] c"Could not open file %s error!\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [30 x i8] c"%s, %d: out of memory error!\0A\00"
@.str.5 = [132 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/linneman/snake/refs/heads/master/addqlh.c\00"
@.str.6 = [38 x i8] c"%s, %d: error while reading file %s!\0A\00"
@.str.7 = [55 x i8] c"header already present, no patch needs to be applied!\0A\00"
@.str.8 = [3 x i8] c"wb\00"
@.str.9 = [30 x i8] c"%s, %d: write error occured!\0A\00"
@str = [43 x i8] c"Invocation: qlh <exec-file to be patched>\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [30 x i32]
%4 = bitcast [30 x i32]* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @strcmp(i8* dereferenceable(1) %8, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %6, %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
br label %65
13: ; preds = %6
%14 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %7
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %18)
br label %65
20: ; preds = %13
%21 = load i32, i32* @SEEK_END
%22 = tail call i32 @fseek(i32* %14, i64 0, i32 %21)
%23 = tail call i64 @ftell(i32* %14)
%24 = load i32, i32* @SEEK_SET
%25 = tail call i32 @fseek(i32* %14, i64 0, i32 %24)
%26 = add i64 %23, 120
%27 = tail call i32* @malloc(i64 %26)
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %32
29: ; preds = %20
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.5, i64 0, i64 0), i32 41)
br label %65
32: ; preds = %20
%33 = getelementptr inbounds i32, i32* %27, i64 120
%34 = tail call i64 @fread(i32* %33, i32 4, i64 %23, i32* %14)
%35 = tail call i32 @fclose(i32* %14)
%36 = icmp eq i64 %34, %23
br i1 %36, label %41, label %37
37: ; preds = %32
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %7
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.5, i64 0, i64 0), i32 49, i8* %39)
br label %65
41: ; preds = %32
%42 = getelementptr inbounds [30 x i32], [30 x i32]* %3, i64 0, i64 0
%43 = call i32 @memcmp(i32* %33, i32* %42, i32 120)
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.7, i64 0, i64 0))
br label %65
48: ; preds = %41
%49 = call i32 @memcpy(i32* %27, i32* %42, i32 120)
%50 = load i8*, i8** %7
%51 = call i32* @fopen(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %57
53: ; preds = %48
%54 = load i32, i32* @stderr
%55 = load i8*, i8** %7
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %55)
br label %65
57: ; preds = %48
%58 = call i64 @fwrite(i32* %27, i32 4, i64 %26, i32* %51)
%59 = icmp eq i64 %58, %26
br i1 %59, label %63, label %60
60: ; preds = %57
%61 = load i32, i32* @stderr
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.5, i64 0, i64 0), i32 70)
br label %65
63: ; preds = %57
%64 = call i32 @fclose(i32* %51)
br label %65
65: ; preds = %63, %60, %53, %45, %37, %29, %16, %11
%66 = phi i32 [ -1, %11 ], [ -1, %16 ], [ -1, %29 ], [ -1, %37 ], [ -1, %53 ], [ -1, %60 ], [ 0, %63 ], [ -1, %45 ]
ret i32 %66
}