#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*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char const *);
bool dir_exists(const char *dir_name) {
  DIR *dir = NULL;
  if ((dir_name == NULL) || (*dir_name == '\0')) {
    return false;
  }
  dir = opendir(dir_name);
  if (dir == NULL) {
    return false;
  }
  {
    if ((dir) != NULL) {
      free((dir));
      (dir) = NULL;
    }
  };
  return (true);
}


x86 assembly (clang, -O0):
<dir_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     114f <dir_exists+0x2f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    115b <dir_exists+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    11a2 <dir_exists+0x82>
mov    -0x10(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117f <dir_exists+0x5f>
movl   $0x0,-0x4(%rbp)
jmp    11a2 <dir_exists+0x82>
cmpq   $0x0,-0x18(%rbp)
je     119b <dir_exists+0x7b>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dir_exists>:
push   %rbx
xor    %ebx,%ebx
test   %rdi,%rdi
je     1144 <dir_exists+0x24>
cmpb   $0x0,(%rdi)
je     1144 <dir_exists+0x24>
call   1040 <opendir@plt>
test   %rax,%rax
je     1144 <dir_exists+0x24>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @dir_exists(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
store i8* %0, i8** %3
store i32* null, i32** %4
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %7, %1
store i32 0, i32* %2
br label %26
13: ; preds = %7
%14 = load i8*, i8** %3
%15 = call i32* @opendir(i8* %14)
store i32* %15, i32** %4
%16 = load i32*, i32** %4
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 0, i32* %2
br label %26
19: ; preds = %13
%20 = load i32*, i32** %4
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32*, i32** %4
%24 = call i32 @free(i32* %23)
store i32* null, i32** %4
br label %25
25: ; preds = %22, %19
store i32 1, i32* %2
br label %26
26: ; preds = %25, %18, %12
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
define i32 @dir_exists(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %11, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = tail call i32* @opendir(i8* %0)
%8 = icmp eq i32* %7, null
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 @free(i32* %7)
br label %11
11: ; preds = %6, %1, %3, %9
%12 = phi i32 [ 1, %9 ], [ 0, %3 ], [ 0, %1 ], [ 0, %6 ]
ret i32 %12
}