#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;
int /*<<< orphan*/ exit(scalar_t__);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int mkdir(char *, int);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
void dest_mkdir(char *dir) {
  int ret;
  ret = mkdir(dir, 0777);
  if (ret && errno != EEXIST) {
    fprintf(stderr, "failed to mkdir error %s\n", strerror(errno));
    exit(errno);
  }
}


x86 assembly (clang, -O0):
<dest_mkdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11bd <dest_mkdir+0x7d>
mov    0x2e62(%rip),%rax
mov    (%rax),%rax
mov    0x2e68(%rip),%rcx
cmp    (%rcx),%rax
je     11bd <dest_mkdir+0x7d>
mov    0x2e50(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e3c(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%rdx
lea    0xe57(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%rdi
call   1050 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dest_mkdir>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
test   %eax,%eax
je     1167 <dest_mkdir+0x27>
mov    0x2e78(%rip),%rbx
mov    (%rbx),%rdi
mov    0x2e7e(%rip),%rax
cmp    (%rax),%rdi
jne    116e <dest_mkdir+0x2e>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e63(%rip),%rax
mov    (%rax),%ebp
call   1060 <strerror@plt>
lea    0xe7d(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    (%rbx),%rdi
call   1050 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@EEXIST = global i64 0
@stderr = global i32 0
@.str = [26 x i8] c"failed to mkdir error %s\0A\00"
define void @dest_mkdir(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @mkdir(i8* %4, i32 511)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %19
8: ; preds = %1
%9 = load i64, i64* @errno
%10 = load i64, i64* @EEXIST
%11 = icmp ne i64 %9, %10
br i1 %11, label %12, label %19
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = load i64, i64* @errno
%15 = call i8* @strerror(i64 %14)
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i64, i64* @errno
%18 = call i32 @exit(i64 %17)
unreachable
19: ; preds = %8, %1
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@EEXIST = global i64 0
@stderr = global i32 0
@.str = [26 x i8] c"failed to mkdir error %s\0A\00"
define void @dest_mkdir(i8* nocapture %0) {
%2 = tail call i32 @mkdir(i8* %0, i32 511)
%3 = icmp eq i32 %2, 0
br i1 %3, label %14, label %4
4: ; preds = %1
%5 = load i64, i64* @errno
%6 = load i64, i64* @EEXIST
%7 = icmp eq i64 %5, %6
br i1 %7, label %14, label %8
8: ; preds = %4
%9 = load i32, i32* @stderr
%10 = tail call i8* @strerror(i64 %5)
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i64, i64* @errno
%13 = tail call i32 @exit(i64 %12)
unreachable
14: ; preds = %4, %1
ret void
}