#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*/ CMUTIL_PathCreate(char *, int);
int /*<<< orphan*/ strncat(char *, char const *, size_t);
char *strrchr(char const *, char);
void CMUTIL_LogPathCreate(const char *fpath) {
  char pdir[1024] = {
      0,
  };
  const char *p, *q;
  p = strrchr(fpath, '/');
  q = strrchr(fpath, '\\');
  if (p && q) {
    p = p > q ? p : q;
  } else if (q) {
    p = q;
  }
  strncat(pdir, fpath, (size_t)(p - fpath));
  CMUTIL_PathCreate(pdir, 0755);
}


x86 assembly (clang, -O0):
<CMUTIL_LogPathCreate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x418(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x5c,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     11f0 <CMUTIL_LogPathCreate+0xb0>
cmpq   $0x0,-0x420(%rbp)
je     11f0 <CMUTIL_LogPathCreate+0xb0>
mov    -0x418(%rbp),%rax
cmp    -0x420(%rbp),%rax
jbe    11cf <CMUTIL_LogPathCreate+0x8f>
mov    -0x418(%rbp),%rax
mov    %rax,-0x428(%rbp)
jmp    11dd <CMUTIL_LogPathCreate+0x9d>
mov    -0x420(%rbp),%rax
mov    %rax,-0x428(%rbp)
mov    -0x428(%rbp),%rax
mov    %rax,-0x418(%rbp)
jmp    1211 <CMUTIL_LogPathCreate+0xd1>
cmpq   $0x0,-0x420(%rbp)
je     120c <CMUTIL_LogPathCreate+0xcc>
mov    -0x420(%rbp),%rax
mov    %rax,-0x418(%rbp)
jmp    1211 <CMUTIL_LogPathCreate+0xd1>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x418(%rbp),%rdx
mov    -0x8(%rbp),%rax
sub    %rax,%rdx
call   1050 <strncat@plt>
lea    -0x410(%rbp),%rdi
mov    $0x1ed,%esi
call   1060 <CMUTIL_PathCreate@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CMUTIL_LogPathCreate>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r15
mov    %rsp,%r14
mov    $0x400,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %r15,%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x5c,%esi
call   1030 <strrchr@plt>
cmp    %rax,%rbx
mov    %rax,%rdx
cmova  %rbx,%rdx
test   %rax,%rax
cmove  %rbx,%rax
cmove  %rax,%rdx
test   %rbx,%rbx
cmove  %rax,%rdx
sub    %r15,%rdx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <strncat@plt>
mov    %r14,%rdi
mov    $0x1ed,%esi
call   1060 <CMUTIL_PathCreate@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @CMUTIL_LogPathCreate(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = bitcast [1024 x i8]* %3 to i8*
%7 = load i8*, i8** %2
%8 = call i8* @strrchr(i8* %7, i8 signext 47)
store i8* %8, i8** %4
%9 = load i8*, i8** %2
%10 = call i8* @strrchr(i8* %9, i8 signext 92)
store i8* %10, i8** %5
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %26
13: ; preds = %1
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = load i8*, i8** %4
%18 = load i8*, i8** %5
%19 = icmp ugt i8* %17, %18
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = load i8*, i8** %4
br label %24
22: ; preds = %16
%23 = load i8*, i8** %5
br label %24
24: ; preds = %22, %20
%25 = phi i8* [ %21, %20 ], [ %23, %22 ]
store i8* %25, i8** %4
br label %32
26: ; preds = %13, %1
%27 = load i8*, i8** %5
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = load i8*, i8** %5
store i8* %30, i8** %4
br label %31
31: ; preds = %29, %26
br label %32
32: ; preds = %31, %24
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%34 = load i8*, i8** %2
%35 = load i8*, i8** %4
%36 = load i8*, i8** %2
%37 = ptrtoint i8* %35 to i64
%38 = ptrtoint i8* %36 to i64
%39 = sub i64 %37, %38
%40 = call i32 @strncat(i8* %33, i8* %34, i64 %39)
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%42 = call i32 @CMUTIL_PathCreate(i8* %41, i32 493)
ret void
}

LLVM IR (-O2):
define void @CMUTIL_LogPathCreate(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%5 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 92)
%6 = icmp ne i8* %4, null
%7 = icmp ne i8* %5, null
%8 = select i1 %6, i1 %7, i1 false
%9 = icmp ugt i8* %4, %5
%10 = select i1 %9, i8* %4, i8* %5
%11 = select i1 %7, i8* %5, i8* %4
%12 = select i1 %8, i8* %10, i8* %11
%13 = ptrtoint i8* %12 to i64
%14 = ptrtoint i8* %0 to i64
%15 = sub i64 %13, %14
%16 = call i32 @strncat(i8* %3, i8* %0, i64 %15)
%17 = call i32 @CMUTIL_PathCreate(i8* %3, i32 493)
ret void
}