#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 /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ ENOENT;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
scalar_t__ errno;
int stat(char const *, struct stat *);
scalar_t__ strcmp(char const *, char *);
bool object_exists(const char *path, const char *type) {
  struct stat s;
  if (stat(path, &s) == -1) {
    if (ENOENT == errno) {
      return false;
    } else {
      return false;
    }
  } else {
    if (strcmp(type, "dir") == 0 && S_ISDIR(s.st_mode)) {
      return true;
    } else if (strcmp(type, "file") == 0 && S_ISREG(s.st_mode)) {
      return true;
    } else {
      return false;
    }
  }
}


x86 assembly (clang, -O0):
<object_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
jne    1198 <object_exists+0x58>
mov    0x2e63(%rip),%rax
mov    (%rax),%rax
mov    0x2e69(%rip),%rcx
cmp    (%rcx),%rax
jne    118c <object_exists+0x4c>
movl   $0x0,-0x4(%rbp)
jmp    120f <object_exists+0xcf>
movl   $0x0,-0x4(%rbp)
jmp    120f <object_exists+0xcf>
mov    -0x18(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11d0 <object_exists+0x90>
mov    -0x20(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11d0 <object_exists+0x90>
movl   $0x1,-0x4(%rbp)
jmp    120f <object_exists+0xcf>
mov    -0x18(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1208 <object_exists+0xc8>
mov    -0x20(%rbp),%edi
call   1060 <S_ISREG@plt>
cmp    $0x0,%rax
je     1208 <object_exists+0xc8>
movl   $0x1,-0x4(%rbp)
jmp    120f <object_exists+0xcf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<object_exists>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     11b3 <object_exists+0x73>
lea    0xe9e(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     119d <object_exists+0x5d>
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1199 <object_exists+0x59>
mov    0x8(%rsp),%edi
call   1060 <S_ISREG@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    11b3 <object_exists+0x73>
xor    %eax,%eax
jmp    11b3 <object_exists+0x73>
mov    0x8(%rsp),%edi
call   1030 <S_ISDIR@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
je     116f <object_exists+0x2f>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@ENOENT = global i64 0
@errno = global i64 0
@.str = [4 x i8] c"dir\00"
@.str.1 = [5 x i8] c"file\00"
define i32 @object_exists(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.stat
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = call i32 @stat(i8* %7, %struct.stat* %6)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i64, i64* @ENOENT
%12 = load i64, i64* @errno
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %10
store i32 0, i32* %3
br label %37
15: ; preds = %10
store i32 0, i32* %3
br label %37
16: ; preds = %2
%17 = load i8*, i8** %5
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i64 @S_ISDIR(i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 1, i32* %3
br label %37
26: ; preds = %20, %16
%27 = load i8*, i8** %5
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %26
%31 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%32 = load i32, i32* %31
%33 = call i64 @S_ISREG(i32 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %30
store i32 1, i32* %3
br label %37
36: ; preds = %30, %26
store i32 0, i32* %3
br label %37
37: ; preds = %36, %35, %25, %15, %14
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@ENOENT = global i64 0
@errno = global i64 0
@.str = [4 x i8] c"dir\00"
@.str.1 = [5 x i8] c"file\00"
define i32 @object_exists(i8* nocapture %0, i8* %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = call i32 @stat(i8* %0, %struct.stat* %3)
%6 = icmp eq i32 %5, -1
br i1 %6, label %24, label %7
7: ; preds = %2
%8 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%12 = load i32, i32* %11
%13 = tail call i64 @S_ISDIR(i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %10, %7
%16 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%20 = load i32, i32* %19
%21 = tail call i64 @S_ISREG(i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18, %15
br label %24
24: ; preds = %18, %10, %2, %23
%25 = phi i32 [ 0, %23 ], [ 0, %2 ], [ 1, %10 ], [ 1, %18 ]
ret i32 %25
}