#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 PATH_MAX;
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
int get_depth(char *filename) {
  char local_filename[PATH_MAX];
  int depth = 0;
  char *pstr = NULL;
  strcpy(local_filename, filename);
  if (filename == NULL)
    return -1;
  pstr = strtok(local_filename, "/");
  while (pstr != NULL) {
    pstr = strtok(NULL, "/");
    depth++;
  }
  return depth - 2;
}


x86 assembly (clang, -O0):
<get_depth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ebd(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
cmpq   $0x0,-0x10(%rbp)
jne    118e <get_depth+0x6e>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    11df <get_depth+0xbf>
mov    -0x40(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11cf <get_depth+0xaf>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe48(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a2 <get_depth+0x82>
mov    -0x24(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_depth>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2ebf(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
test   %r14,%r14
je     1194 <get_depth+0x74>
lea    0xea5(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strtok@plt>
mov    $0xfffffffe,%ebx
test   %rax,%rax
je     1199 <get_depth+0x79>
lea    0xe8c(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <strtok@plt>
add    $0x1,%ebx
test   %rax,%rax
jne    1180 <get_depth+0x60>
jmp    1199 <get_depth+0x79>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [2 x i8] c"/\00"
define i32 @get_depth(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %4
%12 = alloca i8, i64 %10
store i64 %10, i64* %5
store i32 0, i32* %6
store i8* null, i8** %7
%13 = load i8*, i8** %3
%14 = call i32 @strcpy(i8* %12, i8* %13)
%15 = load i8*, i8** %3
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %1
store i32 -1, i32* %2
store i32 1, i32* %8
br label %30
18: ; preds = %1
%19 = call i8* @strtok(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %19, i8** %7
br label %20
20: ; preds = %23, %18
%21 = load i8*, i8** %7
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %24, i8** %7
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %20
27: ; preds = %20
%28 = load i32, i32* %6
%29 = sub nsw i32 %28, 2
store i32 %29, i32* %2
store i32 1, i32* %8
br label %30
30: ; preds = %27, %17
%31 = load i8*, i8** %4
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [2 x i8] c"/\00"
define i32 @get_depth(i8* %0) {
%2 = load i32, i32* @PATH_MAX
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = call i32 @strcpy(i8* %4, i8* %0)
%6 = icmp eq i8* %0, null
br i1 %6, label %17, label %7
7: ; preds = %1
%8 = call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %17, label %10
10: ; preds = %7, %10
%11 = phi i32 [ %13, %10 ], [ 0, %7 ]
%12 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = add nuw nsw i32 %11, 1
%14 = icmp eq i8* %12, null
br i1 %14, label %15, label %10
15: ; preds = %10
%16 = add nsw i32 %11, -1
br label %17
17: ; preds = %7, %15, %1
%18 = phi i32 [ -1, %1 ], [ -2, %7 ], [ %16, %15 ]
ret i32 %18
}