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

/* Variables and functions */
int EPERM;
int errno;
int /*<<< orphan*/ fileExists(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
scalar_t__ mkdir(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int check_and_mk_log_dir(const char *base_path) {
  char data_path[256];
  snprintf(data_path, sizeof(data_path), "%s/logs", base_path);
  if (!fileExists(data_path)) {
    if (mkdir(data_path, 0755) != 0) {
      fprintf(stderr,
              "mkdir \"%s\" fail, "
              "errno: %d, error info: %s",
              data_path, errno,
              (strerror(errno) != NULL ? strerror(errno) : "Unkown error"));
      return errno != 0 ? errno : EPERM;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_and_mk_log_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x100,%esi
lea    0xe8a(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <fileExists@plt>
cmp    $0x0,%eax
jne    1288 <check_and_mk_log_dir+0x138>
lea    -0x110(%rbp),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
je     1283 <check_and_mk_log_dir+0x133>
mov    0x2e2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x124(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x120(%rbp)
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x114(%rbp)
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
cmp    $0x0,%rax
je     1209 <check_and_mk_log_dir+0xb9>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %rax,-0x130(%rbp)
jmp    121c <check_and_mk_log_dir+0xcc>
lea    0xe23(%rip),%rax
mov    %rax,-0x130(%rbp)
jmp    121c <check_and_mk_log_dir+0xcc>
mov    -0x114(%rbp),%ecx
mov    -0x120(%rbp),%rdx
mov    -0x124(%rbp),%edi
mov    -0x130(%rbp),%r8
lea    0xdcb(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d8f(%rip),%rax
cmpl   $0x0,(%rax)
je     1266 <check_and_mk_log_dir+0x116>
mov    0x2d7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x134(%rbp)
jmp    1275 <check_and_mk_log_dir+0x125>
mov    0x2d5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x134(%rbp)
mov    -0x134(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128f <check_and_mk_log_dir+0x13f>
jmp    1288 <check_and_mk_log_dir+0x138>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_and_mk_log_dir>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rcx
lea    0xe9b(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <fileExists@plt>
xor    %ebx,%ebx
test   %eax,%eax
je     1191 <check_and_mk_log_dir+0x41>
mov    %ebx,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rsp,%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
test   %rax,%rax
je     1183 <check_and_mk_log_dir+0x33>
mov    0x2e36(%rip),%rax
mov    (%rax),%ebp
mov    0x2e25(%rip),%r14
mov    (%r14),%ebx
mov    %ebx,%edi
call   1070 <strerror@plt>
test   %rax,%rax
je     11cf <check_and_mk_log_dir+0x7f>
mov    (%r14),%edi
call   1070 <strerror@plt>
mov    %rax,%r8
jmp    11d6 <check_and_mk_log_dir+0x86>
lea    0xe5d(%rip),%r8
lea    0xe2b(%rip),%rsi
mov    %rsp,%rdx
mov    %ebp,%edi
mov    %ebx,%ecx
call   1060 <fprintf@plt>
mov    (%r14),%ebx
test   %ebx,%ebx
jne    1183 <check_and_mk_log_dir+0x33>
mov    0x2dd1(%rip),%rax
mov    (%rax),%ebx
jmp    1183 <check_and_mk_log_dir+0x33>

LLVM IR (-O0):
@.str = [8 x i8] c"%s/logs\00"
@stderr = global i32 0
@.str.1 = [43 x i8] c"mkdir \22%s\22 fail, errno: %d, error info: %s\00"
@errno = global i32 0
@.str.2 = [13 x i8] c"Unkown error\00"
@EPERM = global i32 0
define i32 @check_and_mk_log_dir(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [256 x i8]
store i8* %0, i8** %3
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = load i8*, i8** %3
%7 = call i32 @snprintf(i8* %5, i32 256, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%9 = call i32 @fileExists(i8* %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %38, label %11
11: ; preds = %1
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%13 = call i64 @mkdir(i8* %12, i32 493)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %37
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%18 = load i32, i32* @errno
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
br label %26
25: ; preds = %15
br label %26
26: ; preds = %25, %22
%27 = phi i8* [ %24, %22 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), %25 ]
%28 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %17, i32 %18, i8* %27)
%29 = load i32, i32* @errno
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = load i32, i32* @errno
br label %35
33: ; preds = %26
%34 = load i32, i32* @EPERM
br label %35
35: ; preds = %33, %31
%36 = phi i32 [ %32, %31 ], [ %34, %33 ]
store i32 %36, i32* %2
br label %39
37: ; preds = %11
br label %38
38: ; preds = %37, %1
store i32 0, i32* %2
br label %39
39: ; preds = %38, %35
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@.str = [8 x i8] c"%s/logs\00"
@stderr = global i32 0
@.str.1 = [43 x i8] c"mkdir \22%s\22 fail, errno: %d, error info: %s\00"
@errno = global i32 0
@.str.2 = [13 x i8] c"Unkown error\00"
@EPERM = global i32 0
define i32 @check_and_mk_log_dir(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @snprintf(i8* %3, i32 256, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = call i32 @fileExists(i8* %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %25
7: ; preds = %1
%8 = call i64 @mkdir(i8* %3, i32 493)
%9 = icmp eq i64 %8, 0
br i1 %9, label %25, label %10
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %18, label %15
15: ; preds = %10
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
br label %18
18: ; preds = %10, %15
%19 = phi i8* [ %17, %15 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), %10 ]
%20 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %3, i32 %12, i8* %19)
%21 = load i32, i32* @errno
%22 = icmp eq i32 %21, 0
%23 = load i32, i32* @EPERM
%24 = select i1 %22, i32 %23, i32 %21
br label %25
25: ; preds = %1, %7, %18
%26 = phi i32 [ %24, %18 ], [ 0, %7 ], [ 0, %1 ]
ret i32 %26
}