#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;
scalar_t__ errno;
scalar_t__ mkdir(char const *, int);
int /*<<< orphan*/ printf(char *, scalar_t__, char *);
char *strerror(scalar_t__);
char *xstrdup(char *);
int DFMkdirIfAbsent(const char *path, char **errmsg) {
  if ((mkdir(path, 0777) != 0) && (errno != EEXIST)) {
    printf("DFMkdirIfAbsent: errno = %d (%s)\n", errno, strerror(errno));
    if (errmsg != NULL)
      *errmsg = xstrdup(strerror(errno));
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<DFMkdirIfAbsent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
je     11ea <DFMkdirIfAbsent+0xaa>
mov    0x2e69(%rip),%rax
mov    (%rax),%rax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%rax
je     11ea <DFMkdirIfAbsent+0xaa>
mov    0x2e4f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e41(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
lea    0xe53(%rip),%rdi
call   1040 <printf@plt>
cmpq   $0x0,-0x18(%rbp)
je     11de <DFMkdirIfAbsent+0x9e>
mov    0x2e14(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    %rax,%rdi
call   1050 <xstrdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11f1 <DFMkdirIfAbsent+0xb1>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DFMkdirIfAbsent>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     11a8 <DFMkdirIfAbsent+0x68>
mov    0x2e73(%rip),%r15
mov    (%r15),%rbx
mov    0x2e71(%rip),%rax
cmp    (%rax),%rbx
je     11a8 <DFMkdirIfAbsent+0x68>
mov    %rbx,%rdi
call   1060 <strerror@plt>
lea    0xe7d(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
xor    %ebp,%ebp
test   %r14,%r14
je     11a8 <DFMkdirIfAbsent+0x68>
mov    (%r15),%rdi
call   1060 <strerror@plt>
mov    %rax,%rdi
call   1050 <xstrdup@plt>
mov    %rax,(%r14)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EEXIST = global i64 0
@.str = [34 x i8] c"DFMkdirIfAbsent: errno = %d (%s)\0A\00"
define i32 @DFMkdirIfAbsent(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
store i8* %0, i8** %4
store i8** %1, i8*** %5
%6 = load i8*, i8** %4
%7 = call i64 @mkdir(i8* %6, i32 511)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %26
9: ; preds = %2
%10 = load i64, i64* @errno
%11 = load i64, i64* @EEXIST
%12 = icmp ne i64 %10, %11
br i1 %12, label %13, label %26
13: ; preds = %9
%14 = load i64, i64* @errno
%15 = load i64, i64* @errno
%16 = call i8* @strerror(i64 %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i64 %14, i8* %16)
%18 = load i8**, i8*** %5
%19 = icmp ne i8** %18, null
br i1 %19, label %20, label %25
20: ; preds = %13
%21 = load i64, i64* @errno
%22 = call i8* @strerror(i64 %21)
%23 = call i8* @xstrdup(i8* %22)
%24 = load i8**, i8*** %5
store i8* %23, i8** %24
br label %25
25: ; preds = %20, %13
store i32 0, i32* %3
br label %27
26: ; preds = %9, %2
store i32 1, i32* %3
br label %27
27: ; preds = %26, %25
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@errno = global i64 0
@EEXIST = global i64 0
@.str = [34 x i8] c"DFMkdirIfAbsent: errno = %d (%s)\0A\00"
define i32 @DFMkdirIfAbsent(i8* nocapture %0, i8** writeonly %1) {
%3 = tail call i64 @mkdir(i8* %0, i32 511)
%4 = icmp eq i64 %3, 0
br i1 %4, label %17, label %5
5: ; preds = %2
%6 = load i64, i64* @errno
%7 = load i64, i64* @EEXIST
%8 = icmp eq i64 %6, %7
br i1 %8, label %17, label %9
9: ; preds = %5
%10 = tail call i8* @strerror(i64 %6)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i64 %6, i8* %10)
%12 = icmp eq i8** %1, null
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = load i64, i64* @errno
%15 = tail call i8* @strerror(i64 %14)
%16 = tail call i8* @xstrdup(i8* %15)
store i8* %16, i8** %1
br label %17
17: ; preds = %2, %5, %9, %13
%18 = phi i32 [ 0, %13 ], [ 0, %9 ], [ 1, %5 ], [ 1, %2 ]
ret i32 %18
}