#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*/ fgets(char *, int, int /*<<< orphan*/);
int number_of_times_char_in_str(char *, char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ stdin;
int main() {
  char text_string[99];
  printf("Enter a text string: ");
  fgets(text_string, 99, stdin);
  char letter;
  printf("Enter a letter: ");
  scanf("%c", &letter);
  printf("%d\n", number_of_times_char_in_str(text_string, letter));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2e7d(%rip),%rax
mov    (%rax),%edx
mov    $0x63,%esi
call   1040 <fgets@plt>
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe9b(%rip),%rdi
lea    -0x71(%rbp),%rsi
call   1060 <scanf@plt>
lea    -0x70(%rbp),%rdi
movsbl -0x71(%rbp),%esi
call   1050 <number_of_times_char_in_str@plt>
mov    %eax,%esi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
lea    0xeb1(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e8b(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x63,%esi
call   1040 <fgets@plt>
lea    0xe9e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xea1(%rip),%rdi
lea    0xf(%rsp),%rsi
call   1060 <scanf@plt>
movsbl 0xf(%rsp),%esi
mov    %rbx,%rdi
call   1050 <number_of_times_char_in_str@plt>
lea    0xe86(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Enter a text string: \00"
@stdin = global i32 0
@.str.1 = [17 x i8] c"Enter a letter: \00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [99 x i8]
%3 = alloca i8
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [99 x i8], [99 x i8]* %2, i64 0, i64 0
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %5, i32 99, i32 %6)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%10 = getelementptr inbounds [99 x i8], [99 x i8]* %2, i64 0, i64 0
%11 = load i8, i8* %3
%12 = call i32 @number_of_times_char_in_str(i8* %10, i8 signext %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %12)
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"Enter a text string: \00"
@stdin = global i32 0
@.str.1 = [17 x i8] c"Enter a letter: \00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [99 x i8]
%2 = alloca i8
%3 = getelementptr inbounds [99 x i8], [99 x i8]* %1, i64 0, i64 0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %3, i32 99, i32 %5)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%9 = load i8, i8* %2
%10 = call i32 @number_of_times_char_in_str(i8* %3, i8 signext %9)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %10)
ret i32 0
}