#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 *, char *);
char *strchr(char *, char);
int main(void) {
  char str[80];
  char occurrence;
  int counter;
  int occurrenceNumber = 0;
  char *s;
  char c;
  printf("This program calculates the total occurrences of the character "
         "specified a string.(the string must not past 79 characters.)\n");
  printf("Please write the string.\n");
  scanf("%79s", str);
  printf("Specify the character.\n");
  scanf(" %c", &occurrence);
  s = strchr(str, occurrence);
  while (s != NULL) {
    occurrenceNumber++;
    s = strchr(s + 1, occurrence);
  }
  printf("%d\n", occurrenceNumber);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x6c(%rbp)
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rsi
lea    0xf27(%rip),%rdi
call   1050 <scanf@plt>
lea    0xf20(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf2a(%rip),%rdi
lea    -0x61(%rbp),%rsi
call   1050 <scanf@plt>
lea    -0x60(%rbp),%rdi
movsbl -0x61(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
je     11d2 <main+0xa2>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
mov    -0x78(%rbp),%rdi
add    $0x1,%rdi
movsbl -0x61(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x78(%rbp)
jmp    11a4 <main+0x74>
mov    -0x6c(%rbp),%esi
lea    0xedc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x68,%rsp
lea    0xec0(%rip),%rdi
call   1030 <puts@plt>
lea    0xf30(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9b(%rip),%rdi
lea    0x10(%rsp),%rbp
mov    %rbp,%rsi
call   1060 <scanf@plt>
lea    0xf29(%rip),%rdi
call   1030 <puts@plt>
lea    0xe80(%rip),%rdi
lea    0xf(%rsp),%rsi
call   1060 <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+0x86>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebp
add    $0x1,%rax
mov    %rax,%rdi
mov    %ebx,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    11b0 <main+0x70>
lea    0xe3c(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [125 x i8] c"This program calculates the total occurrences of the character specified a string.(the string must not past 79 characters.)\0A\00"
@.str.1 = [26 x i8] c"Please write the string.\0A\00"
@.str.2 = [5 x i8] c"%79s\00"
@.str.3 = [24 x i8] c"Specify the character.\0A\00"
@.str.4 = [4 x i8] c" %c\00"
@.str.5 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [80 x i8]
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %5
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([125 x i8], [125 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%11 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %3)
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%15 = load i8, i8* %3
%16 = call i8* @strchr(i8* %14, i8 signext %15)
store i8* %16, i8** %6
br label %17
17: ; preds = %20, %0
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i8, i8* %3
%26 = call i8* @strchr(i8* %24, i8 signext %25)
store i8* %26, i8** %6
br label %17
27: ; preds = %17
%28 = load i32, i32* %5
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str.2 = [5 x i8] c"%79s\00"
@.str.4 = [4 x i8] c" %c\00"
@.str.5 = [4 x i8] c"%d\0A\00"
@str = [124 x i8] c"This program calculates the total occurrences of the character specified a string.(the string must not past 79 characters.)\00"
@str.6 = [25 x i8] c"Please write the string.\00"
@str.7 = [23 x i8] c"Specify the character.\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = alloca i8
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([124 x i8], [124 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.6, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.7, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %2)
%9 = load i8, i8* %2
%10 = call i8* @strchr(i8* %3, i8 signext %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %19, label %12
12: ; preds = %0, %12
%13 = phi i32 [ %15, %12 ], [ 0, %0 ]
%14 = phi i8* [ %17, %12 ], [ %10, %0 ]
%15 = add nuw nsw i32 %13, 1
%16 = getelementptr inbounds i8, i8* %14, i64 1
%17 = call i8* @strchr(i8* %16, i8 signext %9)
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %12
19: ; preds = %12, %0
%20 = phi i32 [ 0, %0 ], [ %15, %12 ]
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %20)
ret i32 0
}