#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 num_pathname_components(const char *x) {
  int num = 0;
  while ((x = strchr(x, '/')) != NULL) {
    while (*x == '/')
      x++;
    num++;
  }
  return num;
}


x86 assembly (clang, -O0):
<num_pathname_components>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     1173 <num_pathname_components+0x63>
jmp    1144 <num_pathname_components+0x34>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1165 <num_pathname_components+0x55>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1144 <num_pathname_components+0x34>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <num_pathname_components+0x13>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<num_pathname_components>:
push   %rbx
mov    $0x2f,%esi
call   1030 <strchr@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     115f <num_pathname_components+0x4f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0xffffffffffffffff,%rax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0x2f,0x1(%rax)
lea    0x1(%rax),%rax
je     1140 <num_pathname_components+0x30>
add    $0x1,%ebx
mov    %rax,%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1130 <num_pathname_components+0x20>
mov    %ebx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @num_pathname_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 i32 [ %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 nuw nsw i32 %6, 1
%14 = tail call i8* @strchr(i8* dereferenceable(1) %8, i8 signext 47)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %4
16: ; preds = %12, %1
%17 = phi i32 [ 0, %1 ], [ %13, %12 ]
ret i32 %17
}