#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);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, char *);
char *strchr(char *, char);
main() {
  char str[20];
  char *ptr;
  char ch;
  int cnt = 0;
  puts("enter a string: ");
  gets(str);
  ptr = str;
  puts("enter a character to remove all of its occurence: ");
  scanf("%c", &ch);
  while (ptr = strchr(ptr, ch)) {
    cnt++;
    ptr++;
  }
  printf("%d\n", cnt);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x30(%rbp)
lea    0xe93(%rip),%rdi
call   1030 <puts@plt>
lea    -0x20(%rbp),%rdi
call   1060 <gets@plt>
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xe87(%rip),%rdi
call   1030 <puts@plt>
lea    0xeae(%rip),%rdi
lea    -0x29(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x28(%rbp),%rdi
movsbl -0x29(%rbp),%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11d4 <main+0x84>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    119f <main+0x4f>
mov    -0x30(%rbp),%esi
lea    0xe69(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
lea    0xea3(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1060 <gets@plt>
lea    0xe9b(%rip),%rdi
call   1030 <puts@plt>
lea    0xec2(%rip),%rdi
lea    0xf(%rsp),%rsi
call   1070 <scanf@plt>
movsbl 0xf(%rsp),%ebx
mov    %rbp,%rdi
mov    %ebx,%esi
call   1040 <strchr@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11c6 <main+0x76>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%ebp
add    $0x1,%rax
mov    %rax,%rdi
mov    %ebx,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    11b0 <main+0x60>
lea    0xe7a(%rip),%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"enter a string: \00"
@.str.1 = [51 x i8] c"enter a character to remove all of its occurence: \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 [20 x i8]
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
%6 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%8 = call i32 @gets(i8* %7)
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
store i8* %9, i8** %3
%10 = call i32 @puts(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %12
12: ; preds = %17, %0
%13 = load i8*, i8** %3
%14 = load i8, i8* %4
%15 = call i8* @strchr(i8* %13, i8 signext %14)
store i8* %15, i8** %3
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %3
br label %12
22: ; preds = %12
%23 = load i32, i32* %5
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [17 x i8] c"enter a string: \00"
@.str.1 = [51 x i8] c"enter a character to remove all of its occurence: \00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [4 x i8] c"%d\0A\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 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @gets(i8* %3)
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 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* %2
%9 = call i8* @strchr(i8* dereferenceable(1) %3, i8 signext %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %18, label %11
11: ; preds = %0, %11
%12 = phi i8* [ %16, %11 ], [ %9, %0 ]
%13 = phi i32 [ %14, %11 ], [ 0, %0 ]
%14 = add nuw nsw i32 %13, 1
%15 = getelementptr inbounds i8, i8* %12, i64 1
%16 = call i8* @strchr(i8* dereferenceable(1) %15, i8 signext %8)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %11
18: ; preds = %11, %0
%19 = phi i32 [ 0, %0 ], [ %14, %11 ]
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %19)
ret i32 0
}