#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 */
int checkXrefTable(int /*<<< orphan*/ *);
int /*<<< orphan*/ displayResult(short, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
short hasAcceptableSize(int /*<<< orphan*/ *);
short hasCorrectPDFVersion(int /*<<< orphan*/ *);
short hasCorrectSignature(int /*<<< orphan*/ *);
short hasImageHexcode(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
short producerStringPresent(int /*<<< orphan*/ *);
short producerStringWithXrefEntries(int /*<<< orphan*/ *, int);
short trailerContainsHTML(int /*<<< orphan*/ *);
void _mods(const char *path) {
  FILE *fptr = fopen(path, "rb");
  printf(" -- Module test --\n");
  short b = hasAcceptableSize(fptr);
  displayResult(b, "File size");
  if (b == 0) {
    printf("Wrong file size; ending before further checks.\n\n");
    return;
  }
  short a = producerStringPresent(fptr);
  displayResult(a, "Producer string");
  short h = 0;
  if (a == 0) {
    h = trailerContainsHTML(fptr);
    displayResult(h, " -> HTML trailer");
  }
  int xRefLen = 0;
  if (h == 0) {
    xRefLen = checkXrefTable(fptr);
    printf("xref length: %d\n", xRefLen);
  }
  short p = 0;
  if (!h && xRefLen != 0) {
    p = producerStringWithXrefEntries(fptr, xRefLen);
    displayResult(p, "Producer string with offset");
  }
  short c = hasCorrectPDFVersion(fptr);
  displayResult(c, "PDF 1.4");
  short d = hasCorrectSignature(fptr);
  displayResult(d, "PDF signature");
  short e = hasImageHexcode(fptr);
  displayResult(e, "Image hex");
  printf("Score: %d\n", (a + b + c + d + e + p));
  fclose(fptr);
}


x86 assembly (clang, -O0):
<_mods>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   10c0 <hasAcceptableSize@plt>
mov    %ax,-0x12(%rbp)
lea    0xe15(%rip),%rsi
movswl -0x12(%rbp),%edi
call   1060 <displayResult@plt>
movswl -0x12(%rbp),%eax
cmp    $0x0,%eax
jne    122b <_mods+0x6b>
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1374 <_mods+0x1b4>
mov    -0x10(%rbp),%rdi
call   1030 <producerStringPresent@plt>
mov    %ax,-0x14(%rbp)
lea    0xe13(%rip),%rsi
movswl -0x14(%rbp),%edi
call   1060 <displayResult@plt>
movw   $0x0,-0x16(%rbp)
movswl -0x14(%rbp),%eax
cmp    $0x0,%eax
jne    1278 <_mods+0xb8>
mov    -0x10(%rbp),%rdi
call   10d0 <trailerContainsHTML@plt>
mov    %ax,-0x16(%rbp)
lea    0xdf3(%rip),%rsi
movswl -0x16(%rbp),%edi
call   1060 <displayResult@plt>
movl   $0x0,-0x1c(%rbp)
movswl -0x16(%rbp),%eax
cmp    $0x0,%eax
jne    12a9 <_mods+0xe9>
mov    -0x10(%rbp),%rdi
call   1080 <checkXrefTable@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movw   $0x0,-0x1e(%rbp)
cmpw   $0x0,-0x16(%rbp)
jne    12e4 <_mods+0x124>
cmpl   $0x0,-0x1c(%rbp)
je     12e4 <_mods+0x124>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10a0 <producerStringWithXrefEntries@plt>
mov    %ax,-0x1e(%rbp)
lea    0xda9(%rip),%rsi
movswl -0x1e(%rbp),%edi
call   1060 <displayResult@plt>
mov    -0x10(%rbp),%rdi
call   1070 <hasCorrectPDFVersion@plt>
mov    %ax,-0x20(%rbp)
lea    0xda8(%rip),%rsi
movswl -0x20(%rbp),%edi
call   1060 <displayResult@plt>
mov    -0x10(%rbp),%rdi
call   10b0 <hasCorrectSignature@plt>
mov    %ax,-0x22(%rbp)
lea    0xd93(%rip),%rsi
movswl -0x22(%rbp),%edi
call   1060 <displayResult@plt>
mov    -0x10(%rbp),%rdi
call   1090 <hasImageHexcode@plt>
mov    %ax,-0x24(%rbp)
lea    0xd84(%rip),%rsi
movswl -0x24(%rbp),%edi
call   1060 <displayResult@plt>
movswl -0x14(%rbp),%esi
movswl -0x12(%rbp),%eax
add    %eax,%esi
movswl -0x20(%rbp),%eax
add    %eax,%esi
movswl -0x22(%rbp),%eax
add    %eax,%esi
movswl -0x24(%rbp),%eax
add    %eax,%esi
movswl -0x1e(%rbp),%eax
add    %eax,%esi
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_mods>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe1e(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,%r13
lea    0xe95(%rip),%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
call   10d0 <hasAcceptableSize@plt>
movswl %ax,%ebx
lea    0xdfb(%rip),%rsi
mov    %ebx,%edi
call   1070 <displayResult@plt>
test   %bx,%bx
je     131d <_mods+0x14d>
mov    %ebx,0x4(%rsp)
mov    %r13,%rdi
call   1030 <producerStringPresent@plt>
movswl %ax,%ebp
lea    0xddf(%rip),%rsi
mov    %ebp,%edi
call   1070 <displayResult@plt>
test   %bp,%bp
jne    125b <_mods+0x8b>
mov    %r13,%rdi
call   10e0 <trailerContainsHTML@plt>
movswl %ax,%ebx
lea    0xdd1(%rip),%rsi
mov    %ebx,%edi
call   1070 <displayResult@plt>
xor    %r14d,%r14d
test   %bx,%bx
jne    1299 <_mods+0xc9>
mov    %r13,%rdi
call   1090 <checkXrefTable@plt>
mov    %eax,%ebx
lea    0xdc2(%rip),%rdi
xor    %r14d,%r14d
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
test   %ebx,%ebx
je     1299 <_mods+0xc9>
mov    %r13,%rdi
mov    %ebx,%esi
call   10b0 <producerStringWithXrefEntries@plt>
movswl %ax,%r14d
lea    0xdae(%rip),%rsi
mov    %r14d,%edi
call   1070 <displayResult@plt>
mov    %r13,%rdi
call   1080 <hasCorrectPDFVersion@plt>
movswl %ax,%r12d
lea    0xdaf(%rip),%rsi
mov    %r12d,%edi
call   1070 <displayResult@plt>
mov    %r13,%rdi
call   10c0 <hasCorrectSignature@plt>
movswl %ax,%ebx
lea    0xd9d(%rip),%rsi
mov    %ebx,%edi
call   1070 <displayResult@plt>
mov    %r13,%rdi
call   10a0 <hasImageHexcode@plt>
movswl %ax,%r15d
lea    0xd91(%rip),%rsi
mov    %r15d,%edi
call   1070 <displayResult@plt>
add    0x4(%rsp),%ebp
add    %r14d,%ebp
add    %r12d,%ebp
add    %ebx,%ebp
add    %r15d,%ebp
lea    0xd7d(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fclose@plt>
lea    0xd75(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [20 x i8] c" -- Module test --\0A\00"
@.str.2 = [10 x i8] c"File size\00"
@.str.3 = [49 x i8] c"Wrong file size; ending before further checks.\0A\0A\00"
@.str.4 = [16 x i8] c"Producer string\00"
@.str.5 = [17 x i8] c" -> HTML trailer\00"
@.str.6 = [17 x i8] c"xref length: %d\0A\00"
@.str.7 = [28 x i8] c"Producer string with offset\00"
@.str.8 = [8 x i8] c"PDF 1.4\00"
@.str.9 = [14 x i8] c"PDF signature\00"
@.str.10 = [10 x i8] c"Image hex\00"
@.str.11 = [11 x i8] c"Score: %d\0A\00"
define void @_mods(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i16
%5 = alloca i16
%6 = alloca i16
%7 = alloca i32
%8 = alloca i16
%9 = alloca i16
%10 = alloca i16
%11 = alloca i16
store i8* %0, i8** %2
%12 = load i8*, i8** %2
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %3
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32*, i32** %3
%16 = call signext i16 @hasAcceptableSize(i32* %15)
store i16 %16, i16* %4
%17 = load i16, i16* %4
%18 = call i32 @displayResult(i16 signext %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%19 = load i16, i16* %4
%20 = sext i16 %19 to i32
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %1
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
br label %91
24: ; preds = %1
%25 = load i32*, i32** %3
%26 = call signext i16 @producerStringPresent(i32* %25)
store i16 %26, i16* %5
%27 = load i16, i16* %5
%28 = call i32 @displayResult(i16 signext %27, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
store i16 0, i16* %6
%29 = load i16, i16* %5
%30 = sext i16 %29 to i32
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %24
%33 = load i32*, i32** %3
%34 = call signext i16 @trailerContainsHTML(i32* %33)
store i16 %34, i16* %6
%35 = load i16, i16* %6
%36 = call i32 @displayResult(i16 signext %35, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %37
37: ; preds = %32, %24
store i32 0, i32* %7
%38 = load i16, i16* %6
%39 = sext i16 %38 to i32
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %37
%42 = load i32*, i32** %3
%43 = call i32 @checkXrefTable(i32* %42)
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %41, %37
store i16 0, i16* %8
%47 = load i16, i16* %6
%48 = icmp ne i16 %47, 0
br i1 %48, label %58, label %49
49: ; preds = %46
%50 = load i32, i32* %7
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %58
52: ; preds = %49
%53 = load i32*, i32** %3
%54 = load i32, i32* %7
%55 = call signext i16 @producerStringWithXrefEntries(i32* %53, i32 %54)
store i16 %55, i16* %8
%56 = load i16, i16* %8
%57 = call i32 @displayResult(i16 signext %56, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
br label %58
58: ; preds = %52, %49, %46
%59 = load i32*, i32** %3
%60 = call signext i16 @hasCorrectPDFVersion(i32* %59)
store i16 %60, i16* %9
%61 = load i16, i16* %9
%62 = call i32 @displayResult(i16 signext %61, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%63 = load i32*, i32** %3
%64 = call signext i16 @hasCorrectSignature(i32* %63)
store i16 %64, i16* %10
%65 = load i16, i16* %10
%66 = call i32 @displayResult(i16 signext %65, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
%67 = load i32*, i32** %3
%68 = call signext i16 @hasImageHexcode(i32* %67)
store i16 %68, i16* %11
%69 = load i16, i16* %11
%70 = call i32 @displayResult(i16 signext %69, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0))
%71 = load i16, i16* %5
%72 = sext i16 %71 to i32
%73 = load i16, i16* %4
%74 = sext i16 %73 to i32
%75 = add nsw i32 %72, %74
%76 = load i16, i16* %9
%77 = sext i16 %76 to i32
%78 = add nsw i32 %75, %77
%79 = load i16, i16* %10
%80 = sext i16 %79 to i32
%81 = add nsw i32 %78, %80
%82 = load i16, i16* %11
%83 = sext i16 %82 to i32
%84 = add nsw i32 %81, %83
%85 = load i16, i16* %8
%86 = sext i16 %85 to i32
%87 = add nsw i32 %84, %86
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), i32 %87)
%89 = load i32*, i32** %3
%90 = call i32 @fclose(i32* %89)
br label %91
91: ; preds = %58, %22
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.2 = [10 x i8] c"File size\00"
@.str.4 = [16 x i8] c"Producer string\00"
@.str.5 = [17 x i8] c" -> HTML trailer\00"
@.str.6 = [17 x i8] c"xref length: %d\0A\00"
@.str.7 = [28 x i8] c"Producer string with offset\00"
@.str.8 = [8 x i8] c"PDF 1.4\00"
@.str.9 = [14 x i8] c"PDF signature\00"
@.str.10 = [10 x i8] c"Image hex\00"
@.str.11 = [11 x i8] c"Score: %d\0A\00"
@str = [19 x i8] c" -- Module test --\00"
@str.12 = [48 x i8] c"Wrong file size; ending before further checks.\0A\00"
define void @_mods(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%4 = tail call signext i16 @hasAcceptableSize(i32* %2)
%5 = tail call i32 @displayResult(i16 signext %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%6 = sext i16 %4 to i32
%7 = icmp eq i16 %4, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.12, i64 0, i64 0))
br label %45
10: ; preds = %1
%11 = tail call signext i16 @producerStringPresent(i32* %2)
%12 = tail call i32 @displayResult(i16 signext %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%13 = sext i16 %11 to i32
%14 = icmp eq i16 %11, 0
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = tail call signext i16 @trailerContainsHTML(i32* %2)
%17 = tail call i32 @displayResult(i16 signext %16, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%18 = icmp eq i16 %16, 0
br i1 %18, label %19, label %27
19: ; preds = %10, %15
%20 = tail call i32 @checkXrefTable(i32* %2)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %20)
%22 = icmp eq i32 %20, 0
br i1 %22, label %27, label %23
23: ; preds = %19
%24 = tail call signext i16 @producerStringWithXrefEntries(i32* %2, i32 %20)
%25 = tail call i32 @displayResult(i16 signext %24, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
%26 = sext i16 %24 to i32
br label %27
27: ; preds = %15, %23, %19
%28 = phi i32 [ %26, %23 ], [ 0, %19 ], [ 0, %15 ]
%29 = tail call signext i16 @hasCorrectPDFVersion(i32* %2)
%30 = tail call i32 @displayResult(i16 signext %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%31 = tail call signext i16 @hasCorrectSignature(i32* %2)
%32 = tail call i32 @displayResult(i16 signext %31, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
%33 = tail call signext i16 @hasImageHexcode(i32* %2)
%34 = tail call i32 @displayResult(i16 signext %33, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0))
%35 = add nsw i32 %13, %6
%36 = sext i16 %29 to i32
%37 = sext i16 %31 to i32
%38 = sext i16 %33 to i32
%39 = add nsw i32 %35, %28
%40 = add nsw i32 %39, %36
%41 = add nsw i32 %40, %37
%42 = add nsw i32 %41, %38
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), i32 %42)
%44 = tail call i32 @fclose(i32* %2)
br label %45
45: ; preds = %27, %8
ret void
}