#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);
size_t num_components(const char *path) {
  size_t n;
  const char *cp;
  for (n = 0, cp = path; (cp = strchr(cp, '/')) != NULL; n++, cp++) {
    while (*cp == '/')
      cp++;
  }
  return n;
}


x86 assembly (clang, -O0):
<num_components>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1190 <num_components+0x80>
jmp    114d <num_components+0x3d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    116e <num_components+0x5e>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    114d <num_components+0x3d>
jmp    1173 <num_components+0x63>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    112c <num_components+0x1c>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<num_components>:
push   %rbx
mov    $0x2f,%esi
call   1030 <strchr@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     114f <num_components+0x3f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmpb   $0x2f,(%rax)
lea    0x1(%rax),%rax
je     1130 <num_components+0x20>
add    $0x1,%rbx
mov    %rax,%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1130 <num_components+0x20>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i64 @num_components(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
store i8* %0, i8** %2
store i64 0, i64* %3
%5 = load i8*, i8** %2
store i8* %5, i8** %4
br label %6
6: ; preds = %20, %1
%7 = load i8*, i8** %4
%8 = call i8* @strchr(i8* %7, i8 signext 47)
store i8* %8, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %25
10: ; preds = %6
br label %11
11: ; preds = %16, %10
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 47
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %4
br label %11
19: ; preds = %11
br label %20
20: ; preds = %19
%21 = load i64, i64* %3
%22 = add i64 %21, 1
store i64 %22, i64* %3
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
br label %6
25: ; preds = %6
%26 = load i64, i64* %3
ret i64 %26
}

LLVM IR (-O2):
define i64 @num_components(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 47)
%3 = icmp eq i8* %2, null
br i1 %3, label %16, label %4
4: ; preds = %1, %12
%5 = phi i8* [ %14, %12 ], [ %2, %1 ]
%6 = phi i64 [ %13, %12 ], [ 0, %1 ]
br label %7
7: ; preds = %7, %4
%8 = phi i8* [ %11, %7 ], [ %5, %4 ]
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 47
%11 = getelementptr inbounds i8, i8* %8, i64 1
br i1 %10, label %7, label %12
12: ; preds = %7
%13 = add i64 %6, 1
%14 = tail call i8* @strchr(i8* dereferenceable(1) %11, i8 signext 47)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %4
16: ; preds = %12, %1
%17 = phi i64 [ 0, %1 ], [ %13, %12 ]
ret i64 %17
}