#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 mode_t;

/* Variables and functions */
scalar_t__ EEXIST;
int S_IRGRP;
int S_IRUSR;
int S_IWGRP;
int S_IWUSR;
int S_IXUSR;
scalar_t__ errno;
int /*<<< orphan*/ fatal(char *, char *);
int mkdir(char *, int);
int snprintf(char *, int, char *, char *, ...);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ warning(char *, char *);
void filesystem_dir_create_and_store(char *result, int result_size,
                                     char *parent, char *child) {
  int ret;
  mode_t urwx_grx = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP;
  result_size = ((result_size) < (400) ? (result_size) : (400));
  if (!parent || !strlen(parent))
    ret = snprintf(result, result_size, "%s/", child);
  else
    ret = snprintf(result, result_size, "%s/%s/", parent, child);
  if (ret < 0 || ret >= result_size)
    fatal("%s: string too long", result);
  ret = mkdir(result, urwx_grx);
  if (ret && errno != EEXIST)
    warning("cannot create dir %s", result);
}


x86 assembly (clang, -O0):
<filesystem_dir_create_and_store>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    0x2e61(%rip),%rcx
or     (%rcx),%eax
mov    0x2e68(%rip),%rcx
or     (%rcx),%eax
mov    0x2e2f(%rip),%rcx
or     (%rcx),%eax
mov    0x2e4e(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x190,-0xc(%rbp)
jge    11af <filesystem_dir_create_and_store+0x5f>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    11bc <filesystem_dir_create_and_store+0x6c>
mov    $0x190,%eax
mov    %eax,-0x2c(%rbp)
jmp    11bc <filesystem_dir_create_and_store+0x6c>
mov    -0x2c(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11df <filesystem_dir_create_and_store+0x8f>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%eax
jne    1200 <filesystem_dir_create_and_store+0xb0>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rcx
lea    0xe12(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
mov    %eax,-0x24(%rbp)
jmp    1220 <filesystem_dir_create_and_store+0xd0>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xdea(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     1236 <filesystem_dir_create_and_store+0xe6>
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     1246 <filesystem_dir_create_and_store+0xf6>
mov    -0x8(%rbp),%rsi
lea    0xdc6(%rip),%rdi
call   1070 <fatal@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   1040 <mkdir@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1289 <filesystem_dir_create_and_store+0x139>
mov    0x2d5a(%rip),%rax
mov    (%rax),%rax
mov    0x2d58(%rip),%rcx
cmp    (%rcx),%rax
je     1289 <filesystem_dir_create_and_store+0x139>
mov    -0x8(%rbp),%rsi
lea    0xd97(%rip),%rdi
call   1030 <warning@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filesystem_dir_create_and_store>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e51(%rip),%rax
mov    0x2e72(%rip),%rbp
mov    0x0(%rbp),%ebp
or     (%rax),%ebp
mov    0x2e76(%rip),%rax
or     (%rax),%ebp
mov    %rcx,%r15
mov    %rdi,%r14
mov    0x2e37(%rip),%rax
or     (%rax),%ebp
mov    0x2e56(%rip),%rax
or     (%rax),%ebp
cmp    $0x190,%esi
mov    $0x190,%ebx
cmovl  %esi,%ebx
test   %rdx,%rdx
je     11cd <filesystem_dir_create_and_store+0x7d>
mov    %rdx,%r12
mov    %rdx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
je     11cd <filesystem_dir_create_and_store+0x7d>
lea    0xe4b(%rip),%rdx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r12,%rcx
mov    %r15,%r8
xor    %eax,%eax
call   1060 <snprintf@plt>
test   %eax,%eax
jns    11e7 <filesystem_dir_create_and_store+0x97>
jmp    11eb <filesystem_dir_create_and_store+0x9b>
lea    0xe2f(%rip),%rdx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15,%rcx
xor    %eax,%eax
call   1060 <snprintf@plt>
test   %eax,%eax
js     11eb <filesystem_dir_create_and_store+0x9b>
cmp    %ebx,%eax
jl     11fa <filesystem_dir_create_and_store+0xaa>
lea    0xe15(%rip),%rdi
mov    %r14,%rsi
call   1070 <fatal@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <mkdir@plt>
test   %eax,%eax
je     121e <filesystem_dir_create_and_store+0xce>
mov    0x2db1(%rip),%rax
mov    (%rax),%rax
mov    0x2daf(%rip),%rcx
cmp    (%rcx),%rax
jne    1227 <filesystem_dir_create_and_store+0xd7>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xded(%rip),%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <warning@plt>

LLVM IR (-O0):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@.str = [4 x i8] c"%s/\00"
@.str.1 = [7 x i8] c"%s/%s/\00"
@.str.2 = [20 x i8] c"%s: string too long\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.3 = [21 x i8] c"cannot create dir %s\00"
define void @filesystem_dir_create_and_store(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%11 = load i32, i32* @S_IRUSR
%12 = load i32, i32* @S_IWUSR
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IXUSR
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IRGRP
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IWGRP
%19 = or i32 %17, %18
store i32 %19, i32* %10
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 400
br i1 %21, label %22, label %24
22: ; preds = %4
%23 = load i32, i32* %6
br label %25
24: ; preds = %4
br label %25
25: ; preds = %24, %22
%26 = phi i32 [ %23, %22 ], [ 400, %24 ]
store i32 %26, i32* %6
%27 = load i8*, i8** %7
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i8*, i8** %7
%31 = call i32 @strlen(i8* %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %38, label %33
33: ; preds = %29, %25
%34 = load i8*, i8** %5
%35 = load i32, i32* %6
%36 = load i8*, i8** %8
%37 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %34, i32 %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %36)
store i32 %37, i32* %9
br label %44
38: ; preds = %29
%39 = load i8*, i8** %5
%40 = load i32, i32* %6
%41 = load i8*, i8** %7
%42 = load i8*, i8** %8
%43 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %39, i32 %40, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %41, i8* %42)
store i32 %43, i32* %9
br label %44
44: ; preds = %38, %33
%45 = load i32, i32* %9
%46 = icmp slt i32 %45, 0
br i1 %46, label %51, label %47
47: ; preds = %44
%48 = load i32, i32* %9
%49 = load i32, i32* %6
%50 = icmp sge i32 %48, %49
br i1 %50, label %51, label %54
51: ; preds = %47, %44
%52 = load i8*, i8** %5
%53 = call i32 @fatal(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %52)
br label %54
54: ; preds = %51, %47
%55 = load i8*, i8** %5
%56 = load i32, i32* %10
%57 = call i32 @mkdir(i8* %55, i32 %56)
store i32 %57, i32* %9
%58 = load i32, i32* %9
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %67
60: ; preds = %54
%61 = load i64, i64* @errno
%62 = load i64, i64* @EEXIST
%63 = icmp ne i64 %61, %62
br i1 %63, label %64, label %67
64: ; preds = %60
%65 = load i8*, i8** %5
%66 = call i32 @warning(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %65)
br label %67
67: ; preds = %64, %60, %54
ret void
}

LLVM IR (-O2):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@.str = [4 x i8] c"%s/\00"
@.str.1 = [7 x i8] c"%s/%s/\00"
@.str.2 = [20 x i8] c"%s: string too long\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.3 = [21 x i8] c"cannot create dir %s\00"
define void @filesystem_dir_create_and_store(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = load i32, i32* @S_IRUSR
%6 = load i32, i32* @S_IWUSR
%7 = or i32 %6, %5
%8 = load i32, i32* @S_IXUSR
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IRGRP
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IWGRP
%13 = or i32 %11, %12
%14 = icmp slt i32 %1, 400
%15 = select i1 %14, i32 %1, i32 400
%16 = icmp eq i8* %2, null
br i1 %16, label %20, label %17
17: ; preds = %4
%18 = tail call i32 @strlen(i8* %2)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17, %4
%21 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %0, i32 %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %24
22: ; preds = %17
%23 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %0, i32 %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %3)
br label %24
24: ; preds = %22, %20
%25 = phi i32 [ %23, %22 ], [ %21, %20 ]
%26 = icmp sgt i32 %25, -1
%27 = icmp slt i32 %25, %15
%28 = and i1 %26, %27
br i1 %28, label %31, label %29
29: ; preds = %24
%30 = tail call i32 @fatal(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %31
31: ; preds = %24, %29
%32 = tail call i32 @mkdir(i8* %0, i32 %13)
%33 = icmp eq i32 %32, 0
br i1 %33, label %40, label %34
34: ; preds = %31
%35 = load i64, i64* @errno
%36 = load i64, i64* @EEXIST
%37 = icmp eq i64 %35, %36
br i1 %37, label %40, label %38
38: ; preds = %34
%39 = tail call i32 @warning(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %40
40: ; preds = %38, %34, %31
ret void
}