#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
scalar_t__ EEXIST;
int S_IRUSR;
int S_IWUSR;
int S_IXUSR;
int /*<<< orphan*/ bail(char *, char *);
int chmod(char *, int);
char *dirname(char *);
scalar_t__ errno;
int mkdir(char *, int);
char *strdup(char *);
void prep_output(char *fname) {
  int ret;
  char *dir;
  char *base;
  char *bname;
  char *dname;
  struct stat st;
  dir = strdup(fname);
  base = strdup(fname);
  dname = dirname(dir);
  ret = mkdir(dname, S_IRUSR | S_IWUSR | S_IXUSR);
  if (ret < 0)
    if (errno != EEXIST)
      bail("Cannot mkdir (%s)", dname);
  ret = chmod(dname, S_IRUSR | S_IWUSR | S_IXUSR);
  if (ret < 0)
    bail("Cannot chmod 700 (%s)", dname);
  return;
}


x86 assembly (clang, -O0):
<prep_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <dirname@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
mov    0x2e49(%rip),%rax
or     (%rax),%esi
mov    0x2e48(%rip),%rax
or     (%rax),%esi
call   1030 <mkdir@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11e3 <prep_output+0x93>
mov    0x2e0d(%rip),%rax
mov    (%rax),%rax
mov    0x2e0b(%rip),%rcx
cmp    (%rcx),%rax
je     11de <prep_output+0x8e>
mov    -0x30(%rbp),%rsi
lea    0xe27(%rip),%rdi
call   1060 <bail@plt>
jmp    11e3 <prep_output+0x93>
mov    -0x30(%rbp),%rdi
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
mov    0x2de9(%rip),%rax
or     (%rax),%esi
mov    0x2de8(%rip),%rax
or     (%rax),%esi
call   1050 <chmod@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1224 <prep_output+0xd4>
mov    -0x30(%rbp),%rsi
lea    0xdf3(%rip),%rdi
call   1060 <bail@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prep_output>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
call   1070 <strdup@plt>
mov    %rax,%rdi
call   1040 <dirname@plt>
mov    0x2e54(%rip),%r14
mov    0x2e6d(%rip),%r15
mov    (%r15),%esi
or     (%r14),%esi
mov    %rax,%rbx
mov    0x2e65(%rip),%r12
or     (%r12),%esi
mov    %rax,%rdi
call   1030 <mkdir@plt>
test   %eax,%eax
jns    11b8 <prep_output+0x68>
mov    0x2e2e(%rip),%rax
mov    (%rax),%rax
mov    0x2e2c(%rip),%rcx
cmp    (%rcx),%rax
je     11b8 <prep_output+0x68>
lea    0xe50(%rip),%rdi
mov    %rbx,%rsi
call   1060 <bail@plt>
mov    (%r15),%esi
or     (%r14),%esi
or     (%r12),%esi
mov    %rbx,%rdi
call   1050 <chmod@plt>
test   %eax,%eax
js     11da <prep_output+0x8a>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe31(%rip),%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <bail@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str = [18 x i8] c"Cannot mkdir (%s)\00"
@.str.1 = [22 x i8] c"Cannot chmod 700 (%s)\00"
define void @prep_output(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.stat
store i8* %0, i8** %2
%9 = load i8*, i8** %2
%10 = call i8* @strdup(i8* %9)
store i8* %10, i8** %4
%11 = load i8*, i8** %2
%12 = call i8* @strdup(i8* %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %4
%14 = call i8* @dirname(i8* %13)
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = load i32, i32* @S_IRUSR
%17 = load i32, i32* @S_IWUSR
%18 = or i32 %16, %17
%19 = load i32, i32* @S_IXUSR
%20 = or i32 %18, %19
%21 = call i32 @mkdir(i8* %15, i32 %20)
store i32 %21, i32* %3
%22 = load i32, i32* %3
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %1
%25 = load i64, i64* @errno
%26 = load i64, i64* @EEXIST
%27 = icmp ne i64 %25, %26
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i8*, i8** %7
%30 = call i32 @bail(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %28, %24
br label %32
32: ; preds = %31, %1
%33 = load i8*, i8** %7
%34 = load i32, i32* @S_IRUSR
%35 = load i32, i32* @S_IWUSR
%36 = or i32 %34, %35
%37 = load i32, i32* @S_IXUSR
%38 = or i32 %36, %37
%39 = call i32 @chmod(i8* %33, i32 %38)
store i32 %39, i32* %3
%40 = load i32, i32* %3
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %32
%43 = load i8*, i8** %7
%44 = call i32 @bail(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %42, %32
ret void
}

LLVM IR (-O2):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str = [18 x i8] c"Cannot mkdir (%s)\00"
@.str.1 = [22 x i8] c"Cannot chmod 700 (%s)\00"
define void @prep_output(i8* nocapture %0) {
%2 = tail call i8* @strdup(i8* %0)
%3 = tail call i8* @dirname(i8* %2)
%4 = load i32, i32* @S_IRUSR
%5 = load i32, i32* @S_IWUSR
%6 = or i32 %5, %4
%7 = load i32, i32* @S_IXUSR
%8 = or i32 %6, %7
%9 = tail call i32 @mkdir(i8* %3, i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %1
%12 = load i64, i64* @errno
%13 = load i64, i64* @EEXIST
%14 = icmp eq i64 %12, %13
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = tail call i32 @bail(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %17
17: ; preds = %11, %15, %1
%18 = load i32, i32* @S_IRUSR
%19 = load i32, i32* @S_IWUSR
%20 = or i32 %19, %18
%21 = load i32, i32* @S_IXUSR
%22 = or i32 %20, %21
%23 = tail call i32 @chmod(i8* %3, i32 %22)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %17
%26 = tail call i32 @bail(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %27
27: ; preds = %25, %17
ret void
}