#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)) {
      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)) {
      return (1);
    }
  }
  ret = IsResourceFork(f, 0);
  if (!ret) {
    fclose(f);
    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    1362 <IsResourceInFile+0x1f2>
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     1284 <IsResourceInFile+0x114>
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    1284 <IsResourceInFile+0x114>
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    1284 <IsResourceInFile+0x114>
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    1284 <IsResourceInFile+0x114>
mov    -0x28(%rbp),%rax
movsbl 0x4(%rax),%eax
cmp    $0x0,%eax
jne    1284 <IsResourceInFile+0x114>
mov    -0x18(%rbp),%rdi
call   1070 <IsResourceInBinary@plt>
cmp    $0x0,%rax
je     127f <IsResourceInFile+0x10f>
movl   $0x1,-0x4(%rbp)
jmp    1362 <IsResourceInFile+0x1f2>
jmp    132f <IsResourceInFile+0x1bf>
cmpq   $0x0,-0x28(%rbp)
je     132a <IsResourceInFile+0x1ba>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x68,%eax
je     12b1 <IsResourceInFile+0x141>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x48,%eax
jne    132a <IsResourceInFile+0x1ba>
mov    -0x28(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x71,%eax
je     12d3 <IsResourceInFile+0x163>
mov    -0x28(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x51,%eax
jne    132a <IsResourceInFile+0x1ba>
mov    -0x28(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x78,%eax
je     12f5 <IsResourceInFile+0x185>
mov    -0x28(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x58,%eax
jne    132a <IsResourceInFile+0x1ba>
mov    -0x28(%rbp),%rax
movsbl 0x4(%rax),%eax
cmp    $0x0,%eax
jne    132a <IsResourceInFile+0x1ba>
mov    -0x18(%rbp),%rdi
call   1080 <IsResourceInHex@plt>
cmp    $0x0,%rax
je     1325 <IsResourceInFile+0x1b5>
movl   $0x1,-0x4(%rbp)
jmp    1362 <IsResourceInFile+0x1f2>
jmp    132a <IsResourceInFile+0x1ba>
jmp    132f <IsResourceInFile+0x1bf>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1050 <IsResourceFork@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    135c <IsResourceInFile+0x1ec>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
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   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xf1e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     121a <IsResourceInFile+0xaa>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
cmove  %rbx,%rax
mov    %rax,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1233 <IsResourceInFile+0xc3>
mov    0x1(%rax),%cl
lea    -0x42(%rcx),%edx
cmp    $0x26,%dl
ja     1233 <IsResourceInFile+0xc3>
movzbl %dl,%edx
lea    0xe36(%rip),%rsi
movslq (%rsi,%rdx,4),%rdx
add    %rsi,%rdx
jmp    *%rdx
mov    0x2(%rax),%dl
or     $0x20,%dl
cmp    $0x69,%dl
jne    11ef <IsResourceInFile+0x7f>
mov    0x3(%rax),%dl
or     $0x20,%dl
cmp    $0x6e,%dl
jne    11ef <IsResourceInFile+0x7f>
cmpb   $0x0,0x4(%rax)
je     121e <IsResourceInFile+0xae>
cmp    $0x48,%cl
jne    1233 <IsResourceInFile+0xc3>
mov    0x2(%rax),%cl
or     $0x20,%cl
cmp    $0x71,%cl
jne    1233 <IsResourceInFile+0xc3>
mov    0x3(%rax),%cl
or     $0x20,%cl
cmp    $0x78,%cl
jne    1233 <IsResourceInFile+0xc3>
cmpb   $0x0,0x4(%rax)
jne    1233 <IsResourceInFile+0xc3>
mov    %r14,%rdi
call   1080 <IsResourceInHex@plt>
jmp    1226 <IsResourceInFile+0xb6>
xor    %eax,%eax
jmp    1241 <IsResourceInFile+0xd1>
mov    %r14,%rdi
call   1070 <IsResourceInBinary@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    1241 <IsResourceInFile+0xd1>
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <IsResourceFork@plt>
test   %eax,%eax
je     1249 <IsResourceInFile+0xd9>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
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 %137
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 %73
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 %73
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 %73
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 %73
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 %73
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 %72
71: ; preds = %67
store i32 1, i32* %2
br label %137
72: ; preds = %67
br label %125
73: ; preds = %61, %55, %43, %31, %20
%74 = load i8*, i8** %6
%75 = icmp ne i8* %74, null
br i1 %75, label %76, label %124
76: ; preds = %73
%77 = load i8*, i8** %6
%78 = getelementptr inbounds i8, i8* %77, i64 1
%79 = load i8, i8* %78
%80 = sext i8 %79 to i32
%81 = icmp eq i32 %80, 104
br i1 %81, label %88, label %82
82: ; preds = %76
%83 = load i8*, i8** %6
%84 = getelementptr inbounds i8, i8* %83, i64 1
%85 = load i8, i8* %84
%86 = sext i8 %85 to i32
%87 = icmp eq i32 %86, 72
br i1 %87, label %88, label %124
88: ; preds = %82, %76
%89 = load i8*, i8** %6
%90 = getelementptr inbounds i8, i8* %89, i64 2
%91 = load i8, i8* %90
%92 = sext i8 %91 to i32
%93 = icmp eq i32 %92, 113
br i1 %93, label %100, label %94
94: ; preds = %88
%95 = load i8*, i8** %6
%96 = getelementptr inbounds i8, i8* %95, i64 2
%97 = load i8, i8* %96
%98 = sext i8 %97 to i32
%99 = icmp eq i32 %98, 81
br i1 %99, label %100, label %124
100: ; preds = %94, %88
%101 = load i8*, i8** %6
%102 = getelementptr inbounds i8, i8* %101, i64 3
%103 = load i8, i8* %102
%104 = sext i8 %103 to i32
%105 = icmp eq i32 %104, 120
br i1 %105, label %112, label %106
106: ; preds = %100
%107 = load i8*, i8** %6
%108 = getelementptr inbounds i8, i8* %107, i64 3
%109 = load i8, i8* %108
%110 = sext i8 %109 to i32
%111 = icmp eq i32 %110, 88
br i1 %111, label %112, label %124
112: ; preds = %106, %100
%113 = load i8*, i8** %6
%114 = getelementptr inbounds i8, i8* %113, i64 4
%115 = load i8, i8* %114
%116 = sext i8 %115 to i32
%117 = icmp eq i32 %116, 0
br i1 %117, label %118, label %124
118: ; preds = %112
%119 = load i32*, i32** %4
%120 = call i64 @IsResourceInHex(i32* %119)
%121 = icmp ne i64 %120, 0
br i1 %121, label %122, label %123
122: ; preds = %118
store i32 1, i32* %2
br label %137
123: ; preds = %118
br label %124
124: ; preds = %123, %112, %106, %94, %82, %73
br label %125
125: ; preds = %124, %72
%126 = load i32*, i32** %4
%127 = call i32 @IsResourceFork(i32* %126, i32 0)
store i32 %127, i32* %7
%128 = load i32, i32* %7
%129 = icmp ne i32 %128, 0
br i1 %129, label %135, label %130
130: ; preds = %125
%131 = load i32*, i32** %4
%132 = call i32 @fclose(i32* %131)
%133 = load i8*, i8** %3
%134 = call i32 @HasResourceFork(i8* %133)
store i32 %134, i32* %7
br label %135
135: ; preds = %130, %125
%136 = load i32, i32* %7
store i32 %136, i32* %2
br label %137
137: ; preds = %135, %122, %71, %12
%138 = load i32, i32* %2
ret i32 %138
}

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 %47, 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 %41, label %10
10: ; preds = %4
%11 = getelementptr inbounds i8, i8* %8, i64 1
%12 = load i8, i8* %11
switch i8 %12, label %41 [
i8 98, label %13
i8 66, label %13
i8 104, label %28
i8 72, label %28
]
13: ; preds = %10, %10
%14 = getelementptr inbounds i8, i8* %8, i64 2
%15 = load i8, i8* %14
switch i8 %15, label %26 [
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 %26 [
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 %26
23: ; preds = %19
%24 = tail call i64 @IsResourceInBinary(i32* %2)
%25 = icmp eq i64 %24, 0
br i1 %25, label %41, label %47
26: ; preds = %19, %13, %16
%27 = icmp eq i8 %12, 72
br i1 %27, label %28, label %41
28: ; preds = %26, %10, %10
%29 = getelementptr inbounds i8, i8* %8, i64 2
%30 = load i8, i8* %29
switch i8 %30, label %41 [
i8 113, label %31
i8 81, label %31
]
31: ; preds = %28, %28
%32 = getelementptr inbounds i8, i8* %8, i64 3
%33 = load i8, i8* %32
switch i8 %33, label %41 [
i8 120, label %34
i8 88, label %34
]
34: ; preds = %31, %31
%35 = getelementptr inbounds i8, i8* %8, i64 4
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = tail call i64 @IsResourceInHex(i32* %2)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %26, %10, %4, %31, %28, %34, %38, %23
%42 = tail call i32 @IsResourceFork(i32* %2, i32 0)
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = tail call i32 @fclose(i32* %2)
%46 = tail call i32 @HasResourceFork(i8* %0)
br label %47
47: ; preds = %41, %44, %38, %23, %1
%48 = phi i32 [ 0, %1 ], [ 1, %23 ], [ 1, %38 ], [ %42, %41 ], [ %46, %44 ]
ret i32 %48
}