#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*/ ENOENT;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ LOG_NOTICE;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ mkdir(char const *, int);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char const *, ...);
void checkDirectory(const char *imagePath) {
  DIR *imageDir;
  syslog(LOG_NOTICE, "Check if %s exists.", imagePath);
  imageDir = opendir(imagePath);
  if (imageDir) {
    syslog(LOG_NOTICE, "%s found. Continue execting.", imagePath);
    closedir(imageDir);
  } else if (ENOENT == errno) {
    syslog(LOG_NOTICE, "%s not found. Create it and continue execting.",
           imagePath);
    mkdir(imagePath, 0777);
  } else {
    syslog(LOG_ERR, "Error (%d) occured during checking %s. Exiting", errno,
           imagePath);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<checkDirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe90(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
mov    -0x8(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b8 <checkDirectory+0x68>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
mov    -0x10(%rbp),%rdi
call   1050 <closedir@plt>
jmp    1232 <checkDirectory+0xe2>
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
mov    0x2e18(%rip),%rcx
cmp    (%rcx),%eax
jne    11fe <checkDirectory+0xae>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe4d(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
jmp    122d <checkDirectory+0xdd>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
mov    0x2dd2(%rip),%rax
movslq (%rax),%rdx
mov    -0x8(%rbp),%rcx
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1232 <checkDirectory+0xe2>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkDirectory>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2e79(%rip),%r15
mov    (%r15),%edi
lea    0xe97(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <syslog@plt>
mov    %r14,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     11a4 <checkDirectory+0x54>
mov    %rax,%rbx
mov    (%r15),%edi
lea    0xe87(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <syslog@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <closedir@plt>
mov    0x2e1d(%rip),%rax
mov    0x2e2e(%rip),%rcx
movslq (%rcx),%rdx
cmp    %edx,(%rax)
jne    11df <checkDirectory+0x8f>
mov    (%r15),%edi
lea    0xe6e(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <syslog@plt>
mov    %r14,%rdi
mov    $0x1ff,%esi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <mkdir@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
mov    %r14,%rcx
xor    %eax,%eax
call   1060 <syslog@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@LOG_NOTICE = global i32 0
@.str = [20 x i8] c"Check if %s exists.\00"
@.str.1 = [29 x i8] c"%s found. Continue execting.\00"
@ENOENT = global i32 0
@errno = global i32 0
@.str.2 = [47 x i8] c"%s not found. Create it and continue execting.\00"
@LOG_ERR = global i32 0
@.str.3 = [47 x i8] c"Error (%d) occured during checking %s. Exiting\00"
define void @checkDirectory(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = load i32, i32* @LOG_NOTICE
%5 = load i8*, i8** %2
%6 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = load i8*, i8** %2
%8 = call i32* @opendir(i8* %7)
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %17
11: ; preds = %1
%12 = load i32, i32* @LOG_NOTICE
%13 = load i8*, i8** %2
%14 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i32*, i32** %3
%16 = call i32 @closedir(i32* %15)
br label %36
17: ; preds = %1
%18 = load i32, i32* @ENOENT
%19 = load i32, i32* @errno
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %27
21: ; preds = %17
%22 = load i32, i32* @LOG_NOTICE
%23 = load i8*, i8** %2
%24 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %22, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %2
%26 = call i32 @mkdir(i8* %25, i32 511)
br label %35
27: ; preds = %17
%28 = load i32, i32* @LOG_ERR
%29 = load i32, i32* @errno
%30 = sext i32 %29 to i64
%31 = inttoptr i64 %30 to i8*
%32 = load i8*, i8** %2
%33 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %28, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %31, i8* %32)
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %21
br label %36
36: ; preds = %35, %11
ret void
}

LLVM IR (-O2):
@LOG_NOTICE = global i32 0
@.str = [20 x i8] c"Check if %s exists.\00"
@.str.1 = [29 x i8] c"%s found. Continue execting.\00"
@ENOENT = global i32 0
@errno = global i32 0
@.str.2 = [47 x i8] c"%s not found. Create it and continue execting.\00"
@LOG_ERR = global i32 0
@.str.3 = [47 x i8] c"Error (%d) occured during checking %s. Exiting\00"
define void @checkDirectory(i8* %0) {
%2 = load i32, i32* @LOG_NOTICE
%3 = tail call i32 (i32, i8*, i8*, ...) @syslog(i32 %2, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = tail call i32* @opendir(i8* %0)
%5 = icmp eq i32* %4, null
br i1 %5, label %10, label %6
6: ; preds = %1
%7 = load i32, i32* @LOG_NOTICE
%8 = tail call i32 (i32, i8*, i8*, ...) @syslog(i32 %7, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%9 = tail call i32 @closedir(i32* %4)
br label %24
10: ; preds = %1
%11 = load i32, i32* @ENOENT
%12 = load i32, i32* @errno
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i32, i32* @LOG_NOTICE
%16 = tail call i32 (i32, i8*, i8*, ...) @syslog(i32 %15, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%17 = tail call i32 @mkdir(i8* %0, i32 511)
br label %24
18: ; preds = %10
%19 = load i32, i32* @LOG_ERR
%20 = sext i32 %12 to i64
%21 = inttoptr i64 %20 to i8*
%22 = tail call i32 (i32, i8*, i8*, ...) @syslog(i32 %19, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %21, i8* %0)
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %14, %6
ret void
}