#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 IsResourceFork(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int HasResourceFork(char *filename) {
  char *respath = malloc(strlen(filename) + strlen("/rsrc") + 1);
  FILE *temp;
  int ret = 0;
  strcpy(respath, filename);
  strcat(respath, "/rsrc");
  temp = fopen(respath, "r");
  free(respath);
  if (temp != NULL)
    ret = IsResourceFork(temp, 0);
  return (ret);
}


x86 assembly (clang, -O0):
<HasResourceFork>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
lea    0xe70(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xe38(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x18(%rbp)
je     1203 <HasResourceFork+0x93>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1060 <IsResourceFork@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HasResourceFork>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <strlen@plt>
lea    0x6(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
lea    0xe66(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
lea    0xe5d(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
test   %r14,%r14
je     11d2 <HasResourceFork+0x62>
mov    %r14,%rdi
xor    %esi,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <IsResourceFork@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"/rsrc\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @HasResourceFork(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
%8 = call i64 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = add nsw i64 %7, %8
%10 = add nsw i64 %9, 1
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %3
store i32 0, i32* %5
%12 = load i8*, i8** %3
%13 = load i8*, i8** %2
%14 = call i32 @strcpy(i8* %12, i8* %13)
%15 = load i8*, i8** %3
%16 = call i32 @strcat(i8* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%17 = load i8*, i8** %3
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %4
%19 = load i8*, i8** %3
%20 = call i32 @free(i8* %19)
%21 = load i32*, i32** %4
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %1
%24 = load i32*, i32** %4
%25 = call i32 @IsResourceFork(i32* %24, i32 0)
store i32 %25, i32* %5
br label %26
26: ; preds = %23, %1
%27 = load i32, i32* %5
ret i32 %27
}

LLVM IR (-O2):
@.str = [6 x i8] c"/rsrc\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @HasResourceFork(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add nsw i64 %2, 6
%4 = tail call i8* @malloc(i64 %3)
%5 = tail call i32 @strcpy(i8* %4, i8* %0)
%6 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @free(i8* %4)
%9 = icmp eq i32* %7, null
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = tail call i32 @IsResourceFork(i32* %7, i32 0)
br label %12
12: ; preds = %10, %1
%13 = phi i32 [ %11, %10 ], [ 0, %1 ]
ret i32 %13
}