#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 EOF;
char getchar();
int /*<<< orphan*/ reg_set(int, int, int);
int /*<<< orphan*/ scanf(char *, char *);
void sys_get_char(int reg) {
  char in;
  scanf("%c", &in);
  reg_set(0x1, reg, in);
  char ch;
  while ((ch = getchar()) != '\n' && ch != EOF)
    ;
  reg_set(0x0, 0x1, 0x0);
}


x86 assembly (clang, -O0):
<sys_get_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0xebe(%rip),%rdi
lea    -0x5(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x4(%rbp),%esi
movsbl -0x5(%rbp),%edx
mov    $0x1,%edi
call   1040 <reg_set@plt>
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0x6(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x7(%rbp)
je     118d <sys_get_char+0x5d>
movsbl -0x6(%rbp),%eax
mov    0x2e66(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x7(%rbp)
mov    -0x7(%rbp),%al
test   $0x1,%al
jne    119d <sys_get_char+0x6d>
jmp    11a2 <sys_get_char+0x72>
jmp    115c <sys_get_char+0x2c>
xor    %edx,%edx
mov    $0x1,%esi
mov    %edx,%edi
call   1040 <reg_set@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_get_char>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xec2(%rip),%rdi
lea    0xf(%rsp),%rsi
call   1050 <scanf@plt>
movsbl 0xf(%rsp),%edx
mov    $0x1,%edi
mov    %ebx,%esi
call   1040 <reg_set@plt>
mov    0x2e88(%rip),%rbx
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%al
je     116f <sys_get_char+0x3f>
cmp    (%rbx),%al
jne    1160 <sys_get_char+0x30>
xor    %edi,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1040 <reg_set@plt>
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@EOF = global i8 0
define void @sys_get_char(i32 %0) {
%2 = alloca i8
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = load i8, i8* %2
%5 = sext i8 %4 to i32
%6 = call i32 @reg_set(i32 1, i32 %0, i32 %5)
br label %7
7: ; preds = %7, %1
%8 = call signext i8 (...) @getchar()
%9 = icmp ne i8 %8, 10
%10 = load i8, i8* @EOF
%11 = icmp ne i8 %8, %10
%12 = select i1 %9, i1 %11, i1 false
br i1 %12, label %7, label %13
13: ; preds = %7
%14 = call i32 @reg_set(i32 0, i32 1, i32 0)
ret void
}