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

/* Variables and functions */
int EFAULT;
scalar_t__ mkdir(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int stat(char *, struct stat *);
int svc_root_path_init(char *svc_root_path) {
  struct stat svcdir = {0};
  if (stat(svc_root_path, &svcdir) == -1) {
    if (mkdir(svc_root_path, 0700) < 0) {
      printf("Cannot create %s SVC root directory!\n", svc_root_path);
      return -EFAULT;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<svc_root_path_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
jne    11b2 <svc_root_path_init+0x72>
mov    -0x10(%rbp),%rdi
mov    $0x1c0,%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
jge    11ad <svc_root_path_init+0x6d>
mov    -0x10(%rbp),%rsi
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
mov    0x2e55(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11b9 <svc_root_path_init+0x79>
jmp    11b2 <svc_root_path_init+0x72>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<svc_root_path_init>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
movl   $0x0,(%rsp)
mov    %rsp,%rsi
call   1050 <stat@plt>
mov    $0x1,%ebp
cmp    $0xffffffff,%eax
jne    117b <svc_root_path_init+0x4b>
mov    %rbx,%rdi
mov    $0x1c0,%esi
call   1030 <mkdir@plt>
test   %rax,%rax
jns    117b <svc_root_path_init+0x4b>
lea    0xe98(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    0x2e81(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [38 x i8] c"Cannot create %s SVC root directory!\0A\00"
@EFAULT = global i32 0
define i32 @svc_root_path_init(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %3
%5 = bitcast %struct.stat* %4 to i8*
%6 = load i8*, i8** %3
%7 = call i32 @stat(i8* %6, %struct.stat* %4)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %19
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i64 @mkdir(i8* %10, i32 448)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EFAULT
%17 = sub nsw i32 0, %16
store i32 %17, i32* %2
br label %20
18: ; preds = %9
br label %19
19: ; preds = %18, %1
store i32 1, i32* %2
br label %20
20: ; preds = %19, %13
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [38 x i8] c"Cannot create %s SVC root directory!\0A\00"
@EFAULT = global i32 0
define i32 @svc_root_path_init(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
store i32 0, i32* %4
%5 = call i32 @stat(i8* %0, %struct.stat* %2)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %14
7: ; preds = %1
%8 = tail call i64 @mkdir(i8* %0, i32 448)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %0)
%12 = load i32, i32* @EFAULT
%13 = sub nsw i32 0, %12
br label %14
14: ; preds = %1, %7, %10
%15 = phi i32 [ %13, %10 ], [ 1, %7 ], [ 1, %1 ]
ret i32 %15
}