#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*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main(void) {
  char c[1000], ch;
  int i, count = 0;
  printf("Enter the string: ");
  gets(c);
  printf("Enter the character to find frequency: ");
  scanf("%c", &ch);
  for (i = 0; c[i] != '\0'; ++i) {
    if (ch == c[i]) {
      ++count;
    }
  }
  printf("The frequency of \033[1;34m%c: %d\033[0m", ch, count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x3fc(%rbp)
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x3f0(%rbp),%rdi
call   1040 <gets@plt>
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec0(%rip),%rdi
lea    -0x3f1(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x0,-0x3f8(%rbp)
movslq -0x3f8(%rbp),%rax
movsbl -0x3f0(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     11ef <main+0xbf>
movsbl -0x3f1(%rbp),%eax
movslq -0x3f8(%rbp),%rcx
movsbl -0x3f0(%rbp,%rcx,1),%ecx
ff
cmp    %ecx,%eax
jne    11d6 <main+0xa6>
mov    -0x3fc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3fc(%rbp)
jmp    11db <main+0xab>
mov    -0x3f8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3f8(%rbp)
jmp    1191 <main+0x61>
movsbl -0x3f1(%rbp),%esi
mov    -0x3fc(%rbp),%edx
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x400,%rsp
lea    0xec1(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x10(%rsp),%rdi
call   1040 <gets@plt>
lea    0xeba(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed4(%rip),%rdi
lea    0xf(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x10(%rsp),%al
movsbl 0xf(%rsp),%esi
test   %al,%al
je     11a5 <main+0x75>
lea    0x11(%rsp),%rcx
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %edx,%edx
cmp    %al,%sil
sete   %dl
add    %edx,%ebx
movzbl (%rcx),%eax
add    $0x1,%rcx
test   %al,%al
jne    1190 <main+0x60>
lea    0xe92(%rip),%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Enter the string: \00"
@.str.1 = [40 x i8] c"Enter the character to find frequency: \00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [35 x i8] c"The frequency of \1B[1;34m%c: %d\1B[0m\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x i8]
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%8 = call i32 @gets(i8* %7)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3)
store i32 0, i32* %4
br label %11
11: ; preds = %31, %0
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %34
18: ; preds = %11
%19 = load i8, i8* %3
%20 = sext i8 %19 to i32
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %20, %25
br i1 %26, label %27, label %30
27: ; preds = %18
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %30
30: ; preds = %27, %18
br label %31
31: ; preds = %30
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %11
34: ; preds = %11
%35 = load i8, i8* %3
%36 = sext i8 %35 to i32
%37 = load i32, i32* %5
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %36, i32 %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"Enter the string: \00"
@.str.1 = [40 x i8] c"Enter the character to find frequency: \00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [35 x i8] c"The frequency of \1B[1;34m%c: %d\1B[0m\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = alloca i8
%3 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @gets(i8* %3)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%8 = load i8, i8* %3
%9 = icmp eq i8 %8, 0
%10 = load i8, i8* %2
br i1 %9, label %22, label %11
11: ; preds = %0, %11
%12 = phi i64 [ %18, %11 ], [ 0, %0 ]
%13 = phi i8 [ %20, %11 ], [ %8, %0 ]
%14 = phi i32 [ %17, %11 ], [ 0, %0 ]
%15 = icmp eq i8 %10, %13
%16 = zext i1 %15 to i32
%17 = add nuw nsw i32 %14, %16
%18 = add nuw nsw i64 %12, 1
%19 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %11
22: ; preds = %11, %0
%23 = phi i32 [ 0, %0 ], [ %17, %11 ]
%24 = sext i8 %10 to i32
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %24, i32 %23)
ret i32 0
}