#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 */
char getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putcharExplicit(char);
void testGetchar() {
  char input;
  printf("Testing getchar()...\n");
  printf("Enter Q to quit\n\n");
  while (1) {
    input = getchar();
    if (input == 'Q') {
      printf("\nEnding getchar() test\n");
      break;
    }
    putcharExplicit(input);
  }
}


x86 assembly (clang, -O0):
<testGetchar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
call   1030 <printf@plt>
lea    0xecb(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0x51,%eax
jne    1178 <testGetchar+0x48>
lea    0xeba(%rip),%rdi
call   1030 <printf@plt>
jmp    1186 <testGetchar+0x56>
movsbl -0x1(%rbp),%edi
call   1050 <putcharExplicit@plt>
jmp    1150 <testGetchar+0x20>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testGetchar>:
push   %rax
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0x51,%al
je     1165 <testGetchar+0x35>
movsbl %al,%edi
call   1050 <putcharExplicit@plt>
jmp    1150 <testGetchar+0x20>
lea    0xeba(%rip),%rdi
pop    %rax
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Testing getchar()...\0A\00"
@.str.1 = [18 x i8] c"Enter Q to quit\0A\0A\00"
@.str.2 = [24 x i8] c"\0AEnding getchar() test\0A\00"
define void @testGetchar() {
%1 = alloca i8
%2 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%3 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %4
4: ; preds = %0, %11
%5 = call signext i8 (...) @getchar()
store i8 %5, i8* %1
%6 = load i8, i8* %1
%7 = sext i8 %6 to i32
%8 = icmp eq i32 %7, 81
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %14
11: ; preds = %4
%12 = load i8, i8* %1
%13 = call i32 @putcharExplicit(i8 signext %12)
br label %4
14: ; preds = %9
ret void
}

LLVM IR (-O2):
@str = [21 x i8] c"Testing getchar()...\00"
@str.3 = [17 x i8] c"Enter Q to quit\0A\00"
@str.4 = [23 x i8] c"\0AEnding getchar() test\00"
define void @testGetchar() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.3, i64 0, i64 0))
%3 = tail call signext i8 (...) @getchar()
%4 = icmp eq i8 %3, 81
br i1 %4, label %5, label %7
5: ; preds = %7, %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.4, i64 0, i64 0))
ret void
7: ; preds = %0, %7
%8 = phi i8 [ %10, %7 ], [ %3, %0 ]
%9 = tail call i32 @putcharExplicit(i8 signext %8)
%10 = tail call signext i8 (...) @getchar()
%11 = icmp eq i8 %10, 81
br i1 %11, label %5, label %7
}