#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*/ EXIT_SUCCESS;
int /*<<< orphan*/ addstr(char *);
int /*<<< orphan*/ endwin();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char getch();
int /*<<< orphan*/ initscr();
int /*<<< orphan*/ printw(char *, char);
int /*<<< orphan*/ refresh();
int main(void) {
  char ch;
  initscr();
  addstr("Please type x to quit");
  refresh();
  while ((ch = getch()) != 'x') {
    printw("\ntyped: %c\n", ch);
  }
  endwin();
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <initscr@plt>
lea    0xe73(%rip),%rdi
call   1090 <addstr@plt>
mov    $0x0,%al
call   1050 <refresh@plt>
mov    $0x0,%al
call   1060 <getch@plt>
mov    %al,-0x5(%rbp)
movsbl %al,%eax
cmp    $0x78,%eax
je     11c4 <main+0x54>
lea    0xe60(%rip),%rdi
movsbl -0x5(%rbp),%esi
call   1040 <printw@plt>
jmp    1199 <main+0x29>
mov    $0x0,%al
call   1070 <endwin@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1030 <initscr@plt>
lea    0xe81(%rip),%rdi
call   1090 <addstr@plt>
xor    %eax,%eax
call   1050 <refresh@plt>
xor    %eax,%eax
call   1060 <getch@plt>
cmp    $0x78,%al
je     11b6 <main+0x46>
lea    0xe79(%rip),%rbx
nopl   (%rax)
movsbl %al,%esi
mov    %rbx,%rdi
call   1040 <printw@plt>
xor    %eax,%eax
call   1060 <getch@plt>
cmp    $0x78,%al
jne    11a0 <main+0x30>
xor    %eax,%eax
call   1070 <endwin@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Please type x to quit\00"
@.str.1 = [12 x i8] c"\0Atyped: %c\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
store i32 0, i32* %1
%3 = call i32 (...) @initscr()
%4 = call i32 @addstr(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (...) @refresh()
br label %6
6: ; preds = %10, %0
%7 = call signext i8 (...) @getch()
store i8 %7, i8* %2
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 120
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = load i8, i8* %2
%12 = call i32 @printw(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8 signext %11)
br label %6
13: ; preds = %6
%14 = call i32 (...) @endwin()
%15 = load i32, i32* @EXIT_SUCCESS
%16 = call i32 @exit(i32 %15)
unreachable
}

LLVM IR (-O2):
@.str = [22 x i8] c"Please type x to quit\00"
@.str.1 = [12 x i8] c"\0Atyped: %c\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i32 (...) @initscr()
%2 = tail call i32 @addstr(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 (...) @refresh()
%4 = tail call signext i8 (...) @getch()
%5 = icmp eq i8 %4, 120
br i1 %5, label %11, label %6
6: ; preds = %0, %6
%7 = phi i8 [ %9, %6 ], [ %4, %0 ]
%8 = tail call i32 @printw(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8 signext %7)
%9 = tail call signext i8 (...) @getch()
%10 = icmp eq i8 %9, 120
br i1 %10, label %11, label %6
11: ; preds = %6, %0
%12 = tail call i32 (...) @endwin()
%13 = load i32, i32* @EXIT_SUCCESS
%14 = tail call i32 @exit(i32 %13)
unreachable
}