#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 /*<<< orphan*/ uint8_t;
struct VM {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ console_printf(char *, char *, int);
scalar_t__ memcmp(int /*<<< orphan*/ const *, char *, int);
int load_header(struct VM *vm, const uint8_t **pos) {
  const uint8_t *p = *pos;
  if (memcmp(p, "RITE0006", 8) != 0) {
    console_printf(
        "<raise> %s:%d\n",
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/mrubyc/mrubyc/refs/heads/master/src/load.c",
        55);
    ;
    return -1;
  }
  if (memcmp(p + 14, "MATZ", 4) != 0) {
    console_printf(
        "<raise> %s:%d\n",
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/mrubyc/mrubyc/refs/heads/master/src/load.c",
        64);
    ;
    return -1;
  }
  if (memcmp(p + 18, "0000", 4) != 0) {
    console_printf(
        "<raise> %s:%d\n",
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/mrubyc/mrubyc/refs/heads/master/src/load.c",
        68);
    ;
    return -1;
  }
  *pos += 22;
  return 0;
}


x86 assembly (clang, -O0):
<load_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xeba(%rip),%rsi
mov    $0x8,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
je     117e <load_header+0x5e>
lea    0xea8(%rip),%rdi
lea    0xeb0(%rip),%rsi
mov    $0x37,%edx
call   1040 <console_printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1221 <load_header+0x101>
mov    -0x20(%rbp),%rdi
add    $0x38,%rdi
lea    0xf10(%rip),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
je     11c5 <load_header+0xa5>
lea    0xe61(%rip),%rdi
lea    0xe69(%rip),%rsi
mov    $0x40,%edx
call   1040 <console_printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1221 <load_header+0x101>
mov    -0x20(%rbp),%rdi
add    $0x48,%rdi
lea    0xece(%rip),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
je     120c <load_header+0xec>
lea    0xe1a(%rip),%rdi
lea    0xe22(%rip),%rsi
mov    $0x44,%edx
call   1040 <console_printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1221 <load_header+0x101>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
add    $0x58,%rcx
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_header>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    (%rsi),%rbx
lea    0xecf(%rip),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
je     1158 <load_header+0x38>
lea    0xebf(%rip),%rdi
lea    0xec7(%rip),%rsi
mov    $0x37,%edx
jmp    11b7 <load_header+0x97>
lea    0x38(%rbx),%rdi
lea    0xf3a(%rip),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
je     1187 <load_header+0x67>
lea    0xe90(%rip),%rdi
lea    0xe98(%rip),%rsi
mov    $0x40,%edx
jmp    11b7 <load_header+0x97>
add    $0x48,%rbx
lea    0xf10(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
je     11c9 <load_header+0xa9>
lea    0xe5e(%rip),%rdi
lea    0xe66(%rip),%rsi
mov    $0x44,%edx
call   1040 <console_printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
addq   $0x58,(%r14)
xor    %eax,%eax
jmp    11c1 <load_header+0xa1>

LLVM IR (-O0):
%struct.VM = type { i32 }
@.str = [9 x i8] c"RITE0006\00"
@.str.1 = [15 x i8] c"<raise> %s:%d\0A\00"
@.str.2 = [133 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/mrubyc/mrubyc/refs/heads/master/src/load.c\00"
@.str.3 = [5 x i8] c"MATZ\00"
@.str.4 = [5 x i8] c"0000\00"
define i32 @load_header(%struct.VM* %0, i32** %1) {
%3 = alloca i32
%4 = alloca %struct.VM*
%5 = alloca i32**
%6 = alloca i32*
store %struct.VM* %0, %struct.VM** %4
store i32** %1, i32*** %5
%7 = load i32**, i32*** %5
%8 = load i32*, i32** %7
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = call i64 @memcmp(i32* %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @console_printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([133 x i8], [133 x i8]* @.str.2, i64 0, i64 0), i32 55)
store i32 -1, i32* %3
br label %32
14: ; preds = %2
%15 = load i32*, i32** %6
%16 = getelementptr inbounds i32, i32* %15, i64 14
%17 = call i64 @memcmp(i32* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 @console_printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([133 x i8], [133 x i8]* @.str.2, i64 0, i64 0), i32 64)
store i32 -1, i32* %3
br label %32
21: ; preds = %14
%22 = load i32*, i32** %6
%23 = getelementptr inbounds i32, i32* %22, i64 18
%24 = call i64 @memcmp(i32* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @console_printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([133 x i8], [133 x i8]* @.str.2, i64 0, i64 0), i32 68)
store i32 -1, i32* %3
br label %32
28: ; preds = %21
%29 = load i32**, i32*** %5
%30 = load i32*, i32** %29
%31 = getelementptr inbounds i32, i32* %30, i64 22
store i32* %31, i32** %29
store i32 0, i32* %3
br label %32
32: ; preds = %28, %26, %19, %12
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
%struct.VM = type { i32 }
@.str = [9 x i8] c"RITE0006\00"
@.str.1 = [15 x i8] c"<raise> %s:%d\0A\00"
@.str.2 = [133 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/mrubyc/mrubyc/refs/heads/master/src/load.c\00"
@.str.3 = [5 x i8] c"MATZ\00"
@.str.4 = [5 x i8] c"0000\00"
define i32 @load_header(%struct.VM* nocapture readnone %0, i32** nocapture %1) {
%3 = load i32*, i32** %1
%4 = tail call i64 @memcmp(i32* %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @console_printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([133 x i8], [133 x i8]* @.str.2, i64 0, i64 0), i32 55)
br label %23
8: ; preds = %2
%9 = getelementptr inbounds i32, i32* %3, i64 14
%10 = tail call i64 @memcmp(i32* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = tail call i32 @console_printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([133 x i8], [133 x i8]* @.str.2, i64 0, i64 0), i32 64)
br label %23
14: ; preds = %8
%15 = getelementptr inbounds i32, i32* %3, i64 18
%16 = tail call i64 @memcmp(i32* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %14
%19 = tail call i32 @console_printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([133 x i8], [133 x i8]* @.str.2, i64 0, i64 0), i32 68)
br label %23
20: ; preds = %14
%21 = load i32*, i32** %1
%22 = getelementptr inbounds i32, i32* %21, i64 22
store i32* %22, i32** %1
br label %23
23: ; preds = %20, %18, %12, %6
%24 = phi i32 [ -1, %6 ], [ -1, %12 ], [ -1, %18 ], [ 0, %20 ]
ret i32 %24
}