#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*/ clear_screen();
int /*<<< orphan*/ cursor(int, int);
int /*<<< orphan*/ cursor_on();
int getch();
int /*<<< orphan*/ isprint(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ start_edit(char *);
int /*<<< orphan*/ start_game(char *);
void main_screen(void) {
  int c, quit = 0;
  char file[70];
  size_t filelen = 0;
  file[0] = 0;
  while (!quit) {
    clear_screen();
    cursor_on();
    cursor(30, 1);
    printf("TMAZE by DWK");
    cursor(5, 20);
    printf("%s", file);
    switch ((c = getch())) {
    case 0:
      switch ((c = getch())) {}
      break;
    case 27:
      quit = 1;
      break;
    case '\b':
      if (filelen > 0) {
        file[--filelen] = 0;
      }
      break;
    case '\r':
      start_game(file);
      break;
    case 10:
      start_edit(file);
      break;
    default:
      if (isprint(c) && filelen < 70) {
        file[filelen++] = c;
        file[filelen] = 0;
      }
    }
  }
}


x86 assembly (clang, -O0):
<main_screen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x8(%rbp)
movq   $0x0,-0x58(%rbp)
movb   $0x0,-0x50(%rbp)
cmpl   $0x0,-0x8(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b1 <main_screen+0x31>
jmp    12d3 <main_screen+0x153>
xor    %eax,%eax
mov    %al,-0x61(%rbp)
call   1090 <clear_screen@plt>
mov    -0x61(%rbp),%al
call   1040 <cursor_on@plt>
mov    $0x1e,%edi
mov    $0x1,%esi
call   1060 <cursor@plt>
mov    -0x61(%rbp),%al
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
mov    $0x5,%edi
mov    $0x14,%esi
call   1060 <cursor@plt>
mov    -0x61(%rbp),%al
lea    0xe83(%rip),%rdi
lea    -0x50(%rbp),%rsi
call   1030 <printf@plt>
mov    -0x61(%rbp),%al
call   1080 <getch@plt>
mov    %eax,-0x4(%rbp)
mov    %eax,%ecx
mov    %rcx,-0x60(%rbp)
sub    $0x1b,%eax
ja     128c <main_screen+0x10c>
mov    -0x60(%rbp),%rax
lea    0xdd8(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xor    %eax,%eax
call   1080 <getch@plt>
mov    %eax,-0x4(%rbp)
jmp    12ce <main_screen+0x14e>
movl   $0x1,-0x8(%rbp)
jmp    12ce <main_screen+0x14e>
cmpq   $0x0,-0x58(%rbp)
jbe    126b <main_screen+0xeb>
mov    -0x58(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x58(%rbp)
movb   $0x0,-0x51(%rbp,%rax,1)
jmp    12ce <main_screen+0x14e>
lea    -0x50(%rbp),%rdi
call   10a0 <start_game@plt>
jmp    12ce <main_screen+0x14e>
lea    -0x50(%rbp),%rdi
call   1050 <start_edit@plt>
jmp    12ce <main_screen+0x14e>
mov    -0x4(%rbp),%edi
call   1070 <isprint@plt>
cmp    $0x0,%eax
je     12c9 <main_screen+0x149>
cmpq   $0x46,-0x58(%rbp)
jae    12c9 <main_screen+0x149>
mov    -0x4(%rbp),%eax
mov    %al,%cl
mov    -0x58(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x58(%rbp)
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0x58(%rbp),%rax
movb   $0x0,-0x50(%rbp,%rax,1)
jmp    12ce <main_screen+0x14e>
jmp    119b <main_screen+0x1b>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main_screen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
movb   $0x0,(%rsp)
lea    0xed7(%rip),%r14
lea    0xedd(%rip),%r15
mov    %rsp,%r12
lea    0xe56(%rip),%rbx
xor    %eax,%eax
mov    %rax,%r13
jmp    11c8 <main_screen+0x48>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1050 <start_edit@plt>
xor    %eax,%eax
call   1090 <clear_screen@plt>
xor    %eax,%eax
call   1040 <cursor_on@plt>
mov    $0x1e,%edi
mov    $0x1,%esi
call   1060 <cursor@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x5,%edi
mov    $0x14,%esi
call   1060 <cursor@plt>
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1080 <getch@plt>
mov    %eax,%ebp
cmp    $0x1b,%eax
ja     1230 <main_screen+0xb0>
mov    %ebp,%eax
movslq (%rbx,%rax,4),%rax
add    %rbx,%rax
jmp    *%rax
xor    %eax,%eax
call   1080 <getch@plt>
jmp    11c8 <main_screen+0x48>
nopl   (%rax)
mov    %ebp,%edi
call   1070 <isprint@plt>
test   %eax,%eax
je     11c8 <main_screen+0x48>
cmp    $0x45,%r13
ja     11c8 <main_screen+0x48>
jmp    1280 <main_screen+0x100>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
call   10a0 <start_game@plt>
jmp    11c8 <main_screen+0x48>
nopl   (%rax)
mov    $0x0,%eax
test   %r13,%r13
je     11ac <main_screen+0x2c>
movb   $0x0,-0x1(%rsp,%r13,1)
add    $0xffffffffffffffff,%r13
mov    %r13,%rax
jmp    11ac <main_screen+0x2c>
lea    0x1(%r13),%rax
mov    %bpl,(%rsp,%r13,1)
movb   $0x0,0x1(%rsp,%r13,1)
jmp    11ac <main_screen+0x2c>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"TMAZE by DWK\00"
@.str.1 = [3 x i8] c"%s\00"
define void @main_screen() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [70 x i8]
%4 = alloca i64
store i32 0, i32* %2
store i64 0, i64* %4
%5 = getelementptr inbounds [70 x i8], [70 x i8]* %3, i64 0, i64 0
store i8 0, i8* %5
br label %6
6: ; preds = %53, %0
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 0
%9 = xor i1 %8, true
br i1 %9, label %10, label %54
10: ; preds = %6
%11 = call i32 (...) @clear_screen()
%12 = call i32 (...) @cursor_on()
%13 = call i32 @cursor(i32 30, i32 1)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @cursor(i32 5, i32 20)
%16 = getelementptr inbounds [70 x i8], [70 x i8]* %3, i64 0, i64 0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = call i32 (...) @getch()
store i32 %18, i32* %1
switch i32 %18, label %37 [
i32 0, label %19
i32 27, label %22
i32 8, label %23
i32 13, label %31
i32 10, label %34
]
19: ; preds = %10
%20 = call i32 (...) @getch()
store i32 %20, i32* %1
switch i32 %20, label %21 [
]
21: ; preds = %19
br label %53
22: ; preds = %10
store i32 1, i32* %2
br label %53
23: ; preds = %10
%24 = load i64, i64* %4
%25 = icmp ugt i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i64, i64* %4
%28 = add i64 %27, -1
store i64 %28, i64* %4
%29 = getelementptr inbounds [70 x i8], [70 x i8]* %3, i64 0, i64 %28
store i8 0, i8* %29
br label %30
30: ; preds = %26, %23
br label %53
31: ; preds = %10
%32 = getelementptr inbounds [70 x i8], [70 x i8]* %3, i64 0, i64 0
%33 = call i32 @start_game(i8* %32)
br label %53
34: ; preds = %10
%35 = getelementptr inbounds [70 x i8], [70 x i8]* %3, i64 0, i64 0
%36 = call i32 @start_edit(i8* %35)
br label %53
37: ; preds = %10
%38 = load i32, i32* %1
%39 = call i32 @isprint(i32 %38)
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %52
41: ; preds = %37
%42 = load i64, i64* %4
%43 = icmp ult i64 %42, 70
br i1 %43, label %44, label %52
44: ; preds = %41
%45 = load i32, i32* %1
%46 = trunc i32 %45 to i8
%47 = load i64, i64* %4
%48 = add i64 %47, 1
store i64 %48, i64* %4
%49 = getelementptr inbounds [70 x i8], [70 x i8]* %3, i64 0, i64 %47
store i8 %46, i8* %49
%50 = load i64, i64* %4
%51 = getelementptr inbounds [70 x i8], [70 x i8]* %3, i64 0, i64 %50
store i8 0, i8* %51
br label %52
52: ; preds = %44, %41, %37
br label %53
53: ; preds = %52, %34, %31, %30, %22, %21
br label %6
54: ; preds = %6
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"TMAZE by DWK\00"
@.str.1 = [3 x i8] c"%s\00"
define void @main_screen() {
%1 = alloca [70 x i8]
%2 = getelementptr inbounds [70 x i8], [70 x i8]* %1, i64 0, i64 0
store i8 0, i8* %2
br label %3
3: ; preds = %35, %0
%4 = phi i64 [ 0, %0 ], [ %36, %35 ]
%5 = icmp ult i64 %4, 70
br label %6
6: ; preds = %29, %3
%7 = call i32 (...) @clear_screen()
%8 = call i32 (...) @cursor_on()
%9 = call i32 @cursor(i32 30, i32 1)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @cursor(i32 5, i32 20)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%13 = call i32 (...) @getch()
switch i32 %13, label %25 [
i32 0, label %14
i32 27, label %37
i32 8, label %16
i32 13, label %21
i32 10, label %23
]
14: ; preds = %6
%15 = call i32 (...) @getch()
br label %29
16: ; preds = %6
%17 = icmp eq i64 %4, 0
br i1 %17, label %35, label %18
18: ; preds = %16
%19 = add i64 %4, -1
%20 = getelementptr inbounds [70 x i8], [70 x i8]* %1, i64 0, i64 %19
store i8 0, i8* %20
br label %35
21: ; preds = %6
%22 = call i32 @start_game(i8* %2)
br label %29
23: ; preds = %6
%24 = call i32 @start_edit(i8* %2)
br label %29
25: ; preds = %6
%26 = call i32 @isprint(i32 %13)
%27 = icmp ne i32 %26, 0
%28 = select i1 %27, i1 %5, i1 false
br i1 %28, label %30, label %29
29: ; preds = %25, %23, %21, %14
br label %6
30: ; preds = %25
%31 = trunc i32 %13 to i8
%32 = add nuw nsw i64 %4, 1
%33 = getelementptr inbounds [70 x i8], [70 x i8]* %1, i64 0, i64 %4
store i8 %31, i8* %33
%34 = getelementptr inbounds [70 x i8], [70 x i8]* %1, i64 0, i64 %32
store i8 0, i8* %34
br label %35
35: ; preds = %30, %16, %18
%36 = phi i64 [ %19, %18 ], [ 0, %16 ], [ %32, %30 ]
br label %3
37: ; preds = %6
ret void
}