#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);
scalar_t__ strncmp(char const *, char *, int);
int strspn(char const *, char *);
int depth(const char *path) {
  int n = 0;
  for (;;) {
    if (strncmp(path, "./", 2) == 0)
      path += 2;
    else if (strncmp(path, "../", 3) == 0) {
      path += 3;
      if (--n < 0)
        return n;
    } else if ((path = strchr(path, '/')))
      ++n;
    else
      return n;
    path = path + strspn(path, "/");
  }
}


x86 assembly (clang, -O0):
<depth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb3(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1173 <depth+0x43>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
jmp    11ff <depth+0xcf>
mov    -0x10(%rbp),%rdi
lea    0xe82(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11c0 <depth+0x90>
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11bb <depth+0x8b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    122c <depth+0xfc>
jmp    11fa <depth+0xca>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11ea <depth+0xba>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f5 <depth+0xc5>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    122c <depth+0xfc>
jmp    11fa <depth+0xca>
jmp    11ff <depth+0xcf>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   1050 <strspn@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    1143 <depth+0x13>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<depth>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %r13d,%r13d
lea    0xeb9(%rip),%r14
lea    0xeb3(%rip),%r15
lea    0xeaa(%rip),%r12
jmp    1178 <depth+0x48>
nopl   0x0(%rax,%rax,1)
add    $0x2,%rbx
mov    %rbx,%rbp
mov    %rbp,%rdi
mov    %r15,%rsi
call   1050 <strspn@plt>
movslq %eax,%rbx
add    %rbp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1160 <depth+0x30>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11c0 <depth+0x90>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11d8 <depth+0xa8>
mov    %rax,%rbp
add    $0x1,%r13d
jmp    1167 <depth+0x37>
nopl   (%rax)
lea    -0x1(%r13),%eax
test   %r13d,%r13d
jle    11d5 <depth+0xa5>
add    $0x3,%rbx
mov    %rbx,%rbp
mov    %eax,%r13d
jmp    1167 <depth+0x37>
mov    %eax,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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