#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 fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char, char);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
void do_something(void) {
  char ch = 0;
  while (ch != 'q') {
    ch = fgetc(stdin);
    if (ch != '\r' && ch != '\n') {
      fprintf(stdout, "input = 0x%x(%c)\n", ch, ch);
    }
  }
}


x86 assembly (clang, -O0):
<do_something>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0x71,%eax
je     1188 <do_something+0x68>
mov    0x2ea8(%rip),%rax
mov    (%rax),%edi
call   1030 <fgetc@plt>
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0xd,%eax
je     1183 <do_something+0x63>
movsbl -0x1(%rbp),%eax
cmp    $0xa,%eax
je     1183 <do_something+0x63>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    -0x1(%rbp),%al
lea    0xe89(%rip),%rsi
movsbl %al,%edx
movsbl -0x1(%rbp),%ecx
call   1040 <fprintf@plt>
jmp    112c <do_something+0xc>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_something>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2eb9(%rip),%r15
mov    0x2ea2(%rip),%r12
lea    0xec3(%rip),%r14
nopl   (%rax)
mov    (%r15),%edi
call   1030 <fgetc@plt>
cmp    $0xa,%al
je     1140 <do_something+0x20>
mov    %eax,%ebx
cmp    $0xd,%al
je     1140 <do_something+0x20>
mov    (%r12),%edi
movsbl %bl,%ecx
mov    %r14,%rsi
mov    %ecx,%edx
call   1040 <fprintf@plt>
cmp    $0x71,%bl
jne    1140 <do_something+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@stdout = global i32 0
@.str = [18 x i8] c"input = 0x%x(%c)\0A\00"
define void @do_something() {
%1 = alloca i8
store i8 0, i8* %1
br label %2
2: ; preds = %21, %0
%3 = load i8, i8* %1
%4 = sext i8 %3 to i32
%5 = icmp ne i32 %4, 113
br i1 %5, label %6, label %22
6: ; preds = %2
%7 = load i32, i32* @stdin
%8 = call signext i8 @fgetc(i32 %7)
store i8 %8, i8* %1
%9 = load i8, i8* %1
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 13
br i1 %11, label %12, label %21
12: ; preds = %6
%13 = load i8, i8* %1
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 10
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i32, i32* @stdout
%18 = load i8, i8* %1
%19 = load i8, i8* %1
%20 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8 signext %18, i8 signext %19)
br label %21
21: ; preds = %16, %12, %6
br label %2
22: ; preds = %2
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@stdout = global i32 0
@.str = [18 x i8] c"input = 0x%x(%c)\0A\00"
define void @do_something() {
br label %1
1: ; preds = %8, %0
%2 = load i32, i32* @stdin
%3 = tail call signext i8 @fgetc(i32 %2)
switch i8 %3, label %4 [
i8 10, label %8
i8 13, label %8
]
4: ; preds = %1
%5 = load i32, i32* @stdout
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8 signext %3, i8 signext %3)
%7 = icmp eq i8 %3, 113
br i1 %7, label %9, label %8
8: ; preds = %4, %1, %1
br label %1
9: ; preds = %4
ret void
}