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

/* Variables and functions */
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ fm_is_dir(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ io_err(char *, char *);
int mkdir(char *, int /*<<< orphan*/);
char *read_file_opt_dup(char *);
int fm_init_base(void) {
  int rv = 0;
  char *base_dir = read_file_opt_dup("base-dir");
  if (!fm_is_dir(base_dir)) {
    if (mkdir(base_dir, S_IRWXU) == -1) {
      io_err("unable to create directory: %s\n", base_dir);
      rv = -1;
    }
  }
  do {
    if ((base_dir) != NULL) {
      free(base_dir);
      (base_dir) = NULL;
    }
  } while (0);
  return rv;
}


x86 assembly (clang, -O0):
<fm_init_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1060 <read_file_opt_dup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <fm_is_dir@plt>
cmp    $0x0,%eax
jne    11b8 <fm_init_base+0x68>
mov    -0x10(%rbp),%rdi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
call   1040 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    11b3 <fm_init_base+0x63>
mov    -0x10(%rbp),%rsi
lea    0xe62(%rip),%rdi
call   1050 <io_err@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b8 <fm_init_base+0x68>
jmp    11bd <fm_init_base+0x6d>
cmpq   $0x0,-0x10(%rbp)
je     11d9 <fm_init_base+0x89>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
jmp    11de <fm_init_base+0x8e>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fm_init_base>:
push   %rbp
push   %rbx
push   %rax
lea    0xea6(%rip),%rdi
call   1060 <read_file_opt_dup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <fm_is_dir@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    119a <fm_init_base+0x4a>
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    119a <fm_init_base+0x4a>
lea    0xe7c(%rip),%rdi
mov    %rbx,%rsi
call   1050 <io_err@plt>
mov    $0xffffffff,%ebp
test   %rbx,%rbx
je     11a7 <fm_init_base+0x57>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"base-dir\00"
@S_IRWXU = global i32 0
@.str.1 = [32 x i8] c"unable to create directory: %s\0A\00"
define i32 @fm_init_base() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
%3 = call i8* @read_file_opt_dup(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @fm_is_dir(i8* %4)
%6 = icmp ne i32 %5, 0
br i1 %6, label %16, label %7
7: ; preds = %0
%8 = load i8*, i8** %2
%9 = load i32, i32* @S_IRWXU
%10 = call i32 @mkdir(i8* %8, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i8*, i8** %2
%14 = call i32 @io_err(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %13)
store i32 -1, i32* %1
br label %15
15: ; preds = %12, %7
br label %16
16: ; preds = %15, %0
br label %17
17: ; preds = %16
%18 = load i8*, i8** %2
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i8*, i8** %2
%22 = call i32 @free(i8* %21)
store i8* null, i8** %2
br label %23
23: ; preds = %20, %17
br label %24
24: ; preds = %23
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [9 x i8] c"base-dir\00"
@S_IRWXU = global i32 0
@.str.1 = [32 x i8] c"unable to create directory: %s\0A\00"
define i32 @fm_init_base() {
%1 = tail call i8* @read_file_opt_dup(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @fm_is_dir(i8* %1)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %10
4: ; preds = %0
%5 = load i32, i32* @S_IRWXU
%6 = tail call i32 @mkdir(i8* %1, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 @io_err(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %10
10: ; preds = %0, %8, %4
%11 = phi i32 [ 0, %0 ], [ -1, %8 ], [ 0, %4 ]
%12 = icmp eq i8* %1, null
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 @free(i8* %1)
br label %15
15: ; preds = %13, %10
ret i32 %11
}