#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 CMSSUPER {
  int dummy;
};
struct CMSINODE {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ cmsfs_error(unsigned char *);
struct CMSINODE *cmsfs_fopen(unsigned char *, struct CMSSUPER *, int);
unsigned char *cmsfs_malloc(scalar_t__);
struct CMSSUPER *cmsfs_vopen(unsigned char *);
scalar_t__ strlen(unsigned char *);
struct CMSINODE *cmsfs_open(unsigned char *filepath, int flag,
                            unsigned char *dn) {
  struct CMSSUPER *vh;
  struct CMSINODE *fh;
  unsigned char *filetemp, *slash, *p, *q, *vn;
  vn = (unsigned char *)dn;
  filetemp = cmsfs_malloc(strlen(filepath) + 1);
  if (filetemp == NULL)
    return NULL;
  slash = p = filetemp;
  q = (unsigned char *)filepath;
  while (*q != 0x00) {
    *p = *q;
    if (*p == '/')
      slash = p;
    p++;
    q++;
  }
  if (*slash == '/') {
    *slash++ = 0x00;
    vn = filetemp;
  }
  if (vn == NULL) {
    cmsfs_error((
        unsigned char *)"cmsfs_open(): incomplete path or missing volume spec");
    return NULL;
  }
  vh = cmsfs_vopen(vn);
  if (vh == NULL)
    return NULL;
  fh = cmsfs_fopen(slash, vh, flag);
  if (fh == NULL)
    return NULL;
  return fh;
}


x86 assembly (clang, -O0):
<cmsfs_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <cmsfs_malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    119c <cmsfs_open+0x4c>
movq   $0x0,-0x8(%rbp)
jmp    12a8 <cmsfs_open+0x158>
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
je     1201 <cmsfs_open+0xb1>
mov    -0x50(%rbp),%rax
mov    (%rax),%cl
mov    -0x48(%rbp),%rax
mov    %cl,(%rax)
mov    -0x48(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x2f,%eax
jne    11e4 <cmsfs_open+0x94>
mov    -0x48(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    11b0 <cmsfs_open+0x60>
mov    -0x40(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x2f,%eax
jne    122b <cmsfs_open+0xdb>
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x40(%rbp)
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    124f <cmsfs_open+0xff>
lea    0xdc3(%rip),%rdi
call   1040 <cmsfs_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    12a8 <cmsfs_open+0x158>
mov    -0x58(%rbp),%rdi
call   1070 <cmsfs_vopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1274 <cmsfs_open+0x124>
movq   $0x0,-0x8(%rbp)
jmp    12a8 <cmsfs_open+0x158>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <cmsfs_fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12a0 <cmsfs_open+0x150>
movq   $0x0,-0x8(%rbp)
jmp    12a8 <cmsfs_open+0x158>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmsfs_open>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %esi,%r14d
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <cmsfs_malloc@plt>
test   %rax,%rax
je     11f4 <cmsfs_open+0xa4>
mov    (%rbx),%cl
mov    %rax,%rbp
test   %cl,%cl
je     11a8 <cmsfs_open+0x58>
add    $0x1,%rbx
mov    %rax,%rdx
mov    %rax,%rbp
nopw   0x0(%rax,%rax,1)
mov    %cl,(%rdx)
cmp    $0x2f,%cl
cmove  %rdx,%rbp
add    $0x1,%rdx
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
jne    1190 <cmsfs_open+0x40>
cmpb   $0x2f,0x0(%rbp)
jne    11e0 <cmsfs_open+0x90>
movb   $0x0,0x0(%rbp)
add    $0x1,%rbp
test   %rax,%rax
je     11e8 <cmsfs_open+0x98>
mov    %rax,%rdi
call   1070 <cmsfs_vopen@plt>
test   %rax,%rax
je     11f4 <cmsfs_open+0xa4>
mov    %rbp,%rdi
mov    %rax,%rsi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <cmsfs_fopen@plt>
mov    %r15,%rax
test   %rax,%rax
jne    11bb <cmsfs_open+0x6b>
lea    0xe11(%rip),%rdi
call   1040 <cmsfs_error@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.CMSINODE = type { i32 }
%struct.CMSSUPER = type { i32 }
@.str = [53 x i8] c"cmsfs_open(): incomplete path or missing volume spec\00"
define %struct.CMSINODE* @cmsfs_open(i8* %0, i32 %1, i8* %2) {
%4 = alloca %struct.CMSINODE*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.CMSSUPER*
%9 = alloca %struct.CMSINODE*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%15 = load i8*, i8** %7
store i8* %15, i8** %14
%16 = load i8*, i8** %5
%17 = call i64 @strlen(i8* %16)
%18 = add nsw i64 %17, 1
%19 = call i8* @cmsfs_malloc(i64 %18)
store i8* %19, i8** %10
%20 = load i8*, i8** %10
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %3
store %struct.CMSINODE* null, %struct.CMSINODE** %4
br label %76
23: ; preds = %3
%24 = load i8*, i8** %10
store i8* %24, i8** %12
store i8* %24, i8** %11
%25 = load i8*, i8** %5
store i8* %25, i8** %13
br label %26
26: ; preds = %41, %23
%27 = load i8*, i8** %13
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %46
31: ; preds = %26
%32 = load i8*, i8** %13
%33 = load i8, i8* %32
%34 = load i8*, i8** %12
store i8 %33, i8* %34
%35 = load i8*, i8** %12
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = icmp eq i32 %37, 47
br i1 %38, label %39, label %41
39: ; preds = %31
%40 = load i8*, i8** %12
store i8* %40, i8** %11
br label %41
41: ; preds = %39, %31
%42 = load i8*, i8** %12
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %12
%44 = load i8*, i8** %13
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %13
br label %26
46: ; preds = %26
%47 = load i8*, i8** %11
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = icmp eq i32 %49, 47
br i1 %50, label %51, label %55
51: ; preds = %46
%52 = load i8*, i8** %11
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %11
store i8 0, i8* %52
%54 = load i8*, i8** %10
store i8* %54, i8** %14
br label %55
55: ; preds = %51, %46
%56 = load i8*, i8** %14
%57 = icmp eq i8* %56, null
br i1 %57, label %58, label %60
58: ; preds = %55
%59 = call i32 @cmsfs_error(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
store %struct.CMSINODE* null, %struct.CMSINODE** %4
br label %76
60: ; preds = %55
%61 = load i8*, i8** %14
%62 = call %struct.CMSSUPER* @cmsfs_vopen(i8* %61)
store %struct.CMSSUPER* %62, %struct.CMSSUPER** %8
%63 = load %struct.CMSSUPER*, %struct.CMSSUPER** %8
%64 = icmp eq %struct.CMSSUPER* %63, null
br i1 %64, label %65, label %66
65: ; preds = %60
store %struct.CMSINODE* null, %struct.CMSINODE** %4
br label %76
66: ; preds = %60
%67 = load i8*, i8** %11
%68 = load %struct.CMSSUPER*, %struct.CMSSUPER** %8
%69 = load i32, i32* %6
%70 = call %struct.CMSINODE* @cmsfs_fopen(i8* %67, %struct.CMSSUPER* %68, i32 %69)
store %struct.CMSINODE* %70, %struct.CMSINODE** %9
%71 = load %struct.CMSINODE*, %struct.CMSINODE** %9
%72 = icmp eq %struct.CMSINODE* %71, null
br i1 %72, label %73, label %74
73: ; preds = %66
store %struct.CMSINODE* null, %struct.CMSINODE** %4
br label %76
74: ; preds = %66
%75 = load %struct.CMSINODE*, %struct.CMSINODE** %9
store %struct.CMSINODE* %75, %struct.CMSINODE** %4
br label %76
76: ; preds = %74, %73, %65, %58, %22
%77 = load %struct.CMSINODE*, %struct.CMSINODE** %4
ret %struct.CMSINODE* %77
}

LLVM IR (-O2):
%struct.CMSINODE = type { i32 }
%struct.CMSSUPER = type { i32 }
@.str = [53 x i8] c"cmsfs_open(): incomplete path or missing volume spec\00"
define %struct.CMSINODE* @cmsfs_open(i8* nocapture %0, i32 %1, i8* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = add nsw i64 %4, 1
%6 = tail call i8* @cmsfs_malloc(i64 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %39, label %8
8: ; preds = %3
%9 = load i8, i8* %0
%10 = icmp eq i8 %9, 0
br i1 %10, label %22, label %11
11: ; preds = %8, %11
%12 = phi i8 [ %20, %11 ], [ %9, %8 ]
%13 = phi i8* [ %19, %11 ], [ %0, %8 ]
%14 = phi i8* [ %18, %11 ], [ %6, %8 ]
%15 = phi i8* [ %17, %11 ], [ %6, %8 ]
store i8 %12, i8* %14
%16 = icmp eq i8 %12, 47
%17 = select i1 %16, i8* %14, i8* %15
%18 = getelementptr inbounds i8, i8* %14, i64 1
%19 = getelementptr inbounds i8, i8* %13, i64 1
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %11
22: ; preds = %11, %8
%23 = phi i8* [ %6, %8 ], [ %17, %11 ]
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 47
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = getelementptr inbounds i8, i8* %23, i64 1
store i8 0, i8* %23
br label %28
28: ; preds = %26, %22
%29 = phi i8* [ %27, %26 ], [ %23, %22 ]
%30 = phi i8* [ %6, %26 ], [ %2, %22 ]
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = tail call i32 @cmsfs_error(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
br label %39
34: ; preds = %28
%35 = tail call %struct.CMSSUPER* @cmsfs_vopen(i8* %30)
%36 = icmp eq %struct.CMSSUPER* %35, null
br i1 %36, label %39, label %37
37: ; preds = %34
%38 = tail call %struct.CMSINODE* @cmsfs_fopen(i8* %29, %struct.CMSSUPER* %35, i32 %1)
br label %39
39: ; preds = %37, %34, %3, %32
%40 = phi %struct.CMSINODE* [ null, %32 ], [ null, %3 ], [ null, %34 ], [ %38, %37 ]
ret %struct.CMSINODE* %40
}