#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 */

/* Variables and functions */
int /*<<< orphan*/ g_create_dir(char *);
int /*<<< orphan*/ g_directory_exist(char *);
int /*<<< orphan*/ g_free(char *);
char *g_strdup(char const *);
char *strchr(char *, char);
int g_create_path(const char *path) {
  char *pp;
  char *sp;
  char *copypath;
  int status;
  status = 1;
  copypath = g_strdup(path);
  pp = copypath;
  sp = strchr(pp, '/');
  while (sp != 0) {
    if (sp != pp) {
      *sp = 0;
      if (!g_directory_exist(copypath)) {
        if (!g_create_dir(copypath)) {
          status = 0;
          break;
        }
      }
      *sp = '/';
    }
    pp = sp + 1;
    sp = strchr(pp, '/');
  }
  g_free(copypath);
  return status;
}


x86 assembly (clang, -O0):
<g_create_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <g_strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1209 <g_create_path+0xb9>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11e6 <g_create_path+0x96>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1050 <g_directory_exist@plt>
cmp    $0x0,%eax
jne    11df <g_create_path+0x8f>
mov    -0x20(%rbp),%rdi
call   1040 <g_create_dir@plt>
cmp    $0x0,%eax
jne    11da <g_create_path+0x8a>
movl   $0x0,-0x24(%rbp)
jmp    1209 <g_create_path+0xb9>
jmp    11df <g_create_path+0x8f>
mov    -0x18(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
mov    %rax,-0x18(%rbp)
jmp    118a <g_create_path+0x3a>
mov    -0x20(%rbp),%rdi
call   1030 <g_free@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<g_create_path>:
push   %rbp
push   %r14
push   %rbx
call   1070 <g_strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
mov    $0x1,%r14d
test   %rax,%rax
je     11c4 <g_create_path+0x74>
mov    %rax,%rbp
mov    %rbx,%rcx
jmp    11a0 <g_create_path+0x50>
nopl   0x0(%rax)
movb   $0x2f,0x0(%rbp)
add    $0x1,%rbp
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
mov    %rbp,%rcx
mov    %rax,%rbp
test   %rax,%rax
je     11c4 <g_create_path+0x74>
cmp    %rcx,%rbp
je     1184 <g_create_path+0x34>
movb   $0x0,0x0(%rbp)
mov    %rbx,%rdi
call   1050 <g_directory_exist@plt>
test   %eax,%eax
jne    1180 <g_create_path+0x30>
mov    %rbx,%rdi
call   1040 <g_create_dir@plt>
test   %eax,%eax
jne    1180 <g_create_path+0x30>
xor    %r14d,%r14d
mov    %rbx,%rdi
call   1030 <g_free@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @g_create_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %2
store i32 1, i32* %6
%7 = load i8*, i8** %2
%8 = call i8* @g_strdup(i8* %7)
store i8* %8, i8** %5
%9 = load i8*, i8** %5
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = call i8* @strchr(i8* %10, i8 signext 47)
store i8* %11, i8** %4
br label %12
12: ; preds = %32, %1
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %37
15: ; preds = %12
%16 = load i8*, i8** %4
%17 = load i8*, i8** %3
%18 = icmp ne i8* %16, %17
br i1 %18, label %19, label %32
19: ; preds = %15
%20 = load i8*, i8** %4
store i8 0, i8* %20
%21 = load i8*, i8** %5
%22 = call i32 @g_directory_exist(i8* %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %30, label %24
24: ; preds = %19
%25 = load i8*, i8** %5
%26 = call i32 @g_create_dir(i8* %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %29, label %28
28: ; preds = %24
store i32 0, i32* %6
br label %37
29: ; preds = %24
br label %30
30: ; preds = %29, %19
%31 = load i8*, i8** %4
store i8 47, i8* %31
br label %32
32: ; preds = %30, %15
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8* %34, i8** %3
%35 = load i8*, i8** %3
%36 = call i8* @strchr(i8* %35, i8 signext 47)
store i8* %36, i8** %4
br label %12
37: ; preds = %28, %12
%38 = load i8*, i8** %5
%39 = call i32 @g_free(i8* %38)
%40 = load i32, i32* %6
ret i32 %40
}

LLVM IR (-O2):
define i32 @g_create_path(i8* %0) {
%2 = tail call i8* @g_strdup(i8* %0)
%3 = tail call i8* @strchr(i8* dereferenceable(1) %2, i8 signext 47)
%4 = icmp eq i8* %3, null
br i1 %4, label %20, label %5
5: ; preds = %1, %16
%6 = phi i8* [ %17, %16 ], [ %2, %1 ]
%7 = phi i8* [ %18, %16 ], [ %3, %1 ]
%8 = icmp eq i8* %7, %6
br i1 %8, label %16, label %9
9: ; preds = %5
store i8 0, i8* %7
%10 = tail call i32 @g_directory_exist(i8* %2)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = tail call i32 @g_create_dir(i8* %2)
%14 = icmp eq i32 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %12, %9
store i8 47, i8* %7
br label %16
16: ; preds = %15, %5
%17 = getelementptr inbounds i8, i8* %7, i64 1
%18 = tail call i8* @strchr(i8* %17, i8 signext 47)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %5
20: ; preds = %16, %12, %1
%21 = phi i32 [ 1, %1 ], [ 0, %12 ], [ 1, %16 ]
%22 = tail call i32 @g_free(i8* %2)
ret i32 %21
}