int count_components(const char *p) {
  int ctr;
  for (; *p == '/'; p++)
    ;
  for (ctr = 0; *p; ctr++) {
    for (; *p && *p != '/'; p++)
      ;
    for (; *p == '/'; p++)
      ;
  }
  return ctr;
}


x86 assembly (clang, -O0):
<count_components>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    112e <count_components+0x2e>
jmp    111d <count_components+0x1d>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1108 <count_components+0x8>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d0 <count_components+0xd0>
jmp    1147 <count_components+0x47>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xd(%rbp)
je     116c <count_components+0x6c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    117c <count_components+0x7c>
jmp    1192 <count_components+0x92>
jmp    1181 <count_components+0x81>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1147 <count_components+0x47>
jmp    1197 <count_components+0x97>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11bd <count_components+0xbd>
jmp    11ac <count_components+0xac>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1197 <count_components+0x97>
jmp    11c2 <count_components+0xc2>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1135 <count_components+0x35>
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_components>:
add    $0xffffffffffffffff,%rdi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl 0x1(%rdi),%ecx
add    $0x1,%rdi
cmp    $0x2f,%cl
je     1110 <count_components+0x10>
xor    %eax,%eax
test   %cl,%cl
je     1174 <count_components+0x74>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rdi,%rdx
add    $0xffffffffffffffff,%rdi
cmp    $0x2f,%cl
je     1160 <count_components+0x60>
nopl   0x0(%rax)
test   %cl,%cl
je     1160 <count_components+0x60>
movzbl 0x1(%rdx),%ecx
add    $0x1,%rdx
add    $0x1,%rdi
cmp    $0x2f,%cl
jne    1140 <count_components+0x40>
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x1(%rdi),%ecx
add    $0x1,%rdi
cmp    $0x2f,%cl
je     1160 <count_components+0x60>
add    $0x1,%eax
test   %cl,%cl
jne    1130 <count_components+0x30>
ret

LLVM IR (-O0):
define i32 @count_components(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
br label %4
4: ; preds = %10, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp eq i32 %7, 47
br i1 %8, label %9, label %13
9: ; preds = %4
br label %10
10: ; preds = %9
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %2
br label %4
13: ; preds = %4
store i32 0, i32* %3
br label %14
14: ; preds = %46, %13
%15 = load i8*, i8** %2
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
br i1 %17, label %18, label %49
18: ; preds = %14
br label %19
19: ; preds = %32, %18
%20 = load i8*, i8** %2
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = load i8*, i8** %2
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 47
br label %29
29: ; preds = %24, %19
%30 = phi i1 [ false, %19 ], [ %28, %24 ]
br i1 %30, label %31, label %35
31: ; preds = %29
br label %32
32: ; preds = %31
%33 = load i8*, i8** %2
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %2
br label %19
35: ; preds = %29
br label %36
36: ; preds = %42, %35
%37 = load i8*, i8** %2
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 47
br i1 %40, label %41, label %45
41: ; preds = %36
br label %42
42: ; preds = %41
%43 = load i8*, i8** %2
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %2
br label %36
45: ; preds = %36
br label %46
46: ; preds = %45
%47 = load i32, i32* %3
%48 = add nsw i32 %47, 1
store i32 %48, i32* %3
br label %14
49: ; preds = %14
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
define i32 @count_components(i8* nocapture %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8* [ %0, %1 ], [ %5, %2 ]
%4 = load i8, i8* %3
%5 = getelementptr inbounds i8, i8* %3, i64 1
switch i8 %4, label %6 [
i8 47, label %2
i8 0, label %25
]
6: ; preds = %2, %22
%7 = phi i8 [ %19, %22 ], [ %4, %2 ]
%8 = phi i32 [ %23, %22 ], [ 0, %2 ]
%9 = phi i8* [ %18, %22 ], [ %3, %2 ]
br label %10
10: ; preds = %6, %14
%11 = phi i8 [ %16, %14 ], [ %7, %6 ]
%12 = phi i8* [ %15, %14 ], [ %9, %6 ]
switch i8 %11, label %14 [
i8 0, label %13
i8 47, label %13
]
13: ; preds = %10, %10
br label %17
14: ; preds = %10
%15 = getelementptr inbounds i8, i8* %12, i64 1
%16 = load i8, i8* %15
br label %10
17: ; preds = %13, %17
%18 = phi i8* [ %21, %17 ], [ %12, %13 ]
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 47
%21 = getelementptr inbounds i8, i8* %18, i64 1
br i1 %20, label %17, label %22
22: ; preds = %17
%23 = add nuw nsw i32 %8, 1
%24 = icmp eq i8 %19, 0
br i1 %24, label %25, label %6
25: ; preds = %2, %22
%26 = phi i32 [ %23, %22 ], [ 0, %2 ]
ret i32 %26
}