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

/* Variables and functions */
int Xorriso_auto_chmod(struct XorrisO *, char *, int);
int /*<<< orphan*/ Xorriso_no_malloc_memory(struct XorrisO *,
                                            int /*<<< orphan*/ *,
                                            int /*<<< orphan*/);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(char *);
char *strchr(char *, char);
int /*<<< orphan*/ strncpy(char *, char *, int);
int Xorriso_make_accessible(struct XorrisO *xorriso, char *disk_path,
                            int flag) {
  int done = 0, ret, just_rx = 2;
  char *npt, *apt, *path, *wpt;
  {
    path = (char *)calloc(1, (4096) * sizeof(char));
    if (path == NULL) {
      Xorriso_no_malloc_memory(xorriso, NULL, 0);
      ret = -1;
      goto ex;
    }
  };
  apt = disk_path;
  wpt = path;
  for (npt = apt; !done; apt = npt + 1) {
    npt = strchr(apt, '/');
    if (npt == NULL)
      break;
    if (strchr(npt + 1, '/') == NULL)
      just_rx = 0;
    strncpy(wpt, apt, npt + 1 - apt);
    wpt += npt + 1 - apt;
    *wpt = 0;
    ret = Xorriso_auto_chmod(xorriso, path, just_rx);
    if (ret == -1) {
      ret = -1;
      goto ex;
    }
    if (ret == -2) {
      ret = 0;
      goto ex;
    }
  }
  ret = 1;
ex : {
  if (path != NULL)
    free((char *)path);
};
  return (ret);
}


x86 assembly (clang, -O0):
<Xorriso_make_accessible>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x2,-0x20(%rbp)
mov    $0x1,%edi
mov    $0x1000,%esi
call   1060 <calloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11ba <Xorriso_make_accessible+0x5a>
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <Xorriso_no_malloc_memory@plt>
movl   $0xffffffff,-0x1c(%rbp)
jmp    12c5 <Xorriso_make_accessible+0x165>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e8 <Xorriso_make_accessible+0x88>
jmp    12be <Xorriso_make_accessible+0x15e>
mov    -0x30(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    120a <Xorriso_make_accessible+0xaa>
jmp    12be <Xorriso_make_accessible+0x15e>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
jne    122d <Xorriso_make_accessible+0xcd>
movl   $0x0,-0x20(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1040 <strncpy@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1080 <Xorriso_auto_chmod@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1292 <Xorriso_make_accessible+0x132>
movl   $0xffffffff,-0x1c(%rbp)
jmp    12c5 <Xorriso_make_accessible+0x165>
cmpl   $0xfffffffe,-0x1c(%rbp)
jne    12a8 <Xorriso_make_accessible+0x148>
movl   $0x0,-0x1c(%rbp)
jmp    12c5 <Xorriso_make_accessible+0x165>
jmp    12ad <Xorriso_make_accessible+0x14d>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11d2 <Xorriso_make_accessible+0x72>
movl   $0x1,-0x1c(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     12d9 <Xorriso_make_accessible+0x179>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Xorriso_make_accessible>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x1,%edi
mov    $0x1000,%esi
call   1060 <calloc@plt>
test   %rax,%rax
je     1227 <Xorriso_make_accessible+0xc7>
mov    %rax,%r14
mov    %rbx,0x10(%rsp)
mov    $0x2,%r13d
mov    %rax,%rbx
mov    %rax,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     123b <Xorriso_make_accessible+0xdb>
mov    %rax,%r12
add    $0x1,%r12
mov    %r12,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
test   %rax,%rax
mov    $0x0,%eax
cmove  %eax,%r13d
mov    %r12,%rbp
sub    %r15,%rbp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1040 <strncpy@plt>
movb   $0x0,(%rbx,%rbp,1)
mov    0x10(%rsp),%rdi
mov    %r14,%rsi
mov    %r13d,%edx
call   1080 <Xorriso_auto_chmod@plt>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
je     1241 <Xorriso_make_accessible+0xe1>
add    %rbp,%rbx
mov    %r12,%r15
cmp    $0xfffffffe,%r14d
mov    0x8(%rsp),%r14
jne    11b0 <Xorriso_make_accessible+0x50>
xor    %r14d,%r14d
jmp    1241 <Xorriso_make_accessible+0xe1>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <Xorriso_no_malloc_memory@plt>
mov    $0xffffffff,%r14d
jmp    124b <Xorriso_make_accessible+0xeb>
mov    $0x1,%r14d
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.XorrisO = type { i32 }
define i32 @Xorriso_make_accessible(%struct.XorrisO* %0, i8* %1, i32 %2) {
%4 = alloca %struct.XorrisO*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
store %struct.XorrisO* %0, %struct.XorrisO** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i32 2, i32* %9
%14 = call i64 @calloc(i32 1, i32 4096)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %12
%16 = load i8*, i8** %12
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %3
%19 = load %struct.XorrisO*, %struct.XorrisO** %4
%20 = call i32 @Xorriso_no_malloc_memory(%struct.XorrisO* %19, i32* null, i32 0)
store i32 -1, i32* %8
br label %77
21: ; preds = %3
%22 = load i8*, i8** %5
store i8* %22, i8** %11
%23 = load i8*, i8** %12
store i8* %23, i8** %13
%24 = load i8*, i8** %11
store i8* %24, i8** %10
br label %25
25: ; preds = %73, %21
%26 = load i32, i32* %7
%27 = icmp ne i32 %26, 0
%28 = xor i1 %27, true
br i1 %28, label %29, label %76
29: ; preds = %25
%30 = load i8*, i8** %11
%31 = call i8* @strchr(i8* %30, i8 signext 47)
store i8* %31, i8** %10
%32 = load i8*, i8** %10
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %35
34: ; preds = %29
br label %76
35: ; preds = %29
%36 = load i8*, i8** %10
%37 = getelementptr inbounds i8, i8* %36, i64 1
%38 = call i8* @strchr(i8* %37, i8 signext 47)
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %41
40: ; preds = %35
store i32 0, i32* %9
br label %41
41: ; preds = %40, %35
%42 = load i8*, i8** %13
%43 = load i8*, i8** %11
%44 = load i8*, i8** %10
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = load i8*, i8** %11
%47 = ptrtoint i8* %45 to i64
%48 = ptrtoint i8* %46 to i64
%49 = sub i64 %47, %48
%50 = trunc i64 %49 to i32
%51 = call i32 @strncpy(i8* %42, i8* %43, i32 %50)
%52 = load i8*, i8** %10
%53 = getelementptr inbounds i8, i8* %52, i64 1
%54 = load i8*, i8** %11
%55 = ptrtoint i8* %53 to i64
%56 = ptrtoint i8* %54 to i64
%57 = sub i64 %55, %56
%58 = load i8*, i8** %13
%59 = getelementptr inbounds i8, i8* %58, i64 %57
store i8* %59, i8** %13
%60 = load i8*, i8** %13
store i8 0, i8* %60
%61 = load %struct.XorrisO*, %struct.XorrisO** %4
%62 = load i8*, i8** %12
%63 = load i32, i32* %9
%64 = call i32 @Xorriso_auto_chmod(%struct.XorrisO* %61, i8* %62, i32 %63)
store i32 %64, i32* %8
%65 = load i32, i32* %8
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %68
67: ; preds = %41
store i32 -1, i32* %8
br label %77
68: ; preds = %41
%69 = load i32, i32* %8
%70 = icmp eq i32 %69, -2
br i1 %70, label %71, label %72
71: ; preds = %68
store i32 0, i32* %8
br label %77
72: ; preds = %68
br label %73
73: ; preds = %72
%74 = load i8*, i8** %10
%75 = getelementptr inbounds i8, i8* %74, i64 1
store i8* %75, i8** %11
br label %25
76: ; preds = %34, %25
store i32 1, i32* %8
br label %77
77: ; preds = %76, %71, %67, %18
%78 = load i8*, i8** %12
%79 = icmp ne i8* %78, null
br i1 %79, label %80, label %83
80: ; preds = %77
%81 = load i8*, i8** %12
%82 = call i32 @free(i8* %81)
br label %83
83: ; preds = %80, %77
%84 = load i32, i32* %8
ret i32 %84
}

LLVM IR (-O2):
%struct.XorrisO = type { i32 }
define i32 @Xorriso_make_accessible(%struct.XorrisO* %0, i8* %1, i32 %2) {
%4 = tail call i64 @calloc(i32 1, i32 4096)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %4, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @Xorriso_no_malloc_memory(%struct.XorrisO* %0, i32* null, i32 0)
br label %32
9: ; preds = %3, %15
%10 = phi i32 [ %19, %15 ], [ 2, %3 ]
%11 = phi i8* [ %16, %15 ], [ %1, %3 ]
%12 = phi i8* [ %25, %15 ], [ %5, %3 ]
%13 = tail call i8* @strchr(i8* dereferenceable(1) %11, i8 signext 47)
%14 = icmp eq i8* %13, null
br i1 %14, label %27, label %15
15: ; preds = %9
%16 = getelementptr inbounds i8, i8* %13, i64 1
%17 = tail call i8* @strchr(i8* %16, i8 signext 47)
%18 = icmp eq i8* %17, null
%19 = select i1 %18, i32 0, i32 %10
%20 = ptrtoint i8* %16 to i64
%21 = ptrtoint i8* %11 to i64
%22 = sub i64 %20, %21
%23 = trunc i64 %22 to i32
%24 = tail call i32 @strncpy(i8* %12, i8* %11, i32 %23)
%25 = getelementptr inbounds i8, i8* %12, i64 %22
store i8 0, i8* %25
%26 = tail call i32 @Xorriso_auto_chmod(%struct.XorrisO* %0, i8* %5, i32 %19)
switch i32 %26, label %9 [
i32 -1, label %27
i32 -2, label %29
]
27: ; preds = %9, %15
%28 = phi i32 [ 1, %9 ], [ %26, %15 ]
br label %29
29: ; preds = %15, %27
%30 = phi i32 [ %28, %27 ], [ 0, %15 ]
%31 = tail call i32 @free(i8* %5)
br label %32
32: ; preds = %7, %29
%33 = phi i32 [ -1, %7 ], [ %30, %29 ]
ret i32 %33
}