#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 HasResourceFork(char *);
int IsResourceFork(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ IsResourceInBinary(int /*<<< orphan*/ *);
scalar_t__ IsResourceInHex(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *strrchr(char *, char);
int IsResourceInFile(char *filename) {
  FILE *f;
  char *spt, *pt;
  int ret;
  f = fopen(filename, "r");
  if (f == NULL)
    return (0);
  spt = strrchr(filename, '/');
  if (spt == NULL)
    spt = filename;
  pt = strrchr(spt, '.');
  if (pt != NULL && (pt[1] == 'b' || pt[1] == 'B') &&
      (pt[2] == 'i' || pt[2] == 'I') && (pt[3] == 'n' || pt[3] == 'N') &&
      pt[4] == '\0') {
    if (IsResourceInBinary(f)) {
      fclose(f);
      return (1);
    }
  } else if (pt != NULL && (pt[1] == 'h' || pt[1] == 'H') &&
             (pt[2] == 'q' || pt[2] == 'Q') && (pt[3] == 'x' || pt[3] == 'X') &&
             pt[4] == '\0') {
    if (IsResourceInHex(f)) {
      fclose(f);
      return (1);
    }
  }
  ret = IsResourceFork(f, 0);
  fclose(f);
  if (!ret)
    ret = HasResourceFork(filename);
  return (ret);
}


x86 assembly (clang, -O0):
<IsResourceInFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a7 <IsResourceInFile+0x37>
movl   $0x0,-0x4(%rbp)
jmp    1374 <IsResourceInFile+0x204>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11cc <IsResourceInFile+0x5c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     128d <IsResourceInFile+0x11d>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x62,%eax
je     120b <IsResourceInFile+0x9b>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x42,%eax
jne    128d <IsResourceInFile+0x11d>
mov    -0x28(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x69,%eax
je     122d <IsResourceInFile+0xbd>
mov    -0x28(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x49,%eax
jne    128d <IsResourceInFile+0x11d>
mov    -0x28(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x6e,%eax
je     124f <IsResourceInFile+0xdf>
mov    -0x28(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x4e,%eax
jne    128d <IsResourceInFile+0x11d>
mov    -0x28(%rbp),%rax
movsbl 0x4(%rax),%eax
cmp    $0x0,%eax
jne    128d <IsResourceInFile+0x11d>
mov    -0x18(%rbp),%rdi
call   1070 <IsResourceInBinary@plt>
cmp    $0x0,%rax
je     1288 <IsResourceInFile+0x118>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1374 <IsResourceInFile+0x204>
jmp    1341 <IsResourceInFile+0x1d1>
cmpq   $0x0,-0x28(%rbp)
je     133c <IsResourceInFile+0x1cc>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x68,%eax
je     12ba <IsResourceInFile+0x14a>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x48,%eax
jne    133c <IsResourceInFile+0x1cc>
mov    -0x28(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x71,%eax
je     12dc <IsResourceInFile+0x16c>
mov    -0x28(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x51,%eax
jne    133c <IsResourceInFile+0x1cc>
mov    -0x28(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x78,%eax
je     12fe <IsResourceInFile+0x18e>
mov    -0x28(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x58,%eax
jne    133c <IsResourceInFile+0x1cc>
mov    -0x28(%rbp),%rax
movsbl 0x4(%rax),%eax
cmp    $0x0,%eax
jne    133c <IsResourceInFile+0x1cc>
mov    -0x18(%rbp),%rdi
call   1080 <IsResourceInHex@plt>
cmp    $0x0,%rax
je     1337 <IsResourceInFile+0x1c7>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1374 <IsResourceInFile+0x204>
jmp    133c <IsResourceInFile+0x1cc>
jmp    1341 <IsResourceInFile+0x1d1>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1050 <IsResourceFork@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0x2c(%rbp)
jne    136e <IsResourceInFile+0x1fe>
mov    -0x10(%rbp),%rdi
call   1090 <HasResourceFork@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IsResourceInFile>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xf1e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1230 <IsResourceInFile+0xc0>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
cmove  %r14,%rax
mov    %rax,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1241 <IsResourceInFile+0xd1>
mov    0x1(%rax),%cl
lea    -0x42(%rcx),%edx
cmp    $0x26,%dl
ja     1241 <IsResourceInFile+0xd1>
movzbl %dl,%edx
lea    0xe32(%rip),%rsi
movslq (%rsi,%rdx,4),%rdx
add    %rsi,%rdx
jmp    *%rdx
mov    0x2(%rax),%dl
or     $0x20,%dl
cmp    $0x69,%dl
jne    11f3 <IsResourceInFile+0x83>
mov    0x3(%rax),%dl
or     $0x20,%dl
cmp    $0x6e,%dl
jne    11f3 <IsResourceInFile+0x83>
cmpb   $0x0,0x4(%rax)
je     1234 <IsResourceInFile+0xc4>
cmp    $0x48,%cl
jne    1241 <IsResourceInFile+0xd1>
mov    0x2(%rax),%cl
or     $0x20,%cl
cmp    $0x71,%cl
jne    1241 <IsResourceInFile+0xd1>
mov    0x3(%rax),%cl
or     $0x20,%cl
cmp    $0x78,%cl
jne    1241 <IsResourceInFile+0xd1>
cmpb   $0x0,0x4(%rax)
jne    1241 <IsResourceInFile+0xd1>
mov    %rbx,%rdi
call   1080 <IsResourceInHex@plt>
test   %rax,%rax
je     1241 <IsResourceInFile+0xd1>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%ebp
jmp    1259 <IsResourceInFile+0xe9>
xor    %ebp,%ebp
jmp    1259 <IsResourceInFile+0xe9>
mov    %rbx,%rdi
call   1070 <IsResourceInBinary@plt>
test   %rax,%rax
jne    1221 <IsResourceInFile+0xb1>
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <IsResourceFork@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %ebp,%ebp
je     1260 <IsResourceInFile+0xf0>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1090 <HasResourceFork@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @IsResourceInFile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 0, i32* %2
br label %141
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i8* @strrchr(i8* %14, i8 signext 47)
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = load i8*, i8** %3
store i8* %19, i8** %5
br label %20
20: ; preds = %18, %13
%21 = load i8*, i8** %5
%22 = call i8* @strrchr(i8* %21, i8 signext 46)
store i8* %22, i8** %6
%23 = load i8*, i8** %6
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %75
25: ; preds = %20
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 98
br i1 %30, label %37, label %31
31: ; preds = %25
%32 = load i8*, i8** %6
%33 = getelementptr inbounds i8, i8* %32, i64 1
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 66
br i1 %36, label %37, label %75
37: ; preds = %31, %25
%38 = load i8*, i8** %6
%39 = getelementptr inbounds i8, i8* %38, i64 2
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 105
br i1 %42, label %49, label %43
43: ; preds = %37
%44 = load i8*, i8** %6
%45 = getelementptr inbounds i8, i8* %44, i64 2
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 73
br i1 %48, label %49, label %75
49: ; preds = %43, %37
%50 = load i8*, i8** %6
%51 = getelementptr inbounds i8, i8* %50, i64 3
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 110
br i1 %54, label %61, label %55
55: ; preds = %49
%56 = load i8*, i8** %6
%57 = getelementptr inbounds i8, i8* %56, i64 3
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 78
br i1 %60, label %61, label %75
61: ; preds = %55, %49
%62 = load i8*, i8** %6
%63 = getelementptr inbounds i8, i8* %62, i64 4
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp eq i32 %65, 0
br i1 %66, label %67, label %75
67: ; preds = %61
%68 = load i32*, i32** %4
%69 = call i64 @IsResourceInBinary(i32* %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %67
%72 = load i32*, i32** %4
%73 = call i32 @fclose(i32* %72)
store i32 1, i32* %2
br label %141
74: ; preds = %67
br label %129
75: ; preds = %61, %55, %43, %31, %20
%76 = load i8*, i8** %6
%77 = icmp ne i8* %76, null
br i1 %77, label %78, label %128
78: ; preds = %75
%79 = load i8*, i8** %6
%80 = getelementptr inbounds i8, i8* %79, i64 1
%81 = load i8, i8* %80
%82 = sext i8 %81 to i32
%83 = icmp eq i32 %82, 104
br i1 %83, label %90, label %84
84: ; preds = %78
%85 = load i8*, i8** %6
%86 = getelementptr inbounds i8, i8* %85, i64 1
%87 = load i8, i8* %86
%88 = sext i8 %87 to i32
%89 = icmp eq i32 %88, 72
br i1 %89, label %90, label %128
90: ; preds = %84, %78
%91 = load i8*, i8** %6
%92 = getelementptr inbounds i8, i8* %91, i64 2
%93 = load i8, i8* %92
%94 = sext i8 %93 to i32
%95 = icmp eq i32 %94, 113
br i1 %95, label %102, label %96
96: ; preds = %90
%97 = load i8*, i8** %6
%98 = getelementptr inbounds i8, i8* %97, i64 2
%99 = load i8, i8* %98
%100 = sext i8 %99 to i32
%101 = icmp eq i32 %100, 81
br i1 %101, label %102, label %128
102: ; preds = %96, %90
%103 = load i8*, i8** %6
%104 = getelementptr inbounds i8, i8* %103, i64 3
%105 = load i8, i8* %104
%106 = sext i8 %105 to i32
%107 = icmp eq i32 %106, 120
br i1 %107, label %114, label %108
108: ; preds = %102
%109 = load i8*, i8** %6
%110 = getelementptr inbounds i8, i8* %109, i64 3
%111 = load i8, i8* %110
%112 = sext i8 %111 to i32
%113 = icmp eq i32 %112, 88
br i1 %113, label %114, label %128
114: ; preds = %108, %102
%115 = load i8*, i8** %6
%116 = getelementptr inbounds i8, i8* %115, i64 4
%117 = load i8, i8* %116
%118 = sext i8 %117 to i32
%119 = icmp eq i32 %118, 0
br i1 %119, label %120, label %128
120: ; preds = %114
%121 = load i32*, i32** %4
%122 = call i64 @IsResourceInHex(i32* %121)
%123 = icmp ne i64 %122, 0
br i1 %123, label %124, label %127
124: ; preds = %120
%125 = load i32*, i32** %4
%126 = call i32 @fclose(i32* %125)
store i32 1, i32* %2
br label %141
127: ; preds = %120
br label %128
128: ; preds = %127, %114, %108, %96, %84, %75
br label %129
129: ; preds = %128, %74
%130 = load i32*, i32** %4
%131 = call i32 @IsResourceFork(i32* %130, i32 0)
store i32 %131, i32* %7
%132 = load i32*, i32** %4
%133 = call i32 @fclose(i32* %132)
%134 = load i32, i32* %7
%135 = icmp ne i32 %134, 0
br i1 %135, label %139, label %136
136: ; preds = %129
%137 = load i8*, i8** %3
%138 = call i32 @HasResourceFork(i8* %137)
store i32 %138, i32* %7
br label %139
139: ; preds = %136, %129
%140 = load i32, i32* %7
store i32 %140, i32* %2
br label %141
141: ; preds = %139, %124, %71, %12
%142 = load i32, i32* %2
ret i32 %142
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @IsResourceInFile(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %51, label %4
4: ; preds = %1
%5 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%6 = icmp eq i8* %5, null
%7 = select i1 %6, i8* %0, i8* %5
%8 = tail call i8* @strrchr(i8* dereferenceable(1) %7, i8 signext 46)
%9 = icmp eq i8* %8, null
br i1 %9, label %45, label %10
10: ; preds = %4
%11 = getelementptr inbounds i8, i8* %8, i64 1
%12 = load i8, i8* %11
switch i8 %12, label %45 [
i8 98, label %13
i8 66, label %13
i8 104, label %30
i8 72, label %30
]
13: ; preds = %10, %10
%14 = getelementptr inbounds i8, i8* %8, i64 2
%15 = load i8, i8* %14
switch i8 %15, label %28 [
i8 105, label %16
i8 73, label %16
]
16: ; preds = %13, %13
%17 = getelementptr inbounds i8, i8* %8, i64 3
%18 = load i8, i8* %17
switch i8 %18, label %28 [
i8 110, label %19
i8 78, label %19
]
19: ; preds = %16, %16
%20 = getelementptr inbounds i8, i8* %8, i64 4
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = tail call i64 @IsResourceInBinary(i32* %2)
%25 = icmp eq i64 %24, 0
br i1 %25, label %45, label %26
26: ; preds = %23
%27 = tail call i32 @fclose(i32* %2)
br label %51
28: ; preds = %19, %13, %16
%29 = icmp eq i8 %12, 72
br i1 %29, label %30, label %45
30: ; preds = %28, %10, %10
%31 = getelementptr inbounds i8, i8* %8, i64 2
%32 = load i8, i8* %31
switch i8 %32, label %45 [
i8 113, label %33
i8 81, label %33
]
33: ; preds = %30, %30
%34 = getelementptr inbounds i8, i8* %8, i64 3
%35 = load i8, i8* %34
switch i8 %35, label %45 [
i8 120, label %36
i8 88, label %36
]
36: ; preds = %33, %33
%37 = getelementptr inbounds i8, i8* %8, i64 4
%38 = load i8, i8* %37
%39 = icmp eq i8 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %36
%41 = tail call i64 @IsResourceInHex(i32* %2)
%42 = icmp eq i64 %41, 0
br i1 %42, label %45, label %43
43: ; preds = %40
%44 = tail call i32 @fclose(i32* %2)
br label %51
45: ; preds = %28, %10, %4, %33, %30, %36, %40, %23
%46 = tail call i32 @IsResourceFork(i32* %2, i32 0)
%47 = tail call i32 @fclose(i32* %2)
%48 = icmp eq i32 %46, 0
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = tail call i32 @HasResourceFork(i8* %0)
br label %51
51: ; preds = %45, %49, %1, %43, %26
%52 = phi i32 [ 1, %26 ], [ 1, %43 ], [ 0, %1 ], [ %46, %45 ], [ %50, %49 ]
ret i32 %52
}