#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*/ TRUE;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ endwin();
int /*<<< orphan*/ initscr();
int /*<<< orphan*/ keypad(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ mvinch(int /*<<< orphan*/, int);
int /*<<< orphan*/ noecho();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ printw(char *);
int /*<<< orphan*/ raw();
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ stdscr;
int main() {
  initscr();
  raw();
  noecho();
  keypad(stdscr, TRUE);
  printw("test\n");
  refresh();
  char text[] = "test";
  for (int i = 0; i < 4; ++i)
    assert((int)mvinch(0, i) == text[i]);
  printf("it worked!\n");
  endwin();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <initscr@plt>
mov    $0x0,%al
call   1060 <raw@plt>
mov    $0x0,%al
call   10b0 <noecho@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
call   1040 <keypad@plt>
lea    0xe1e(%rip),%rdi
call   1080 <printw@plt>
mov    $0x0,%al
call   1090 <refresh@plt>
mov    0xe12(%rip),%eax
mov    %eax,-0x9(%rbp)
mov    0xe0d(%rip),%al
mov    %al,-0x5(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jge    1241 <main+0xa1>
mov    -0x10(%rbp),%esi
xor    %edi,%edi
call   10c0 <mvinch@plt>
movslq -0x10(%rbp),%rcx
movsbl -0x9(%rbp,%rcx,1),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1207 <main+0x67>
lea    0xdc3(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   10a0 <endwin@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1050 <initscr@plt>
xor    %eax,%eax
call   1060 <raw@plt>
xor    %eax,%eax
call   10b0 <noecho@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
call   1040 <keypad@plt>
lea    0xe2c(%rip),%rdi
call   1080 <printw@plt>
xor    %eax,%eax
call   1090 <refresh@plt>
xor    %edi,%edi
xor    %esi,%esi
call   10c0 <mvinch@plt>
xor    %edi,%edi
cmp    $0x74,%eax
sete   %dil
call   1070 <assert@plt>
xor    %edi,%edi
mov    $0x1,%esi
call   10c0 <mvinch@plt>
xor    %edi,%edi
cmp    $0x65,%eax
sete   %dil
call   1070 <assert@plt>
xor    %edi,%edi
mov    $0x2,%esi
call   10c0 <mvinch@plt>
xor    %edi,%edi
cmp    $0x73,%eax
sete   %dil
call   1070 <assert@plt>
xor    %edi,%edi
mov    $0x3,%esi
call   10c0 <mvinch@plt>
xor    %edi,%edi
cmp    $0x74,%eax
sete   %dil
call   1070 <assert@plt>
lea    0xdba(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   10a0 <endwin@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stdscr = global i32 0
@TRUE = global i32 0
@.str = [6 x i8] c"test\0A\00"
@__const.main.text = [5 x i8] c"test\00"
@.str.1 = [12 x i8] c"it worked!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @initscr()
%5 = call i32 (...) @raw()
%6 = call i32 (...) @noecho()
%7 = load i32, i32* @stdscr
%8 = load i32, i32* @TRUE
%9 = call i32 @keypad(i32 %7, i32 %8)
%10 = call i32 @printw(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (...) @refresh()
%12 = bitcast [5 x i8]* %2 to i8*
store i32 0, i32* %3
br label %13
13: ; preds = %28, %0
%14 = load i32, i32* %3
%15 = icmp slt i32 %14, 4
br i1 %15, label %16, label %31
16: ; preds = %13
%17 = load i32, i32* %3
%18 = call i64 @mvinch(i32 0, i32 %17)
%19 = trunc i64 %18 to i32
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %19, %24
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
br label %28
28: ; preds = %16
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
br label %13
31: ; preds = %13
%32 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 (...) @endwin()
ret i32 0
}

LLVM IR (-O2):
@stdscr = global i32 0
@TRUE = global i32 0
@.str = [6 x i8] c"test\0A\00"
@str = [11 x i8] c"it worked!\00"
define i32 @main() {
%1 = tail call i32 (...) @initscr()
%2 = tail call i32 (...) @raw()
%3 = tail call i32 (...) @noecho()
%4 = load i32, i32* @stdscr
%5 = load i32, i32* @TRUE
%6 = tail call i32 @keypad(i32 %4, i32 %5)
%7 = tail call i32 @printw(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 (...) @refresh()
%9 = tail call i64 @mvinch(i32 0, i32 0)
%10 = trunc i64 %9 to i32
%11 = icmp eq i32 %10, 116
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = tail call i64 @mvinch(i32 0, i32 1)
%15 = trunc i64 %14 to i32
%16 = icmp eq i32 %15, 101
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
%19 = tail call i64 @mvinch(i32 0, i32 2)
%20 = trunc i64 %19 to i32
%21 = icmp eq i32 %20, 115
%22 = zext i1 %21 to i32
%23 = tail call i32 @assert(i32 %22)
%24 = tail call i64 @mvinch(i32 0, i32 3)
%25 = trunc i64 %24 to i32
%26 = icmp eq i32 %25, 116
%27 = zext i1 %26 to i32
%28 = tail call i32 @assert(i32 %27)
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%30 = tail call i32 (...) @endwin()
ret i32 0
}