#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 */
struct stat {
  int st_mode;
};

/* Variables and functions */
int S_IFDIR;
char const *epk_archive_get_name();
scalar_t__ stat(char const *, struct stat *);
int epk_archive_exists(const char *dir) {
  struct stat statbuf;
  int is_dir = ((stat(dir ? dir : epk_archive_get_name(), &statbuf) == 0) &&
                (statbuf.st_mode & S_IFDIR));
  return is_dir;
}


x86 assembly (clang, -O0):
<epk_archive_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1144 <epk_archive_exists+0x24>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    114f <epk_archive_exists+0x2f>
mov    $0x0,%al
call   1030 <epk_archive_get_name@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <stat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
jne    1183 <epk_archive_exists+0x63>
mov    -0x10(%rbp),%eax
mov    0x2e60(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<epk_archive_exists>:
push   %rax
test   %rdi,%rdi
jne    1130 <epk_archive_exists+0x10>
xor    %eax,%eax
call   1030 <epk_archive_get_name@plt>
mov    %rax,%rdi
mov    %rsp,%rsi
call   1040 <stat@plt>
test   %rax,%rax
sete   %al
mov    0x2e93(%rip),%rcx
mov    (%rcx),%ecx
and    (%rsp),%ecx
setne  %cl
and    %al,%cl
movzbl %cl,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@S_IFDIR = global i32 0
define i32 @epk_archive_exists(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load i8*, i8** %2
br label %11
9: ; preds = %1
%10 = call i8* (...) @epk_archive_get_name()
br label %11
11: ; preds = %9, %7
%12 = phi i8* [ %8, %7 ], [ %10, %9 ]
%13 = call i64 @stat(i8* %12, %struct.stat* %3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%17 = load i32, i32* %16
%18 = load i32, i32* @S_IFDIR
%19 = and i32 %17, %18
%20 = icmp ne i32 %19, 0
br label %21
21: ; preds = %15, %11
%22 = phi i1 [ false, %11 ], [ %20, %15 ]
%23 = zext i1 %22 to i32
store i32 %23, i32* %4
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@S_IFDIR = global i32 0
define i32 @epk_archive_exists(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i8* (...) @epk_archive_get_name()
br label %7
7: ; preds = %1, %5
%8 = phi i8* [ %6, %5 ], [ %0, %1 ]
%9 = call i64 @stat(i8* %8, %struct.stat* %2)
%10 = icmp eq i64 %9, 0
%11 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%12 = load i32, i32* %11
%13 = load i32, i32* @S_IFDIR
%14 = and i32 %13, %12
%15 = icmp ne i32 %14, 0
%16 = select i1 %10, i1 %15, i1 false
%17 = zext i1 %16 to i32
ret i32 %17
}