#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ getenv(char *);
scalar_t__ mkdir(char *, int /*<<< orphan*/);
char *s_asprintf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ s_free(char *);
char *sosc_get_config_directory();
scalar_t__ stat(char *, struct stat *);
int sosc_config_create_directory() {
  char *cdir, *xdgdir;
  struct stat buf[1];
  cdir = sosc_get_config_directory();
  if (!stat(cdir, buf))
    return 0;
  if (!getenv("XDG_CONFIG_HOME")) {
    xdgdir = s_asprintf("%s/.config", getenv("HOME"));
    if (stat(xdgdir, buf) && mkdir(xdgdir, S_IRWXU))
      goto err_xdg;
  }
  if (mkdir(cdir, S_IRWXU))
    goto err_mkdir;
  s_free(cdir);
  return 0;
err_xdg:
  s_free(xdgdir);
err_mkdir:
  s_free(cdir);
  return 1;
}


x86 assembly (clang, -O0):
<sosc_config_create_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1080 <sosc_get_config_directory@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
jne    1196 <sosc_config_create_directory+0x36>
movl   $0x0,-0x4(%rbp)
jmp    1255 <sosc_config_create_directory+0xf5>
lea    0xe63(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%eax
jne    1206 <sosc_config_create_directory+0xa6>
lea    0xe59(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%esi
lea    0xe50(%rip),%rdi
call   1070 <s_asprintf@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
je     1201 <sosc_config_create_directory+0xa1>
mov    -0x18(%rbp),%rdi
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
call   1050 <mkdir@plt>
cmp    $0x0,%rax
je     1201 <sosc_config_create_directory+0xa1>
jmp    123c <sosc_config_create_directory+0xdc>
jmp    1206 <sosc_config_create_directory+0xa6>
mov    -0x10(%rbp),%rdi
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
call   1050 <mkdir@plt>
cmp    $0x0,%rax
je     1227 <sosc_config_create_directory+0xc7>
jmp    1245 <sosc_config_create_directory+0xe5>
mov    -0x10(%rbp),%rdi
call   1040 <s_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1255 <sosc_config_create_directory+0xf5>
mov    -0x18(%rbp),%rdi
call   1040 <s_free@plt>
mov    -0x10(%rbp),%rdi
call   1040 <s_free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sosc_config_create_directory>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
xor    %eax,%eax
call   1080 <sosc_get_config_directory@plt>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   1060 <stat@plt>
test   %rax,%rax
je     1205 <sosc_config_create_directory+0xa5>
lea    0xe76(%rip),%rdi
call   1030 <getenv@plt>
test   %eax,%eax
je     11ad <sosc_config_create_directory+0x4d>
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <mkdir@plt>
test   %rax,%rax
jne    11f8 <sosc_config_create_directory+0x98>
xor    %ebp,%ebp
jmp    11fd <sosc_config_create_directory+0x9d>
lea    0xe57(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe50(%rip),%rdi
mov    %eax,%esi
call   1070 <s_asprintf@plt>
mov    %rax,%rbp
mov    %rsp,%rsi
mov    %rax,%rdi
call   1060 <stat@plt>
test   %rax,%rax
je     1193 <sosc_config_create_directory+0x33>
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1050 <mkdir@plt>
test   %rax,%rax
je     1193 <sosc_config_create_directory+0x33>
mov    %rbp,%rdi
call   1040 <s_free@plt>
mov    $0x1,%ebp
mov    %rbx,%rdi
call   1040 <s_free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [16 x i8] c"XDG_CONFIG_HOME\00"
@.str.1 = [11 x i8] c"%s/.config\00"
@.str.2 = [5 x i8] c"HOME\00"
@S_IRWXU = global i32 0
define i32 @sosc_config_create_directory() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [1 x %struct.stat]
%5 = call i8* (...) @sosc_get_config_directory()
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = getelementptr inbounds [1 x %struct.stat], [1 x %struct.stat]* %4, i64 0, i64 0
%8 = call i64 @stat(i8* %6, %struct.stat* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %0
store i32 0, i32* %1
br label %43
11: ; preds = %0
%12 = call i32 @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i32 %12, 0
br i1 %13, label %28, label %14
14: ; preds = %11
%15 = call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%16 = call i8* @s_asprintf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %15)
store i8* %16, i8** %3
%17 = load i8*, i8** %3
%18 = getelementptr inbounds [1 x %struct.stat], [1 x %struct.stat]* %4, i64 0, i64 0
%19 = call i64 @stat(i8* %17, %struct.stat* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %14
%22 = load i8*, i8** %3
%23 = load i32, i32* @S_IRWXU
%24 = call i64 @mkdir(i8* %22, i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %21
br label %37
27: ; preds = %21, %14
br label %28
28: ; preds = %27, %11
%29 = load i8*, i8** %2
%30 = load i32, i32* @S_IRWXU
%31 = call i64 @mkdir(i8* %29, i32 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %28
br label %40
34: ; preds = %28
%35 = load i8*, i8** %2
%36 = call i32 @s_free(i8* %35)
store i32 0, i32* %1
br label %43
37: ; preds = %26
%38 = load i8*, i8** %3
%39 = call i32 @s_free(i8* %38)
br label %40
40: ; preds = %37, %33
%41 = load i8*, i8** %2
%42 = call i32 @s_free(i8* %41)
store i32 1, i32* %1
br label %43
43: ; preds = %40, %34, %10
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [16 x i8] c"XDG_CONFIG_HOME\00"
@.str.1 = [11 x i8] c"%s/.config\00"
@.str.2 = [5 x i8] c"HOME\00"
@S_IRWXU = global i32 0
define i32 @sosc_config_create_directory() {
%1 = alloca [1 x %struct.stat]
%2 = bitcast [1 x %struct.stat]* %1 to i8*
%3 = tail call i8* (...) @sosc_get_config_directory()
%4 = getelementptr inbounds [1 x %struct.stat], [1 x %struct.stat]* %1, i64 0, i64 0
%5 = call i64 @stat(i8* %3, %struct.stat* %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %29, label %7
7: ; preds = %0
%8 = call i32 @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %7
%11 = call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%12 = call i8* @s_asprintf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = call i64 @stat(i8* %12, %struct.stat* %4)
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %10
%16 = load i32, i32* @S_IRWXU
%17 = call i64 @mkdir(i8* %12, i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %10, %15, %7
%20 = load i32, i32* @S_IRWXU
%21 = call i64 @mkdir(i8* %3, i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %25
23: ; preds = %15
%24 = call i32 @s_free(i8* %12)
br label %25
25: ; preds = %19, %23
br label %26
26: ; preds = %19, %25
%27 = phi i32 [ 1, %25 ], [ 0, %19 ]
%28 = call i32 @s_free(i8* %3)
br label %29
29: ; preds = %26, %0
%30 = phi i32 [ 0, %0 ], [ %27, %26 ]
ret i32 %30
}