#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;
};
struct ol_backend_os_s {
  int dummy;
};

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ _ol_backend_os_posix_path(struct ol_backend_os_s *, char *,
                                             char *);
scalar_t__ stat(char *, struct stat *);
int ol_backend_os_posix_exists(struct ol_backend_os_s *self, char *name) {
  struct stat file_stat;
  char path[4096];
  _ol_backend_os_posix_path(self, name, path);
  if (stat(path, &file_stat) < 0)
    return 0;
  if (S_ISDIR(file_stat.st_mode))
    return 2;
  else
    return 1;
}


x86 assembly (clang, -O0):
<ol_backend_os_posix_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x1020(%rbp),%rdx
call   1050 <_ol_backend_os_posix_path@plt>
lea    -0x1020(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jge    117d <ol_backend_os_posix_exists+0x4d>
movl   $0x0,-0x4(%rbp)
jmp    11a2 <ol_backend_os_posix_exists+0x72>
mov    -0x20(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     119b <ol_backend_os_posix_exists+0x6b>
movl   $0x2,-0x4(%rbp)
jmp    11a2 <ol_backend_os_posix_exists+0x72>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ol_backend_os_posix_exists>:
push   %rbx
sub    $0x1010,%rsp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdx
call   1050 <_ol_backend_os_posix_path@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <stat@plt>
test   %rax,%rax
js     116e <ol_backend_os_posix_exists+0x3e>
mov    0x8(%rsp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x1,%rax
mov    $0x2,%eax
sbb    $0x0,%eax
jmp    1170 <ol_backend_os_posix_exists+0x40>
xor    %eax,%eax
add    $0x1010,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.ol_backend_os_s = type { i32 }
%struct.stat = type { i32 }
define i32 @ol_backend_os_posix_exists(%struct.ol_backend_os_s* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.ol_backend_os_s*
%5 = alloca i8*
%6 = alloca %struct.stat
%7 = alloca [4096 x i8]
store %struct.ol_backend_os_s* %0, %struct.ol_backend_os_s** %4
store i8* %1, i8** %5
%8 = load %struct.ol_backend_os_s*, %struct.ol_backend_os_s** %4
%9 = load i8*, i8** %5
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%11 = call i32 @_ol_backend_os_posix_path(%struct.ol_backend_os_s* %8, i8* %9, i8* %10)
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%13 = call i64 @stat(i8* %12, %struct.stat* %6)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 0, i32* %3
br label %23
16: ; preds = %2
%17 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i64 @S_ISDIR(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 2, i32* %3
br label %23
22: ; preds = %16
store i32 1, i32* %3
br label %23
23: ; preds = %22, %21, %15
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
%struct.ol_backend_os_s = type { i32 }
%struct.stat = type { i32 }
define i32 @ol_backend_os_posix_exists(%struct.ol_backend_os_s* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = alloca [4096 x i8]
%5 = bitcast %struct.stat* %3 to i8*
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%7 = call i32 @_ol_backend_os_posix_path(%struct.ol_backend_os_s* %0, i8* %1, i8* %6)
%8 = call i64 @stat(i8* %6, %struct.stat* %3)
%9 = icmp slt i64 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%12 = load i32, i32* %11
%13 = call i64 @S_ISDIR(i32 %12)
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, i32 1, i32 2
br label %16
16: ; preds = %10, %2
%17 = phi i32 [ 0, %2 ], [ %15, %10 ]
ret i32 %17
}