#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*/ echo(unsigned char);
unsigned char kb_getc();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ set_tty_cooked();
int /*<<< orphan*/ set_tty_raw();
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  unsigned char ch;
  printf("Test Unix single-character input.\n");
  set_tty_raw();
  while (1) {
    usleep(20000);
    ch = kb_getc();
    if (0x03 == ch) {
      set_tty_cooked();
      return 1;
    }
    echo(ch);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <set_tty_raw@plt>
mov    $0x4e20,%edi
call   1080 <usleep@plt>
mov    $0x0,%al
call   1070 <kb_getc@plt>
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%ecx
mov    $0x3,%eax
cmp    %ecx,%eax
jne    11c0 <main+0x60>
mov    $0x0,%al
call   1050 <set_tty_cooked@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret
movzbl -0x11(%rbp),%edi
call   1030 <echo@plt>
jmp    1189 <main+0x29>

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xe98(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1060 <set_tty_raw@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x4e20,%edi
call   1080 <usleep@plt>
xor    %eax,%eax
call   1070 <kb_getc@plt>
cmp    $0x3,%al
je     119f <main+0x3f>
movzbl %al,%edi
call   1030 <echo@plt>
jmp    1180 <main+0x20>
xor    %eax,%eax
call   1050 <set_tty_cooked@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [35 x i8] c"Test Unix single-character input.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (...) @set_tty_raw()
br label %9
9: ; preds = %2, %17
%10 = call i32 @usleep(i32 20000)
%11 = call zeroext i8 (...) @kb_getc()
store i8 %11, i8* %6
%12 = load i8, i8* %6
%13 = zext i8 %12 to i32
%14 = icmp eq i32 3, %13
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 (...) @set_tty_cooked()
ret i32 1
17: ; preds = %9
%18 = load i8, i8* %6
%19 = call i32 @echo(i8 zeroext %18)
br label %9
}

LLVM IR (-O2):
@str = [34 x i8] c"Test Unix single-character input.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (...) @set_tty_raw()
%5 = tail call i32 @usleep(i32 20000)
%6 = tail call zeroext i8 (...) @kb_getc()
%7 = icmp eq i8 %6, 3
br i1 %7, label %8, label %10
8: ; preds = %10, %2
%9 = tail call i32 (...) @set_tty_cooked()
ret i32 1
10: ; preds = %2, %10
%11 = phi i8 [ %14, %10 ], [ %6, %2 ]
%12 = tail call i32 @echo(i8 zeroext %11)
%13 = tail call i32 @usleep(i32 20000)
%14 = tail call zeroext i8 (...) @kb_getc()
%15 = icmp eq i8 %14, 3
br i1 %15, label %8, label %10
}