#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 */
char *strchr(char const *, char);
int /*<<< orphan*/ strspn(char const *, char *);
int M_PathParts(const char *path) {
  int n;
  const char *p;
  const char *t;
  if (path == NULL)
    return 0;
  for (n = 0, p = path;; ++n) {
    t = p;
    if ((p = strchr(p, "/"[0])))
      p += strspn(p, "/");
    else {
      if (*t)
        n++;
      break;
    }
  }
  return n;
}


x86 assembly (clang, -O0):
<M_PathParts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1143 <M_PathParts+0x23>
movl   $0x0,-0x4(%rbp)
jmp    11d1 <M_PathParts+0xb1>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
movsbl 0xe9b(%rip),%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     119d <M_PathParts+0x7d>
mov    -0x20(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1040 <strspn@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    11b8 <M_PathParts+0x98>
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b3 <M_PathParts+0x93>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11cb <M_PathParts+0xab>
jmp    11bd <M_PathParts+0x9d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1152 <M_PathParts+0x32>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<M_PathParts>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     117c <M_PathParts+0x5c>
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1181 <M_PathParts+0x61>
mov    %rax,%rbp
xor    %r15d,%r15d
lea    0xeb5(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r14,%rsi
call   1040 <strspn@plt>
movslq %eax,%rbx
add    %rbp,%rbx
add    $0x1,%r15d
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1150 <M_PathParts+0x30>
jmp    1184 <M_PathParts+0x64>
xor    %r15d,%r15d
jmp    118b <M_PathParts+0x6b>
xor    %r15d,%r15d
cmpb   $0x1,(%rbx)
sbb    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i32 @M_PathParts(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %2
br label %38
10: ; preds = %1
store i32 0, i32* %4
%11 = load i8*, i8** %3
store i8* %11, i8** %5
br label %12
12: ; preds = %33, %10
%13 = load i8*, i8** %5
store i8* %13, i8** %6
%14 = load i8*, i8** %5
%15 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%16 = call i8* @strchr(i8* %14, i8 signext %15)
store i8* %16, i8** %5
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %24
18: ; preds = %12
%19 = load i8*, i8** %5
%20 = call i32 @strspn(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = load i8*, i8** %5
%22 = sext i32 %20 to i64
%23 = getelementptr inbounds i8, i8* %21, i64 %22
store i8* %23, i8** %5
br label %32
24: ; preds = %12
%25 = load i8*, i8** %6
%26 = load i8, i8* %25
%27 = icmp ne i8 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %31
31: ; preds = %28, %24
br label %36
32: ; preds = %18
br label %33
33: ; preds = %32
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %12
36: ; preds = %31
%37 = load i32, i32* %4
store i32 %37, i32* %2
br label %38
38: ; preds = %36, %9
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i32 @M_PathParts(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %22, label %3
3: ; preds = %1
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 47)
%5 = icmp eq i8* %4, null
br i1 %5, label %15, label %6
6: ; preds = %3, %6
%7 = phi i8* [ %13, %6 ], [ %4, %3 ]
%8 = phi i32 [ %12, %6 ], [ 0, %3 ]
%9 = tail call i32 @strspn(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %7, i64 %10
%12 = add nuw nsw i32 %8, 1
%13 = tail call i8* @strchr(i8* dereferenceable(1) %11, i8 signext 47)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %6
15: ; preds = %6, %3
%16 = phi i32 [ 0, %3 ], [ %12, %6 ]
%17 = phi i8* [ %0, %3 ], [ %11, %6 ]
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
%20 = zext i1 %19 to i32
%21 = add nuw nsw i32 %16, %20
br label %22
22: ; preds = %1, %15
%23 = phi i32 [ %21, %15 ], [ 0, %1 ]
ret i32 %23
}