#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 /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ EACCES;
scalar_t__ EEXIST;
int S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
int /*<<< orphan*/ memset(struct stat *, int /*<<< orphan*/, int);
int mkdir(char *, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stat(char *, struct stat *);
void test() {
  int err;
  struct stat s;
  err = mkdir("folder-readonly/subfolder", 0777);
  assert(err);
  assert(errno == EACCES);
  err = mkdir("folder", 0777);
  assert(!err);
  memset(&s, 0, sizeof s);
  stat("folder", &s);
  assert(S_ISDIR(s.st_mode));
  err = mkdir("folder", 0777);
  assert(err);
  assert(errno == EEXIST);
  puts("success");
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1070 <assert@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%rax
mov    0x2e53(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xe67(%rip),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
lea    0xe30(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1080 <stat@plt>
mov    -0x8(%rbp),%edi
call   1050 <S_ISDIR@plt>
mov    %eax,%edi
call   1070 <assert@plt>
lea    0xe11(%rip),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1070 <assert@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%rax
mov    0x2db0(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xddb(%rip),%rdi
call   1040 <puts@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe90(%rip),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
mov    %eax,%edi
call   1070 <assert@plt>
mov    0x2e48(%rip),%r15
mov    (%r15),%rax
mov    0x2e56(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%rax
sete   %dil
call   1070 <assert@plt>
lea    0xe6c(%rip),%r14
mov    %r14,%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <stat@plt>
mov    0x8(%rsp),%edi
call   1050 <S_ISDIR@plt>
mov    %eax,%edi
call   1070 <assert@plt>
mov    %r14,%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
mov    %eax,%edi
call   1070 <assert@plt>
mov    (%r15),%rax
mov    0x2dca(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%rax
sete   %dil
call   1070 <assert@plt>
lea    0xdf7(%rip),%rdi
call   1040 <puts@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [26 x i8] c"folder-readonly/subfolder\00"
@errno = global i64 0
@EACCES = global i64 0
@.str.1 = [7 x i8] c"folder\00"
@EEXIST = global i64 0
@.str.2 = [8 x i8] c"success\00"
define void @test() {
%1 = alloca i32
%2 = alloca %struct.stat
%3 = call i32 @mkdir(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 511)
store i32 %3, i32* %1
%4 = load i32, i32* %1
%5 = call i32 @assert(i32 %4)
%6 = load i64, i64* @errno
%7 = load i64, i64* @EACCES
%8 = icmp eq i64 %6, %7
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = call i32 @mkdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 511)
store i32 %11, i32* %1
%12 = load i32, i32* %1
%13 = icmp ne i32 %12, 0
%14 = xor i1 %13, true
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = call i32 @memset(%struct.stat* %2, i32 0, i32 4)
%18 = call i32 @stat(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %2)
%19 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @S_ISDIR(i32 %20)
%22 = call i32 @assert(i32 %21)
%23 = call i32 @mkdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 511)
store i32 %23, i32* %1
%24 = load i32, i32* %1
%25 = call i32 @assert(i32 %24)
%26 = load i64, i64* @errno
%27 = load i64, i64* @EEXIST
%28 = icmp eq i64 %26, %27
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [26 x i8] c"folder-readonly/subfolder\00"
@errno = global i64 0
@EACCES = global i64 0
@.str.1 = [7 x i8] c"folder\00"
@EEXIST = global i64 0
@.str.2 = [8 x i8] c"success\00"
define void @test() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = tail call i32 @mkdir(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 511)
%4 = tail call i32 @assert(i32 %3)
%5 = load i64, i64* @errno
%6 = load i64, i64* @EACCES
%7 = icmp eq i64 %5, %6
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i32 @mkdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 511)
%11 = icmp eq i32 %10, 0
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = call i32 @memset(%struct.stat* %1, i32 0, i32 4)
%15 = call i32 @stat(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %1)
%16 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @S_ISDIR(i32 %17)
%19 = call i32 @assert(i32 %18)
%20 = call i32 @mkdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 511)
%21 = call i32 @assert(i32 %20)
%22 = load i64, i64* @errno
%23 = load i64, i64* @EEXIST
%24 = icmp eq i64 %22, %23
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
ret void
}