#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 */
scalar_t__ strlen(char *);
int fatfs_total_path_levels(char *path) {
  int levels = 0;
  int length = (int)strlen(path);
  char expectedchar;
  if (!path)
    return -1;
  if (*path == '/') {
    expectedchar = '/';
    path++;
  } else if (path[1] == ':' || path[2] == '\\') {
    expectedchar = '\\';
    path += 3;
  } else
    return -1;
  while (*path) {
    for (; *path;) {
      if (*path == expectedchar) {
        path++;
        break;
      }
      *path++;
    }
    levels++;
  }
  return levels - 1;
}


x86 assembly (clang, -O0):
<fatfs_total_path_levels>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1146 <fatfs_total_path_levels+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    1223 <fatfs_total_path_levels+0x113>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    116b <fatfs_total_path_levels+0x5b>
movb   $0x2f,-0x19(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11b3 <fatfs_total_path_levels+0xa3>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x3a,%eax
je     118d <fatfs_total_path_levels+0x7d>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x5c,%eax
jne    11a2 <fatfs_total_path_levels+0x92>
movb   $0x5c,-0x19(%rbp)
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x10(%rbp)
jmp    11ae <fatfs_total_path_levels+0x9e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1223 <fatfs_total_path_levels+0x113>
jmp    11b3 <fatfs_total_path_levels+0xa3>
jmp    11b8 <fatfs_total_path_levels+0xa8>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     121a <fatfs_total_path_levels+0x10a>
jmp    11ca <fatfs_total_path_levels+0xba>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     120c <fatfs_total_path_levels+0xfc>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
jne    11fb <fatfs_total_path_levels+0xeb>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    120c <fatfs_total_path_levels+0xfc>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11ca <fatfs_total_path_levels+0xba>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b8 <fatfs_total_path_levels+0xa8>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fatfs_total_path_levels>:
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     1167 <fatfs_total_path_levels+0x67>
lea    0x1(%rdi),%rcx
cmpb   $0x2f,(%rdi)
mov    $0x2f,%esi
je     112f <fatfs_total_path_levels+0x2f>
cmpb   $0x3a,(%rcx)
je     1123 <fatfs_total_path_levels+0x23>
cmpb   $0x5c,0x2(%rdi)
jne    1167 <fatfs_total_path_levels+0x67>
add    $0x3,%rdi
mov    $0x5c,%esi
mov    %rdi,%rcx
mov    (%rcx),%dl
test   %dl,%dl
je     1167 <fatfs_total_path_levels+0x67>
xor    %edi,%edi
mov    %edi,%eax
add    $0x1,%rcx
nopl   (%rax)
movsbl %dl,%edi
movzbl (%rcx),%edx
cmp    %edi,%esi
je     1160 <fatfs_total_path_levels+0x60>
add    $0x1,%rcx
test   %dl,%dl
jne    1140 <fatfs_total_path_levels+0x40>
jmp    1167 <fatfs_total_path_levels+0x67>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x1(%rax),%edi
test   %dl,%dl
jne    1137 <fatfs_total_path_levels+0x37>
ret

LLVM IR (-O0):
define i32 @fatfs_total_path_levels(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i8* %0, i8** %3
store i32 0, i32* %4
%7 = load i8*, i8** %3
%8 = call i64 @strlen(i8* %7)
%9 = trunc i64 %8 to i32
store i32 %9, i32* %5
%10 = load i8*, i8** %3
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %1
store i32 -1, i32* %2
br label %68
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 47
br i1 %17, label %18, label %21
18: ; preds = %13
store i8 47, i8* %6
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %3
br label %38
21: ; preds = %13
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 58
br i1 %26, label %33, label %27
27: ; preds = %21
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i64 2
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 92
br i1 %32, label %33, label %36
33: ; preds = %27, %21
store i8 92, i8* %6
%34 = load i8*, i8** %3
%35 = getelementptr inbounds i8, i8* %34, i64 3
store i8* %35, i8** %3
br label %37
36: ; preds = %27
store i32 -1, i32* %2
br label %68
37: ; preds = %33
br label %38
38: ; preds = %37, %18
br label %39
39: ; preds = %62, %38
%40 = load i8*, i8** %3
%41 = load i8, i8* %40
%42 = icmp ne i8 %41, 0
br i1 %42, label %43, label %65
43: ; preds = %39
br label %44
44: ; preds = %58, %43
%45 = load i8*, i8** %3
%46 = load i8, i8* %45
%47 = icmp ne i8 %46, 0
br i1 %47, label %48, label %62
48: ; preds = %44
%49 = load i8*, i8** %3
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = load i8, i8* %6
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %51, %53
br i1 %54, label %55, label %58
55: ; preds = %48
%56 = load i8*, i8** %3
%57 = getelementptr inbounds i8, i8* %56, i32 1
store i8* %57, i8** %3
br label %62
58: ; preds = %48
%59 = load i8*, i8** %3
%60 = getelementptr inbounds i8, i8* %59, i32 1
store i8* %60, i8** %3
%61 = load i8, i8* %59
br label %44
62: ; preds = %55, %44
%63 = load i32, i32* %4
%64 = add nsw i32 %63, 1
store i32 %64, i32* %4
br label %39
65: ; preds = %39
%66 = load i32, i32* %4
%67 = sub nsw i32 %66, 1
store i32 %67, i32* %2
br label %68
68: ; preds = %65, %36, %12
%69 = load i32, i32* %2
ret i32 %69
}

LLVM IR (-O2):
define i32 @fatfs_total_path_levels(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %37, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 47
%6 = getelementptr inbounds i8, i8* %0, i64 1
br i1 %5, label %16, label %7
7: ; preds = %3
%8 = load i8, i8* %6
%9 = icmp eq i8 %8, 58
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %0, i64 2
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 92
br i1 %13, label %14, label %37
14: ; preds = %10, %7
%15 = getelementptr inbounds i8, i8* %0, i64 3
br label %16
16: ; preds = %3, %14
%17 = phi i8* [ %15, %14 ], [ %6, %3 ]
%18 = phi i32 [ 92, %14 ], [ 47, %3 ]
%19 = load i8, i8* %17
%20 = icmp eq i8 %19, 0
br i1 %20, label %37, label %21
21: ; preds = %16, %34
%22 = phi i8 [ %31, %34 ], [ %19, %16 ]
%23 = phi i32 [ %35, %34 ], [ 0, %16 ]
%24 = phi i8* [ %30, %34 ], [ %17, %16 ]
br label %25
25: ; preds = %21, %32
%26 = phi i8* [ %24, %21 ], [ %30, %32 ]
%27 = phi i8 [ %22, %21 ], [ %31, %32 ]
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %18, %28
%30 = getelementptr inbounds i8, i8* %26, i64 1
%31 = load i8, i8* %30
br i1 %29, label %34, label %32
32: ; preds = %25
%33 = icmp eq i8 %31, 0
br i1 %33, label %37, label %25
34: ; preds = %25
%35 = add nuw nsw i32 %23, 1
%36 = icmp eq i8 %31, 0
br i1 %36, label %37, label %21
37: ; preds = %34, %32, %16, %10, %1
%38 = phi i32 [ -1, %1 ], [ -1, %10 ], [ -1, %16 ], [ %23, %32 ], [ %23, %34 ]
ret i32 %38
}