#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*/ getLine(char *, int);
int /*<<< orphan*/ printf(char *, ...);
char *strchr(char *, char);
int main() {
  char line1[80], line2[80];
  char searchStr[80];
  char *searchPtr;
  char searchChr;
  int count = 0;
  printf("Enter line 1: ");
  getLine(line1, 80);
  printf("Enter line 2: ");
  getLine(line2, 80);
  printf("Enter search character: ");
  getLine(searchStr, 2);
  searchChr = searchStr[0];
  searchPtr = strchr(line1, searchChr);
  while (searchPtr != NULL) {
    count++;
    searchPtr = strchr(searchPtr + 1, searchChr);
  }
  searchPtr = strchr(line2, searchChr);
  while (searchPtr != NULL) {
    count++;
    searchPtr = strchr(searchPtr + 1, searchChr);
  }
  printf("%d occurrences of '%c' found in the text\n", count, searchChr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x110(%rbp)
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    $0x50,%esi
call   1050 <getLine@plt>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xb0(%rbp),%rdi
mov    $0x50,%esi
call   1050 <getLine@plt>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x100(%rbp),%rdi
mov    $0x2,%esi
call   1050 <getLine@plt>
mov    -0x100(%rbp),%al
mov    %al,-0x109(%rbp)
lea    -0x60(%rbp),%rdi
movsbl -0x109(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x108(%rbp)
cmpq   $0x0,-0x108(%rbp)
je     1209 <main+0xd9>
mov    -0x110(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x110(%rbp)
mov    -0x108(%rbp),%rdi
add    $0x1,%rdi
movsbl -0x109(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x108(%rbp)
jmp    11c9 <main+0x99>
lea    -0xb0(%rbp),%rdi
movsbl -0x109(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x108(%rbp)
cmpq   $0x0,-0x108(%rbp)
je     1263 <main+0x133>
mov    -0x110(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x110(%rbp)
mov    -0x108(%rbp),%rdi
add    $0x1,%rdi
movsbl -0x109(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x108(%rbp)
jmp    1223 <main+0xf3>
mov    -0x110(%rbp),%esi
movsbl -0x109(%rbp),%edx
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0xf0,%rsp
lea    0xebe(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xa0(%rsp),%r14
mov    %r14,%rdi
mov    $0x50,%esi
call   1050 <getLine@plt>
lea    0xea8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x50(%rsp),%rdi
mov    $0x50,%esi
call   1050 <getLine@plt>
lea    0xe9a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rdi
mov    $0x2,%esi
call   1050 <getLine@plt>
movsbl (%rsp),%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11c6 <main+0x96>
xor    %ebx,%ebx
nopl   (%rax)
add    $0x1,%ebx
add    $0x1,%rax
mov    %rax,%rdi
mov    %ebp,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    11b0 <main+0x80>
lea    0x50(%rsp),%rdi
nopl   0x0(%rax,%rax,1)
mov    %ebp,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11e8 <main+0xb8>
add    $0x1,%ebx
add    $0x1,%rax
mov    %rax,%rdi
jmp    11d0 <main+0xa0>
lea    0xe48(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Enter line 1: \00"
@.str.1 = [15 x i8] c"Enter line 2: \00"
@.str.2 = [25 x i8] c"Enter search character: \00"
@.str.3 = [42 x i8] c"%d occurrences of '%c' found in the text\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [80 x i8]
%3 = alloca [80 x i8]
%4 = alloca [80 x i8]
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %7
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%10 = call i32 @getLine(i8* %9, i32 80)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%13 = call i32 @getLine(i8* %12, i32 80)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%16 = call i32 @getLine(i8* %15, i32 2)
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%18 = load i8, i8* %17
store i8 %18, i8* %6
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%20 = load i8, i8* %6
%21 = call i8* @strchr(i8* %19, i8 signext %20)
store i8* %21, i8** %5
br label %22
22: ; preds = %25, %0
%23 = load i8*, i8** %5
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %32
25: ; preds = %22
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = load i8, i8* %6
%31 = call i8* @strchr(i8* %29, i8 signext %30)
store i8* %31, i8** %5
br label %22
32: ; preds = %22
%33 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%34 = load i8, i8* %6
%35 = call i8* @strchr(i8* %33, i8 signext %34)
store i8* %35, i8** %5
br label %36
36: ; preds = %39, %32
%37 = load i8*, i8** %5
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %46
39: ; preds = %36
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
%42 = load i8*, i8** %5
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i8, i8* %6
%45 = call i8* @strchr(i8* %43, i8 signext %44)
store i8* %45, i8** %5
br label %36
46: ; preds = %36
%47 = load i32, i32* %7
%48 = load i8, i8* %6
%49 = sext i8 %48 to i32
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %47, i32 %49)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"Enter line 1: \00"
@.str.1 = [15 x i8] c"Enter line 2: \00"
@.str.2 = [25 x i8] c"Enter search character: \00"
@.str.3 = [42 x i8] c"%d occurrences of '%c' found in the text\0A\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = alloca [80 x i8]
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @getLine(i8* %4, i32 80)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @getLine(i8* %5, i32 80)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @getLine(i8* %6, i32 2)
%13 = load i8, i8* %6
%14 = call i8* @strchr(i8* %4, i8 signext %13)
%15 = icmp eq i8* %14, null
br i1 %15, label %23, label %16
16: ; preds = %0, %16
%17 = phi i32 [ %19, %16 ], [ 0, %0 ]
%18 = phi i8* [ %21, %16 ], [ %14, %0 ]
%19 = add nuw nsw i32 %17, 1
%20 = getelementptr inbounds i8, i8* %18, i64 1
%21 = call i8* @strchr(i8* %20, i8 signext %13)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %16
23: ; preds = %16, %0
%24 = phi i32 [ 0, %0 ], [ %19, %16 ]
%25 = call i8* @strchr(i8* %5, i8 signext %13)
%26 = icmp eq i8* %25, null
br i1 %26, label %34, label %27
27: ; preds = %23, %27
%28 = phi i32 [ %30, %27 ], [ %24, %23 ]
%29 = phi i8* [ %32, %27 ], [ %25, %23 ]
%30 = add nuw nsw i32 %28, 1
%31 = getelementptr inbounds i8, i8* %29, i64 1
%32 = call i8* @strchr(i8* %31, i8 signext %13)
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %27
34: ; preds = %27, %23
%35 = phi i32 [ %24, %23 ], [ %30, %27 ]
%36 = sext i8 %13 to i32
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %35, i32 %36)
ret i32 0
}