#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 */
char *config_to_path(char *);
scalar_t__ mkdir(char const *, int);
int /*<<< orphan*/ musicd_perror(int, char *, char *, char const *);
scalar_t__ stat(char const *, struct stat *);
int cache_open() {
  const char *directory = config_to_path("cache-dir");
  struct stat status;
  if (stat(directory, &status)) {
    if (mkdir(directory, 0777)) {
      musicd_perror(1, "cache", "could not create directory %s", directory);
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<cache_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
call   1050 <config_to_path@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
je     11b4 <cache_open+0x74>
mov    -0x10(%rbp),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
je     11af <cache_open+0x6f>
mov    -0x10(%rbp),%rcx
mov    $0x1,%edi
lea    0xe73(%rip),%rsi
lea    0xe72(%rip),%rdx
call   1060 <musicd_perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bb <cache_open+0x7b>
jmp    11b4 <cache_open+0x74>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cache_open>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rdi
call   1050 <config_to_path@plt>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   1040 <stat@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1196 <cache_open+0x56>
mov    %rbx,%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
test   %rax,%rax
je     1196 <cache_open+0x56>
lea    0xe8d(%rip),%rsi
lea    0xe8c(%rip),%rdx
mov    $0x1,%edi
mov    %rbx,%rcx
call   1060 <musicd_perror@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [10 x i8] c"cache-dir\00"
@.str.1 = [6 x i8] c"cache\00"
@.str.2 = [30 x i8] c"could not create directory %s\00"
define i32 @cache_open() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca %struct.stat
%4 = call i8* @config_to_path(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @stat(i8* %5, %struct.stat* %3)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %0
%9 = load i8*, i8** %2
%10 = call i64 @mkdir(i8* %9, i32 511)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i8*, i8** %2
%14 = call i32 @musicd_perror(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %13)
store i32 -1, i32* %1
br label %17
15: ; preds = %8
br label %16
16: ; preds = %15, %0
store i32 0, i32* %1
br label %17
17: ; preds = %16, %12
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [10 x i8] c"cache-dir\00"
@.str.1 = [6 x i8] c"cache\00"
@.str.2 = [30 x i8] c"could not create directory %s\00"
define i32 @cache_open() {
%1 = alloca %struct.stat
%2 = tail call i8* @config_to_path(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%3 = bitcast %struct.stat* %1 to i8*
%4 = call i64 @stat(i8* %2, %struct.stat* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %0
%7 = call i64 @mkdir(i8* %2, i32 511)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = call i32 @musicd_perror(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %11
11: ; preds = %0, %6, %9
%12 = phi i32 [ -1, %9 ], [ 0, %6 ], [ 0, %0 ]
ret i32 %12
}