#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 strlen(char const *);
char numOfCharInString(const char *str, const char searchChar) {
  char num = 0;
  char i = 0;
  for (i = 0; i < strlen(str); i++) {
    if (*(str + i) == searchChar) {
      num++;
    }
  }
  return num;
}


x86 assembly (clang, -O0):
<numOfCharInString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movb   $0x0,-0xa(%rbp)
movb   $0x0,-0xb(%rbp)
movb   $0x0,-0xb(%rbp)
movsbl -0xb(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %al,%cl
mov    -0x10(%rbp),%eax
movsbl %cl,%ecx
cmp    %ecx,%eax
jge    1183 <numOfCharInString+0x73>
mov    -0x8(%rbp),%rax
movsbl -0xb(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    1171 <numOfCharInString+0x61>
mov    -0xa(%rbp),%al
add    $0x1,%al
mov    %al,-0xa(%rbp)
jmp    1176 <numOfCharInString+0x66>
mov    -0xb(%rbp),%al
add    $0x1,%al
mov    %al,-0xb(%rbp)
jmp    112e <numOfCharInString+0x1e>
movsbl -0xa(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<numOfCharInString>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
call   1030 <strlen@plt>
test   %al,%al
jle    1151 <numOfCharInString+0x41>
xor    %ebx,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
cmp    %r14b,(%r15,%rbx,1)
sete   %al
add    %al,%bpl
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
movsbq %al,%rax
cmp    %rax,%rbx
jl     1130 <numOfCharInString+0x20>
jmp    1153 <numOfCharInString+0x43>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define signext i8 @numOfCharInString(i8* %0, i8 signext %1) {
%3 = tail call signext i8 @strlen(i8* %0)
%4 = icmp sgt i8 %3, 0
br i1 %4, label %5, label %17
5: ; preds = %2, %5
%6 = phi i64 [ %13, %5 ], [ 0, %2 ]
%7 = phi i8 [ %12, %5 ], [ 0, %2 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %6
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, %1
%11 = zext i1 %10 to i8
%12 = add i8 %7, %11
%13 = add nuw nsw i64 %6, 1
%14 = tail call signext i8 @strlen(i8* %0)
%15 = sext i8 %14 to i64
%16 = icmp slt i64 %13, %15
br i1 %16, label %5, label %17
17: ; preds = %5, %2
%18 = phi i8 [ 0, %2 ], [ %12, %5 ]
ret i8 %18
}