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

/* Variables and functions */
int S_IRGRP;
int S_IROTH;
int S_IRWXU;
int S_IXGRP;
int S_IXOTH;
char *enter_dirfile(char const *);
int /*<<< orphan*/ exit_dirfile(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int mkdir(char const *, int);
int dirfile_create(const char *dirfilename) {
  int status =
      mkdir(dirfilename, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
  if (status != 0)
    return -1;
  char *oldwd = enter_dirfile(dirfilename);
  if (oldwd == NULL)
    return -1;
  FILE *fp = fopen("format", "w");
  fprintf(fp, "# dirfile format file\n");
  fclose(fp);
  exit_dirfile(oldwd);
  return 0;
}


x86 assembly (clang, -O0):
<dirfile_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
mov    0x2e48(%rip),%rax
or     (%rax),%esi
mov    0x2e4f(%rip),%rax
or     (%rax),%esi
mov    0x2e2e(%rip),%rax
or     (%rax),%esi
mov    0x2e45(%rip),%rax
or     (%rax),%esi
call   1030 <mkdir@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11bb <dirfile_create+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    121f <dirfile_create+0xbf>
mov    -0x10(%rbp),%rdi
call   1080 <enter_dirfile@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11df <dirfile_create+0x7f>
movl   $0xffffffff,-0x4(%rbp)
jmp    121f <dirfile_create+0xbf>
lea    0xe1a(%rip),%rdi
lea    0xe1a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe08(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1060 <exit_dirfile@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dirfile_create>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e7e(%rip),%rax
mov    0x2e57(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e5c(%rip),%rax
or     (%rax),%esi
mov    0x2e3b(%rip),%rax
or     (%rax),%esi
mov    %rdi,%rbx
mov    0x2e4f(%rip),%rax
or     (%rax),%esi
call   1030 <mkdir@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
jne    11f2 <dirfile_create+0x92>
mov    %rbx,%rdi
call   1070 <enter_dirfile@plt>
test   %rax,%rax
je     11f2 <dirfile_create+0x92>
mov    %rax,%rbx
lea    0xe48(%rip),%rdi
lea    0xe48(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbp
lea    0xe3b(%rip),%rdi
mov    $0x16,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1050 <exit_dirfile@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IXGRP = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
@.str = [7 x i8] c"format\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [23 x i8] c"# dirfile format file\0A\00"
define i32 @dirfile_create(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = load i32, i32* @S_IRWXU
%9 = load i32, i32* @S_IRGRP
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IXGRP
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IROTH
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IXOTH
%16 = or i32 %14, %15
%17 = call i32 @mkdir(i8* %7, i32 %16)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %1
store i32 -1, i32* %2
br label %35
21: ; preds = %1
%22 = load i8*, i8** %3
%23 = call i8* @enter_dirfile(i8* %22)
store i8* %23, i8** %5
%24 = load i8*, i8** %5
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 -1, i32* %2
br label %35
27: ; preds = %21
%28 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %28, i32** %6
%29 = load i32*, i32** %6
%30 = call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32*, i32** %6
%32 = call i32 @fclose(i32* %31)
%33 = load i8*, i8** %5
%34 = call i32 @exit_dirfile(i8* %33)
store i32 0, i32* %2
br label %35
35: ; preds = %27, %26, %20
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IXGRP = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
@.str = [7 x i8] c"format\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [23 x i8] c"# dirfile format file\0A\00"
define i32 @dirfile_create(i8* %0) {
%2 = load i32, i32* @S_IRWXU
%3 = load i32, i32* @S_IRGRP
%4 = or i32 %3, %2
%5 = load i32, i32* @S_IXGRP
%6 = or i32 %4, %5
%7 = load i32, i32* @S_IROTH
%8 = or i32 %6, %7
%9 = load i32, i32* @S_IXOTH
%10 = or i32 %8, %9
%11 = tail call i32 @mkdir(i8* %0, i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %1
%14 = tail call i8* @enter_dirfile(i8* %0)
%15 = icmp eq i8* %14, null
br i1 %15, label %21, label %16
16: ; preds = %13
%17 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i64 @fwrite(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i64 22, i64 1, i32* %17)
%19 = tail call i32 @fclose(i32* %17)
%20 = tail call i32 @exit_dirfile(i8* %14)
br label %21
21: ; preds = %16, %13, %1
%22 = phi i32 [ -1, %1 ], [ 0, %16 ], [ -1, %13 ]
ret i32 %22
}