#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*/ FILE;

/* Variables and functions */
long ReadLong(int /*<<< orphan*/ *);
char *ReadName();
int /*<<< orphan*/ SEEK_SET;
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
char *strdup(char *);
scalar_t__ strlen(char *);
char *CheckIfModuleWanted(FILE *z80asmfile, long currentlibmodule,
                          char *modname) {
  long fptr_mname, fptr_expr, fptr_name, fptr_libname;
  char *mname;
  char *name;
  fseek(z80asmfile, currentlibmodule + 4 + 4 + 8 + 2, SEEK_SET);
  fptr_mname = ReadLong(z80asmfile);
  fptr_expr = ReadLong(z80asmfile);
  fptr_name = ReadLong(z80asmfile);
  fptr_libname = ReadLong(z80asmfile);
  fseek(z80asmfile, currentlibmodule + 4 + 4 + fptr_mname, SEEK_SET);
  mname = strdup(ReadName());
  if (strcmp(mname, modname) == 0) {
    return mname;
  }
  if (fptr_name != 0) {
    long end = fptr_libname;
    long red = 0;
    if (fptr_libname == -1) {
      end = fptr_mname;
    }
    fseek(z80asmfile, currentlibmodule + 4 + 4 + fptr_name, SEEK_SET);
    red = fptr_name;
    while (red < end) {
      char scope, type;
      long temp;
      scope = fgetc(z80asmfile);
      red++;
      type = fgetc(z80asmfile);
      red++;
      temp = ReadLong(z80asmfile);
      red += 4;
      name = ReadName();
      red += strlen(name);
      red++;
      if ((scope == 'X' || scope == 'G') && strcmp(name, modname) == 0) {
        return mname;
      }
    }
  }
  free(mname);
  return NULL;
}


x86 assembly (clang, -O0):
<CheckIfModuleWanted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x4,%rsi
add    $0x4,%rsi
add    $0x8,%rsi
add    $0x2,%rsi
mov    0x2e2d(%rip),%rax
mov    (%rax),%edx
call   1090 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1080 <ReadLong@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <ReadLong@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <ReadLong@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <ReadLong@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x4,%rsi
add    $0x4,%rsi
add    -0x28(%rbp),%rsi
mov    0x2dd7(%rip),%rax
mov    (%rax),%edx
call   1090 <fseek@plt>
mov    $0x0,%al
call   1050 <ReadName@plt>
mov    %rax,%rdi
call   10a0 <strdup@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1247 <CheckIfModuleWanted+0xc7>
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1377 <CheckIfModuleWanted+0x1f7>
cmpq   $0x0,-0x38(%rbp)
je     1366 <CheckIfModuleWanted+0x1e6>
mov    -0x40(%rbp),%rax
mov    %rax,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
cmpq   $0xffffffffffffffff,-0x40(%rbp)
jne    1275 <CheckIfModuleWanted+0xf5>
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x4,%rsi
add    $0x4,%rsi
add    -0x38(%rbp),%rsi
mov    0x2d50(%rip),%rax
mov    (%rax),%edx
call   1090 <fseek@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
cmp    -0x58(%rbp),%rax
jge    1361 <CheckIfModuleWanted+0x1e1>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x61(%rbp)
mov    -0x60(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x62(%rbp)
mov    -0x60(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <ReadLong@plt>
mov    %rax,-0x70(%rbp)
mov    -0x60(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x60(%rbp)
mov    $0x0,%al
call   1050 <ReadName@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
add    -0x60(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x60(%rbp)
movsbl -0x61(%rbp),%eax
cmp    $0x58,%eax
je     1338 <CheckIfModuleWanted+0x1b8>
movsbl -0x61(%rbp),%eax
cmp    $0x47,%eax
jne    135c <CheckIfModuleWanted+0x1dc>
mov    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    135c <CheckIfModuleWanted+0x1dc>
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1377 <CheckIfModuleWanted+0x1f7>
jmp    129f <CheckIfModuleWanted+0x11f>
jmp    1366 <CheckIfModuleWanted+0x1e6>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CheckIfModuleWanted>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,%r12
add    $0x12,%rsi
mov    0x2e3e(%rip),%r14
mov    (%r14),%edx
call   1090 <fseek@plt>
mov    %r12,%rdi
call   1080 <ReadLong@plt>
mov    %rax,%r15
mov    %r12,%rdi
call   1080 <ReadLong@plt>
mov    %r12,%rdi
call   1080 <ReadLong@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1080 <ReadLong@plt>
mov    %rax,0x8(%rsp)
lea    (%r15,%rbp,1),%rsi
add    $0x8,%rsi
mov    (%r14),%edx
mov    %r12,%rdi
call   1090 <fseek@plt>
xor    %eax,%eax
call   1050 <ReadName@plt>
mov    %rax,%rdi
call   10a0 <strdup@plt>
mov    %rax,(%rsp)
mov    %rax,%rdi
mov    %r13,0x10(%rsp)
mov    %r13,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12b8 <CheckIfModuleWanted+0x138>
test   %rbx,%rbx
je     12ab <CheckIfModuleWanted+0x12b>
add    $0x8,%rbp
mov    0x8(%rsp),%r14
cmp    $0xffffffffffffffff,%r14
cmovne %r14,%r15
add    %rbx,%rbp
mov    0x2da8(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
mov    %rbp,%rsi
call   1090 <fseek@plt>
jmp    1269 <CheckIfModuleWanted+0xe9>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    0x10(%rsp),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12b8 <CheckIfModuleWanted+0x138>
add    %r14,%rbx
add    $0x7,%rbx
cmp    %r15,%rbx
jge    12ab <CheckIfModuleWanted+0x12b>
mov    %r12,%rdi
call   1060 <fgetc@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1060 <fgetc@plt>
mov    %r12,%rdi
call   1080 <ReadLong@plt>
xor    %eax,%eax
call   1050 <ReadName@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %rax,%r14
cmp    $0x58,%bpl
je     1250 <CheckIfModuleWanted+0xd0>
cmp    $0x47,%bpl
je     1250 <CheckIfModuleWanted+0xd0>
jmp    1262 <CheckIfModuleWanted+0xe2>
mov    (%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    12bc <CheckIfModuleWanted+0x13c>
mov    (%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i8* @CheckIfModuleWanted(i32* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i64
%16 = alloca i8
%17 = alloca i8
%18 = alloca i64
store i32* %0, i32** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%19 = load i32*, i32** %5
%20 = load i64, i64* %6
%21 = add nsw i64 %20, 4
%22 = add nsw i64 %21, 4
%23 = add nsw i64 %22, 8
%24 = add nsw i64 %23, 2
%25 = load i32, i32* @SEEK_SET
%26 = call i32 @fseek(i32* %19, i64 %24, i32 %25)
%27 = load i32*, i32** %5
%28 = call i64 @ReadLong(i32* %27)
store i64 %28, i64* %8
%29 = load i32*, i32** %5
%30 = call i64 @ReadLong(i32* %29)
store i64 %30, i64* %9
%31 = load i32*, i32** %5
%32 = call i64 @ReadLong(i32* %31)
store i64 %32, i64* %10
%33 = load i32*, i32** %5
%34 = call i64 @ReadLong(i32* %33)
store i64 %34, i64* %11
%35 = load i32*, i32** %5
%36 = load i64, i64* %6
%37 = add nsw i64 %36, 4
%38 = add nsw i64 %37, 4
%39 = load i64, i64* %8
%40 = add nsw i64 %38, %39
%41 = load i32, i32* @SEEK_SET
%42 = call i32 @fseek(i32* %35, i64 %40, i32 %41)
%43 = call i8* (...) @ReadName()
%44 = call i8* @strdup(i8* %43)
store i8* %44, i8** %12
%45 = load i8*, i8** %12
%46 = load i8*, i8** %7
%47 = call i64 @strcmp(i8* %45, i8* %46)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %3
%50 = load i8*, i8** %12
store i8* %50, i8** %4
br label %113
51: ; preds = %3
%52 = load i64, i64* %10
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %110
54: ; preds = %51
%55 = load i64, i64* %11
store i64 %55, i64* %14
store i64 0, i64* %15
%56 = load i64, i64* %11
%57 = icmp eq i64 %56, -1
br i1 %57, label %58, label %60
58: ; preds = %54
%59 = load i64, i64* %8
store i64 %59, i64* %14
br label %60
60: ; preds = %58, %54
%61 = load i32*, i32** %5
%62 = load i64, i64* %6
%63 = add nsw i64 %62, 4
%64 = add nsw i64 %63, 4
%65 = load i64, i64* %10
%66 = add nsw i64 %64, %65
%67 = load i32, i32* @SEEK_SET
%68 = call i32 @fseek(i32* %61, i64 %66, i32 %67)
%69 = load i64, i64* %10
store i64 %69, i64* %15
br label %70
70: ; preds = %108, %60
%71 = load i64, i64* %15
%72 = load i64, i64* %14
%73 = icmp slt i64 %71, %72
br i1 %73, label %74, label %109
74: ; preds = %70
%75 = load i32*, i32** %5
%76 = call signext i8 @fgetc(i32* %75)
store i8 %76, i8* %16
%77 = load i64, i64* %15
%78 = add nsw i64 %77, 1
store i64 %78, i64* %15
%79 = load i32*, i32** %5
%80 = call signext i8 @fgetc(i32* %79)
store i8 %80, i8* %17
%81 = load i64, i64* %15
%82 = add nsw i64 %81, 1
store i64 %82, i64* %15
%83 = load i32*, i32** %5
%84 = call i64 @ReadLong(i32* %83)
store i64 %84, i64* %18
%85 = load i64, i64* %15
%86 = add nsw i64 %85, 4
store i64 %86, i64* %15
%87 = call i8* (...) @ReadName()
store i8* %87, i8** %13
%88 = load i8*, i8** %13
%89 = call i64 @strlen(i8* %88)
%90 = load i64, i64* %15
%91 = add nsw i64 %90, %89
store i64 %91, i64* %15
%92 = load i64, i64* %15
%93 = add nsw i64 %92, 1
store i64 %93, i64* %15
%94 = load i8, i8* %16
%95 = sext i8 %94 to i32
%96 = icmp eq i32 %95, 88
br i1 %96, label %101, label %97
97: ; preds = %74
%98 = load i8, i8* %16
%99 = sext i8 %98 to i32
%100 = icmp eq i32 %99, 71
br i1 %100, label %101, label %108
101: ; preds = %97, %74
%102 = load i8*, i8** %13
%103 = load i8*, i8** %7
%104 = call i64 @strcmp(i8* %102, i8* %103)
%105 = icmp eq i64 %104, 0
br i1 %105, label %106, label %108
106: ; preds = %101
%107 = load i8*, i8** %12
store i8* %107, i8** %4
br label %113
108: ; preds = %101, %97
br label %70
109: ; preds = %70
br label %110
110: ; preds = %109, %51
%111 = load i8*, i8** %12
%112 = call i32 @free(i8* %111)
store i8* null, i8** %4
br label %113
113: ; preds = %110, %106, %49
%114 = load i8*, i8** %4
ret i8* %114
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i8* @CheckIfModuleWanted(i32* %0, i64 %1, i8* %2) {
%4 = add nsw i64 %1, 8
%5 = add nsw i64 %1, 18
%6 = load i32, i32* @SEEK_SET
%7 = tail call i32 @fseek(i32* %0, i64 %5, i32 %6)
%8 = tail call i64 @ReadLong(i32* %0)
%9 = tail call i64 @ReadLong(i32* %0)
%10 = tail call i64 @ReadLong(i32* %0)
%11 = tail call i64 @ReadLong(i32* %0)
%12 = add nsw i64 %8, %4
%13 = load i32, i32* @SEEK_SET
%14 = tail call i32 @fseek(i32* %0, i64 %12, i32 %13)
%15 = tail call i8* (...) @ReadName()
%16 = tail call i8* @strdup(i8* %15)
%17 = tail call i64 @strcmp(i8* %16, i8* %2)
%18 = icmp eq i64 %17, 0
br i1 %18, label %44, label %19
19: ; preds = %3
%20 = icmp eq i64 %10, 0
br i1 %20, label %42, label %21
21: ; preds = %19
%22 = icmp eq i64 %11, -1
%23 = select i1 %22, i64 %8, i64 %11
%24 = add nsw i64 %10, %4
%25 = load i32, i32* @SEEK_SET
%26 = tail call i32 @fseek(i32* %0, i64 %24, i32 %25)
%27 = icmp slt i64 %10, %23
br i1 %27, label %28, label %42
28: ; preds = %21, %40
%29 = phi i64 [ %36, %40 ], [ %10, %21 ]
%30 = tail call signext i8 @fgetc(i32* %0)
%31 = tail call signext i8 @fgetc(i32* %0)
%32 = tail call i64 @ReadLong(i32* %0)
%33 = tail call i8* (...) @ReadName()
%34 = tail call i64 @strlen(i8* dereferenceable(1) %33)
%35 = add i64 %29, 7
%36 = add i64 %35, %34
switch i8 %30, label %40 [
i8 88, label %37
i8 71, label %37
]
37: ; preds = %28, %28
%38 = tail call i64 @strcmp(i8* %33, i8* %2)
%39 = icmp eq i64 %38, 0
br i1 %39, label %44, label %40
40: ; preds = %37, %28
%41 = icmp slt i64 %36, %23
br i1 %41, label %28, label %42
42: ; preds = %40, %21, %19
%43 = tail call i32 @free(i8* %16)
br label %44
44: ; preds = %37, %3, %42
%45 = phi i8* [ null, %42 ], [ %16, %3 ], [ %16, %37 ]
ret i8* %45
}