#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  char str[20], ch;
  int count = 0, i;
  printf("\nEnter a string : ");
  scanf("%s", &str);
  printf("\nEnter the character to be searched : ");
  scanf("%c", &ch);
  for (i = 0; str[i] != '\0'; i++) {
    if (str[i] == ch)
      count++;
  }
  if (count == 0)
    printf("\nCharacter '%c'is not present", ch);
  else
    printf("\nOccurence of character '%c' : %d", ch, count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x28(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec8(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed2(%rip),%rdi
lea    -0x21(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     11c0 <main+0xa0>
movslq -0x2c(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%eax
movsbl -0x21(%rbp),%ecx
cmp    %ecx,%eax
jne    11ad <main+0x8d>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11b2 <main+0x92>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    117d <main+0x5d>
cmpl   $0x0,-0x28(%rbp)
jne    11e1 <main+0xc1>
movsbl -0x21(%rbp),%esi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f6 <main+0xd6>
movsbl -0x21(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
lea    0xed4(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed7(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
lea    0xec7(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee0(%rip),%rdi
lea    0xf(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x10(%rsp),%dl
test   %dl,%dl
je     11b0 <main+0x90>
mov    0xf(%rsp),%al
lea    0x11(%rsp),%rcx
nopw   0x0(%rax,%rax,1)
xor    %esi,%esi
cmp    %al,%dl
sete   %sil
add    %esi,%ebx
movzbl (%rcx),%edx
add    $0x1,%rcx
test   %dl,%dl
jne    1180 <main+0x60>
test   %ebx,%ebx
je     11b0 <main+0x90>
movsbl 0xf(%rsp),%esi
lea    0xeb9(%rip),%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11c3 <main+0xa3>
movsbl 0xf(%rsp),%esi
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"\0AEnter a string : \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [39 x i8] c"\0AEnter the character to be searched : \00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [30 x i8] c"\0ACharacter '%c'is not present\00"
@.str.5 = [34 x i8] c"\0AOccurence of character '%c' : %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), [20 x i8]* %2)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %3)
store i32 0, i32* %5
br label %10
10: ; preds = %30, %0
%11 = load i32, i32* %5
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %33
17: ; preds = %10
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = load i8, i8* %3
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %22, %24
br i1 %25, label %26, label %29
26: ; preds = %17
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %29
29: ; preds = %26, %17
br label %30
30: ; preds = %29
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %10
33: ; preds = %10
%34 = load i32, i32* %4
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = load i8, i8* %3
%38 = sext i8 %37 to i32
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %38)
br label %45
40: ; preds = %33
%41 = load i8, i8* %3
%42 = sext i8 %41 to i32
%43 = load i32, i32* %4
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %42, i32 %43)
br label %45
45: ; preds = %40, %36
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"\0AEnter a string : \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [39 x i8] c"\0AEnter the character to be searched : \00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [30 x i8] c"\0ACharacter '%c'is not present\00"
@.str.5 = [34 x i8] c"\0AOccurence of character '%c' : %d\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = alloca i8
%3 = getelementptr inbounds [20 x i8], [20 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 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), [20 x i8]* %1)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%8 = load i8, i8* %3
%9 = icmp eq i8 %8, 0
br i1 %9, label %25, label %10
10: ; preds = %0
%11 = load i8, i8* %2
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %19, %12 ]
%14 = phi i8 [ %8, %10 ], [ %21, %12 ]
%15 = phi i32 [ 0, %10 ], [ %18, %12 ]
%16 = icmp eq i8 %14, %11
%17 = zext i1 %16 to i32
%18 = add nuw nsw i32 %15, %17
%19 = add nuw nsw i64 %13, 1
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %12
23: ; preds = %12
%24 = icmp eq i32 %18, 0
br i1 %24, label %25, label %29
25: ; preds = %0, %23
%26 = load i8, i8* %2
%27 = sext i8 %26 to i32
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %27)
br label %33
29: ; preds = %23
%30 = load i8, i8* %2
%31 = sext i8 %30 to i32
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %31, i32 %18)
br label %33
33: ; preds = %29, %25
ret i32 0
}