#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 */
size_t cl_pid_count(char const *r) {
  size_t n = 0;
  for (; *r != '\0'; r++)
    if (*r == '%') {
      if (r[1] == '%')
        r++;
      else
        n += (r[1] == '$');
    }
  return n;
}


x86 assembly (clang, -O0):
<cl_pid_count>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     118a <cl_pid_count+0x8a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    1174 <cl_pid_count+0x74>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x25,%eax
jne    1152 <cl_pid_count+0x52>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    116f <cl_pid_count+0x6f>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x24,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
cltq
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1174 <cl_pid_count+0x74>
jmp    1179 <cl_pid_count+0x79>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1110 <cl_pid_count+0x10>
mov    -0x10(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<cl_pid_count>:
xor    %eax,%eax
jmp    1118 <cl_pid_count+0x18>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %cl,%cl
je     114d <cl_pid_count+0x4d>
add    $0x1,%rdi
movzbl (%rdi),%ecx
cmp    $0x25,%cl
jne    1110 <cl_pid_count+0x10>
movzbl 0x1(%rdi),%ecx
cmp    $0x25,%cl
jne    1140 <cl_pid_count+0x40>
add    $0x1,%rdi
add    $0x1,%rdi
jmp    1118 <cl_pid_count+0x18>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %edx,%edx
cmp    $0x24,%cl
sete   %dl
add    %rdx,%rax
jmp    1114 <cl_pid_count+0x14>
ret

LLVM IR (-O0):
define i64 @cl_pid_count(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
store i8* %0, i8** %2
store i64 0, i64* %3
br label %4
4: ; preds = %35, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %38
9: ; preds = %4
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 37
br i1 %13, label %14, label %34
14: ; preds = %9
%15 = load i8*, i8** %2
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 37
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i8*, i8** %2
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %2
br label %33
23: ; preds = %14
%24 = load i8*, i8** %2
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 36
%29 = zext i1 %28 to i32
%30 = sext i32 %29 to i64
%31 = load i64, i64* %3
%32 = add i64 %31, %30
store i64 %32, i64* %3
br label %33
33: ; preds = %23, %20
br label %34
34: ; preds = %33, %9
br label %35
35: ; preds = %34
%36 = load i8*, i8** %2
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %2
br label %4
38: ; preds = %4
%39 = load i64, i64* %3
ret i64 %39
}

LLVM IR (-O2):
define i64 @cl_pid_count(i8* nocapture %0) {
br label %2
2: ; preds = %14, %1
%3 = phi i8* [ %0, %1 ], [ %17, %14 ]
%4 = phi i64 [ 0, %1 ], [ %16, %14 ]
%5 = load i8, i8* %3
switch i8 %5, label %14 [
i8 0, label %18
i8 37, label %6
]
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %3, i64 1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 37
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = icmp eq i8 %8, 36
%12 = zext i1 %11 to i64
%13 = add i64 %4, %12
br label %14
14: ; preds = %6, %2, %10
%15 = phi i8* [ %3, %10 ], [ %3, %2 ], [ %7, %6 ]
%16 = phi i64 [ %13, %10 ], [ %4, %2 ], [ %4, %6 ]
%17 = getelementptr inbounds i8, i8* %15, i64 1
br label %2
18: ; preds = %2
ret i64 %4
}