#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 */
scalar_t__ EEXIST;
int S_IRGRP;
int S_IROTH;
int S_IRWXU;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int mkdir(char const *, int);
int /*<<< orphan*/ stderr;
int create_dir_if_needed(const char *dir) {
  if (mkdir(dir, S_IRWXU | S_IRGRP | S_IROTH) == -1) {
    if (errno == EEXIST)
      return 1;
    else {
      fprintf(stderr, "can't create output directory\n");
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<create_dir_if_needed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2eb1(%rip),%rax
mov    (%rax),%esi
mov    0x2e80(%rip),%rax
or     (%rax),%esi
mov    0x2e6f(%rip),%rax
or     (%rax),%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    11a0 <create_dir_if_needed+0x80>
mov    0x2e68(%rip),%rax
mov    (%rax),%rax
mov    0x2e6e(%rip),%rcx
cmp    (%rcx),%rax
jne    117f <create_dir_if_needed+0x5f>
movl   $0x1,-0x4(%rbp)
jmp    11a7 <create_dir_if_needed+0x87>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11a7 <create_dir_if_needed+0x87>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_dir_if_needed>:
push   %rax
mov    0x2ec0(%rip),%rax
mov    0x2e91(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e7e(%rip),%rax
or     (%rax),%esi
call   1030 <mkdir@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0xffffffff,%ecx
je     114f <create_dir_if_needed+0x2f>
pop    %rcx
ret
mov    0x2e72(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e78(%rip),%rdx
cmp    (%rdx),%rcx
je     114d <create_dir_if_needed+0x2d>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@stderr = global i32 0
@.str = [31 x i8] c"can't create output directory\0A\00"
define i32 @create_dir_if_needed(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = load i32, i32* @S_IRWXU
%6 = load i32, i32* @S_IRGRP
%7 = or i32 %5, %6
%8 = load i32, i32* @S_IROTH
%9 = or i32 %7, %8
%10 = call i32 @mkdir(i8* %4, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %20
12: ; preds = %1
%13 = load i64, i64* @errno
%14 = load i64, i64* @EEXIST
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %12
store i32 1, i32* %2
br label %21
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %21
20: ; preds = %1
store i32 1, i32* %2
br label %21
21: ; preds = %20, %17, %16
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@stderr = global i32 0
@.str = [31 x i8] c"can't create output directory\0A\00"
define i32 @create_dir_if_needed(i8* nocapture %0) {
%2 = load i32, i32* @S_IRWXU
%3 = load i32, i32* @S_IRGRP
%4 = or i32 %3, %2
%5 = load i32, i32* @S_IROTH
%6 = or i32 %4, %5
%7 = tail call i32 @mkdir(i8* %0, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %16
9: ; preds = %1
%10 = load i64, i64* @errno
%11 = load i64, i64* @EEXIST
%12 = icmp eq i64 %10, %11
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %1, %9, %13
%17 = phi i32 [ 0, %13 ], [ 1, %9 ], [ 1, %1 ]
ret i32 %17
}