#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 /*<<< orphan*/ assert(int /*<<< orphan*/);
char *strchr(char *, char);
int strCountChar(char *string, char search) {
  int c;
  char *pos;
  c = 0;
  assert(string != NULL);
  pos = strchr(string, search);
  while (pos) {
    c++;
    pos = strchr(pos + 1, search);
  }
  return c;
}


x86 assembly (clang, -O0):
<strCountChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movl   $0x0,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     118a <strCountChar+0x6a>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
movsbl -0x9(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
jmp    115c <strCountChar+0x3c>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strCountChar>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <strchr@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1166 <strCountChar+0x46>
movsbl %bpl,%ebp
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
add    $0x1,%rax
mov    %rax,%rdi
mov    %ebp,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1150 <strCountChar+0x30>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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