#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 /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcat(char *, char *);
int isFileExist(char *fileName, char *currDir) {
  char *finalDir;
  finalDir = (char *)malloc(512 * sizeof(char));
  memset(finalDir, 0, 512);
  strcat(finalDir, fileName);
  FILE *file = fopen(finalDir, "r+");
  if (file) {
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<isFileExist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x200,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1030 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xe7a(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11a6 <isFileExist+0x66>
movl   $0x1,-0x4(%rbp)
jmp    11ad <isFileExist+0x6d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isFileExist>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x200,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1030 <memset@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"r+\00"
define i32 @isFileExist(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = call i64 @malloc(i32 512)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = call i32 @memset(i8* %10, i32 0, i32 512)
%12 = load i8*, i8** %6
%13 = load i8*, i8** %4
%14 = call i32 @strcat(i8* %12, i8* %13)
%15 = load i8*, i8** %6
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %7
%17 = load i32*, i32** %7
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %2
store i32 1, i32* %3
br label %21
20: ; preds = %2
store i32 0, i32* %3
br label %21
21: ; preds = %20, %19
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@.str = [3 x i8] c"r+\00"
define i32 @isFileExist(i8* %0, i8* nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 512)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @memset(i8* %4, i32 0, i32 512)
%6 = tail call i32 @strcat(i8* %4, i8* %0)
%7 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp ne i32* %7, null
%9 = zext i1 %8 to i32
ret i32 %9
}