#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 COLS;
int LINES;
int /*<<< orphan*/ mvaddstr(int, int, char *);
int /*<<< orphan*/ refresh();
int strlen(char *);
void drawFrame() {
  mvaddstr(5 / 2, (COLS - 0 - strlen("HELLO SNAKE")) / 2, "HELLO SNAKE");
  int i;
  for (i = 0; i <= COLS; i++) {
    mvaddstr(5, i, "-");
  }
  for (i = 5 + 1; i < (LINES - 5); i++) {
    mvaddstr(i, 0, "|");
  }
  for (i = 5 + 1; i < (LINES - 5); i++) {
    mvaddstr(i, COLS - 1, "|");
  }
  for (i = 0; i <= COLS; i++) {
    mvaddstr((LINES - 5), i, "-");
  }
  mvaddstr((LINES - 5) + 2,
           (COLS - 0 -
            strlen(" Usage: w/s/a/d -> up/down/left/right | space -> stop or "
                   "run \n ")) /
               2,
           " Usage: w/s/a/d -> up/down/left/right | space -> stop or run \n ");
  mvaddstr((LINES - 5) + 3,
           (COLS - 0 -
            strlen("********************* press r to restart | q to quit "
                   "********************* \n")) /
               2,
           "********************* press r to restart | q to quit "
           "********************* \n");
  refresh();
}


x86 assembly (clang, -O0):
<drawFrame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2ea1(%rip),%rax
mov    (%rax),%eax
sub    $0x0,%eax
mov    %eax,-0x8(%rbp)
lea    0xeb2(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%eax
sub    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    $0x2,%edi
lea    0xe90(%rip),%rdx
call   1050 <mvaddstr@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e5a(%rip),%rcx
cmp    (%rcx),%eax
jg     11b0 <drawFrame+0x80>
mov    -0x4(%rbp),%esi
mov    $0x5,%edi
lea    0xe6f(%rip),%rdx
call   1050 <mvaddstr@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    117c <drawFrame+0x4c>
movl   $0x6,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e27(%rip),%rcx
mov    (%rcx),%ecx
sub    $0x5,%ecx
cmp    %ecx,%eax
jge    11ed <drawFrame+0xbd>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
lea    0xe34(%rip),%rdx
call   1050 <mvaddstr@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11b7 <drawFrame+0x87>
movl   $0x6,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2dea(%rip),%rcx
mov    (%rcx),%ecx
sub    $0x5,%ecx
cmp    %ecx,%eax
jge    1234 <drawFrame+0x104>
mov    -0x4(%rbp),%edi
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
sub    $0x1,%esi
lea    0xded(%rip),%rdx
call   1050 <mvaddstr@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11f4 <drawFrame+0xc4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2d9b(%rip),%rcx
cmp    (%rcx),%eax
jg     1276 <drawFrame+0x146>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
sub    $0x5,%edi
mov    -0x4(%rbp),%esi
lea    0xda9(%rip),%rdx
call   1050 <mvaddstr@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    123b <drawFrame+0x10b>
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
sub    $0x5,%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
mov    0x2d51(%rip),%rax
mov    (%rax),%eax
sub    $0x0,%eax
mov    %eax,-0x14(%rbp)
lea    0xd72(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x18(%rbp),%edi
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xd52(%rip),%rdx
call   1050 <mvaddstr@plt>
mov    0x2d1e(%rip),%rax
mov    (%rax),%eax
sub    $0x5,%eax
add    $0x3,%eax
mov    %eax,-0x10(%rbp)
mov    0x2d04(%rip),%rax
mov    (%rax),%eax
sub    $0x0,%eax
mov    %eax,-0xc(%rbp)
lea    0xd65(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x10(%rbp),%edi
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
sub    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xd45(%rip),%rdx
call   1050 <mvaddstr@plt>
mov    $0x0,%al
call   1040 <refresh@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drawFrame>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2ea1(%rip),%r15
mov    (%r15),%ebp
lea    0xeb7(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
sub    %eax,%ebp
mov    %ebp,%esi
shr    $0x1f,%esi
add    %ebp,%esi
sar    %esi
mov    $0x2,%edi
mov    %rbx,%rdx
call   1050 <mvaddstr@plt>
cmpl   $0x0,(%r15)
js     1197 <drawFrame+0x67>
mov    $0xffffffff,%ebx
lea    0xe91(%rip),%rbp
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
mov    $0x5,%edi
mov    %ebx,%esi
mov    %rbp,%rdx
call   1050 <mvaddstr@plt>
cmp    (%r15),%ebx
jl     1180 <drawFrame+0x50>
mov    0x2e4a(%rip),%r12
mov    (%r12),%ebx
cmp    $0xc,%ebx
jl     120e <drawFrame+0xde>
mov    $0x6,%ebp
lea    0xe5b(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
xor    %esi,%esi
mov    %r14,%rdx
call   1050 <mvaddstr@plt>
add    $0x1,%ebp
mov    (%r12),%ebx
lea    -0x5(%rbx),%eax
cmp    %eax,%ebp
jl     11c0 <drawFrame+0x90>
cmp    $0xc,%ebx
jl     120e <drawFrame+0xde>
mov    $0x6,%ebp
lea    0xe23(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    (%r15),%esi
add    $0xffffffff,%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1050 <mvaddstr@plt>
add    $0x1,%ebp
mov    (%r12),%ebx
lea    -0x5(%rbx),%eax
cmp    %eax,%ebp
jl     11f0 <drawFrame+0xc0>
mov    (%r15),%r14d
test   %r14d,%r14d
js     1262 <drawFrame+0x132>
add    $0xfffffffb,%ebx
lea    0xdec(%rip),%rdx
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <mvaddstr@plt>
mov    (%r15),%r14d
test   %r14d,%r14d
jle    125e <drawFrame+0x12e>
mov    $0x1,%ebp
lea    0xdcf(%rip),%rbx
nopl   (%rax)
mov    (%r12),%edi
add    $0xfffffffb,%edi
mov    %ebp,%esi
mov    %rbx,%rdx
call   1050 <mvaddstr@plt>
mov    (%r15),%r14d
lea    0x1(%rbp),%eax
cmp    %r14d,%ebp
mov    %eax,%ebp
jl     1240 <drawFrame+0x110>
mov    (%r12),%ebx
add    $0xfffffffd,%ebx
lea    0xda4(%rip),%rbp
mov    %rbp,%rdi
call   1030 <strlen@plt>
sub    %eax,%r14d
mov    %r14d,%esi
shr    $0x1f,%esi
add    %r14d,%esi
sar    %esi
mov    %ebx,%edi
mov    %rbp,%rdx
call   1050 <mvaddstr@plt>
mov    (%r12),%ebx
add    $0xfffffffe,%ebx
mov    (%r15),%ebp
lea    0xdb3(%rip),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
sub    %eax,%ebp
mov    %ebp,%esi
shr    $0x1f,%esi
add    %ebp,%esi
sar    %esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1050 <mvaddstr@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <refresh@plt>

LLVM IR (-O0):
@COLS = global i32 0
@.str = [12 x i8] c"HELLO SNAKE\00"
@.str.1 = [2 x i8] c"-\00"
@LINES = global i32 0
@.str.2 = [2 x i8] c"|\00"
@.str.3 = [64 x i8] c" Usage: w/s/a/d -> up/down/left/right | space -> stop or run \0A \00"
@.str.4 = [77 x i8] c"********************* press r to restart | q to quit ********************* \0A\00"
define void @drawFrame() {
%1 = alloca i32
%2 = load i32, i32* @COLS
%3 = sub nsw i32 %2, 0
%4 = call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%5 = sub nsw i32 %3, %4
%6 = sdiv i32 %5, 2
%7 = call i32 @mvaddstr(i32 2, i32 %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %8
8: ; preds = %15, %0
%9 = load i32, i32* %1
%10 = load i32, i32* @COLS
%11 = icmp sle i32 %9, %10
br i1 %11, label %12, label %18
12: ; preds = %8
%13 = load i32, i32* %1
%14 = call i32 @mvaddstr(i32 5, i32 %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %12
%16 = load i32, i32* %1
%17 = add nsw i32 %16, 1
store i32 %17, i32* %1
br label %8
18: ; preds = %8
store i32 6, i32* %1
br label %19
19: ; preds = %27, %18
%20 = load i32, i32* %1
%21 = load i32, i32* @LINES
%22 = sub nsw i32 %21, 5
%23 = icmp slt i32 %20, %22
br i1 %23, label %24, label %30
24: ; preds = %19
%25 = load i32, i32* %1
%26 = call i32 @mvaddstr(i32 %25, i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %24
%28 = load i32, i32* %1
%29 = add nsw i32 %28, 1
store i32 %29, i32* %1
br label %19
30: ; preds = %19
store i32 6, i32* %1
br label %31
31: ; preds = %41, %30
%32 = load i32, i32* %1
%33 = load i32, i32* @LINES
%34 = sub nsw i32 %33, 5
%35 = icmp slt i32 %32, %34
br i1 %35, label %36, label %44
36: ; preds = %31
%37 = load i32, i32* %1
%38 = load i32, i32* @COLS
%39 = sub nsw i32 %38, 1
%40 = call i32 @mvaddstr(i32 %37, i32 %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %36
%42 = load i32, i32* %1
%43 = add nsw i32 %42, 1
store i32 %43, i32* %1
br label %31
44: ; preds = %31
store i32 0, i32* %1
br label %45
45: ; preds = %54, %44
%46 = load i32, i32* %1
%47 = load i32, i32* @COLS
%48 = icmp sle i32 %46, %47
br i1 %48, label %49, label %57
49: ; preds = %45
%50 = load i32, i32* @LINES
%51 = sub nsw i32 %50, 5
%52 = load i32, i32* %1
%53 = call i32 @mvaddstr(i32 %51, i32 %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %54
54: ; preds = %49
%55 = load i32, i32* %1
%56 = add nsw i32 %55, 1
store i32 %56, i32* %1
br label %45
57: ; preds = %45
%58 = load i32, i32* @LINES
%59 = sub nsw i32 %58, 5
%60 = add nsw i32 %59, 2
%61 = load i32, i32* @COLS
%62 = sub nsw i32 %61, 0
%63 = call i32 @strlen(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0))
%64 = sub nsw i32 %62, %63
%65 = sdiv i32 %64, 2
%66 = call i32 @mvaddstr(i32 %60, i32 %65, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0))
%67 = load i32, i32* @LINES
%68 = sub nsw i32 %67, 5
%69 = add nsw i32 %68, 3
%70 = load i32, i32* @COLS
%71 = sub nsw i32 %70, 0
%72 = call i32 @strlen(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.4, i64 0, i64 0))
%73 = sub nsw i32 %71, %72
%74 = sdiv i32 %73, 2
%75 = call i32 @mvaddstr(i32 %69, i32 %74, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.4, i64 0, i64 0))
%76 = call i32 (...) @refresh()
ret void
}

LLVM IR (-O2):
@COLS = global i32 0
@.str = [12 x i8] c"HELLO SNAKE\00"
@.str.1 = [2 x i8] c"-\00"
@LINES = global i32 0
@.str.2 = [2 x i8] c"|\00"
@.str.3 = [64 x i8] c" Usage: w/s/a/d -> up/down/left/right | space -> stop or run \0A \00"
@.str.4 = [77 x i8] c"********************* press r to restart | q to quit ********************* \0A\00"
define void @drawFrame() {
%1 = load i32, i32* @COLS
%2 = tail call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%3 = sub nsw i32 %1, %2
%4 = sdiv i32 %3, 2
%5 = tail call i32 @mvaddstr(i32 2, i32 %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @COLS
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %11, %0
%9 = load i32, i32* @LINES
%10 = icmp sgt i32 %9, 11
br i1 %10, label %19, label %26
11: ; preds = %0, %11
%12 = phi i32 [ %14, %11 ], [ 0, %0 ]
%13 = tail call i32 @mvaddstr(i32 5, i32 %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = add nuw nsw i32 %12, 1
%15 = load i32, i32* @COLS
%16 = icmp slt i32 %12, %15
br i1 %16, label %11, label %8
17: ; preds = %19
%18 = icmp sgt i32 %23, 11
br i1 %18, label %35, label %26
19: ; preds = %8, %19
%20 = phi i32 [ %22, %19 ], [ 6, %8 ]
%21 = tail call i32 @mvaddstr(i32 %20, i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = add nuw nsw i32 %20, 1
%23 = load i32, i32* @LINES
%24 = add nsw i32 %23, -5
%25 = icmp slt i32 %22, %24
br i1 %25, label %19, label %17
26: ; preds = %35, %8, %17
%27 = phi i32 [ %23, %17 ], [ %9, %8 ], [ %41, %35 ]
%28 = load i32, i32* @COLS
%29 = icmp slt i32 %28, 0
br i1 %29, label %55, label %30
30: ; preds = %26
%31 = add nsw i32 %27, -5
%32 = tail call i32 @mvaddstr(i32 %31, i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%33 = load i32, i32* @COLS
%34 = icmp sgt i32 %33, 0
br i1 %34, label %44, label %52
35: ; preds = %17, %35
%36 = phi i32 [ %40, %35 ], [ 6, %17 ]
%37 = load i32, i32* @COLS
%38 = add nsw i32 %37, -1
%39 = tail call i32 @mvaddstr(i32 %36, i32 %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%40 = add nuw nsw i32 %36, 1
%41 = load i32, i32* @LINES
%42 = add nsw i32 %41, -5
%43 = icmp slt i32 %40, %42
br i1 %43, label %35, label %26
44: ; preds = %30, %44
%45 = phi i32 [ %46, %44 ], [ 0, %30 ]
%46 = add nuw nsw i32 %45, 1
%47 = load i32, i32* @LINES
%48 = add nsw i32 %47, -5
%49 = tail call i32 @mvaddstr(i32 %48, i32 %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%50 = load i32, i32* @COLS
%51 = icmp slt i32 %46, %50
br i1 %51, label %44, label %52
52: ; preds = %44, %30
%53 = phi i32 [ %33, %30 ], [ %50, %44 ]
%54 = load i32, i32* @LINES
br label %55
55: ; preds = %52, %26
%56 = phi i32 [ %27, %26 ], [ %54, %52 ]
%57 = phi i32 [ %28, %26 ], [ %53, %52 ]
%58 = add nsw i32 %56, -3
%59 = tail call i32 @strlen(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0))
%60 = sub nsw i32 %57, %59
%61 = sdiv i32 %60, 2
%62 = tail call i32 @mvaddstr(i32 %58, i32 %61, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0))
%63 = load i32, i32* @LINES
%64 = add nsw i32 %63, -2
%65 = load i32, i32* @COLS
%66 = tail call i32 @strlen(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.4, i64 0, i64 0))
%67 = sub nsw i32 %65, %66
%68 = sdiv i32 %67, 2
%69 = tail call i32 @mvaddstr(i32 %64, i32 %68, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.4, i64 0, i64 0))
%70 = tail call i32 (...) @refresh()
ret void
}