#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*/ circle(int, int, int);
int /*<<< orphan*/ cleardevice();
int /*<<< orphan*/ closegraph();
int getch();
int getmaxx();
int getmaxy();
int /*<<< orphan*/ initgraph(int *, int *, char *);
int /*<<< orphan*/ outtextxy(int /*<<< orphan*/, int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ setbkcolor(int /*<<< orphan*/);
int /*<<< orphan*/ setcolor(int);
int main(void) {
  int c, gd, gm, x, y;
  gd = 11;
  gm = 7;
  initgraph(&gd, &gm, "");
  setbkcolor(0);
  setcolor(14);
  cleardevice();
  x = getmaxx() / 2;
  y = getmaxy() / 2;
  outtextxy(0, 0, "Press movement keys (ESC=exit)");
  do {
    setcolor(15);
    circle(x, y, 10);
    c = getch();
    setcolor(4);
    circle(x, y, 10);
    switch (c) {
    case 82:
      y -= 20;
      break;
    case 84:
      y += 20;
      break;
    case 81:
      x -= 20;
      break;
    case 83:
      x += 20;
      break;
    case 80:
      x = 10;
      y = 20;
      break;
    case 85:
      y -= 80;
      break;
    case 86:
      y += 80;
      break;
    case 87:
      x = getmaxx() - 10;
      y = getmaxy() - 10;
      break;
    default:
      printf("Key code: %d\n", c);
    }
    if (x < 0)
      x = getmaxx();
    if (x > getmaxx())
      x = 0;
    if (y < 20)
      y = getmaxy();
    if (y > getmaxy())
      y = 20;
  } while (c != 27);
  closegraph();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xb,-0xc(%rbp)
movl   $0x7,-0x10(%rbp)
lea    -0xc(%rbp),%rdi
lea    -0x10(%rbp),%rsi
lea    0xe70(%rip),%rdx
call   1030 <initgraph@plt>
xor    %edi,%edi
call   1050 <setbkcolor@plt>
mov    $0xe,%edi
call   10d0 <setcolor@plt>
mov    $0x0,%al
call   1040 <cleardevice@plt>
mov    $0x0,%al
call   10b0 <getmaxx@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1070 <getmaxy@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
xor    %esi,%esi
lea    0xdfa(%rip),%rdx
mov    %esi,%edi
call   1060 <outtextxy@plt>
mov    $0xf,%edi
call   10d0 <setcolor@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    $0xa,%edx
mov    %edx,-0x24(%rbp)
call   10a0 <circle@plt>
xor    %eax,%eax
call   10c0 <getch@plt>
mov    %eax,-0x8(%rbp)
mov    $0x4,%edi
call   10d0 <setcolor@plt>
mov    -0x24(%rbp),%edx
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   10a0 <circle@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffb0,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x7,%eax
ja     131b <main+0x16b>
mov    -0x20(%rbp),%rax
lea    0xd74(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%eax
sub    $0x14,%eax
mov    %eax,-0x18(%rbp)
jmp    132a <main+0x17a>
mov    -0x18(%rbp),%eax
add    $0x14,%eax
mov    %eax,-0x18(%rbp)
jmp    132a <main+0x17a>
mov    -0x14(%rbp),%eax
sub    $0x14,%eax
mov    %eax,-0x14(%rbp)
jmp    132a <main+0x17a>
mov    -0x14(%rbp),%eax
add    $0x14,%eax
mov    %eax,-0x14(%rbp)
jmp    132a <main+0x17a>
movl   $0xa,-0x14(%rbp)
movl   $0x14,-0x18(%rbp)
jmp    132a <main+0x17a>
mov    -0x18(%rbp),%eax
sub    $0x50,%eax
mov    %eax,-0x18(%rbp)
jmp    132a <main+0x17a>
mov    -0x18(%rbp),%eax
add    $0x50,%eax
mov    %eax,-0x18(%rbp)
jmp    132a <main+0x17a>
mov    $0x0,%al
call   10b0 <getmaxx@plt>
sub    $0xa,%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1070 <getmaxy@plt>
sub    $0xa,%eax
mov    %eax,-0x18(%rbp)
jmp    132a <main+0x17a>
mov    -0x8(%rbp),%esi
lea    0xd1a(%rip),%rdi
call   1080 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jge    133e <main+0x18e>
mov    $0x0,%al
call   10b0 <getmaxx@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   10b0 <getmaxx@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jle    135f <main+0x1af>
movl   $0x0,-0x14(%rbp)
cmpl   $0x14,-0x18(%rbp)
jge    1373 <main+0x1c3>
mov    $0x0,%al
call   1070 <getmaxy@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1070 <getmaxy@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jle    1394 <main+0x1e4>
movl   $0x14,-0x18(%rbp)
jmp    1399 <main+0x1e9>
cmpl   $0x1b,-0x8(%rbp)
jne    122d <main+0x7d>
mov    $0x0,%al
call   1090 <closegraph@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0xb,0x4(%rsp)
movl   $0x7,(%rsp)
lea    0xe7b(%rip),%rdx
lea    0x4(%rsp),%rdi
mov    %rsp,%rsi
call   1030 <initgraph@plt>
xor    %edi,%edi
call   1050 <setbkcolor@plt>
mov    $0xe,%edi
call   10d0 <setcolor@plt>
xor    %eax,%eax
call   1040 <cleardevice@plt>
xor    %eax,%eax
call   10b0 <getmaxx@plt>
mov    %eax,%r12d
shr    $0x1f,%r12d
add    %eax,%r12d
sar    %r12d
xor    %eax,%eax
call   1070 <getmaxy@plt>
mov    %eax,%r13d
shr    $0x1f,%r13d
add    %eax,%r13d
sar    %r13d
lea    0xdfb(%rip),%rdx
xor    %edi,%edi
xor    %esi,%esi
call   1060 <outtextxy@plt>
lea    0xdcb(%rip),%r14
jmp    125e <main+0xae>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <getmaxy@plt>
cmp    %eax,%ebx
mov    $0x14,%eax
cmovg  %eax,%ebx
mov    %ebx,%r13d
cmp    $0x1b,%r15d
je     1388 <main+0x1d8>
mov    $0xf,%edi
call   10d0 <setcolor@plt>
mov    $0xa,%ebp
mov    %r12d,%edi
mov    %r13d,%esi
mov    $0xa,%edx
call   10a0 <circle@plt>
xor    %eax,%eax
call   10c0 <getch@plt>
mov    %eax,%r15d
mov    $0x4,%edi
call   10d0 <setcolor@plt>
mov    %r12d,%edi
mov    %r13d,%esi
mov    $0xa,%edx
call   10a0 <circle@plt>
lea    -0x50(%r15),%eax
cmp    $0x7,%eax
ja     12c6 <main+0x116>
movslq (%r14,%rax,4),%rax
add    %r14,%rax
mov    $0x14,%ebx
jmp    *%rax
add    $0xffffffec,%r12d
test   %r12d,%r12d
jns    1320 <main+0x170>
jmp    1350 <main+0x1a0>
lea    0xd72(%rip),%rdi
mov    %r15d,%esi
call   1080 <printf@plt>
test   %r12d,%r12d
jns    1320 <main+0x170>
jmp    1350 <main+0x1a0>
add    $0xffffffec,%r13d
test   %r12d,%r12d
jns    1320 <main+0x170>
jmp    1350 <main+0x1a0>
add    $0x14,%r12d
test   %r12d,%r12d
jns    1320 <main+0x170>
jmp    1350 <main+0x1a0>
add    $0x14,%r13d
test   %r12d,%r12d
jns    1320 <main+0x170>
jmp    1350 <main+0x1a0>
add    $0xffffffb0,%r13d
test   %r12d,%r12d
jns    1320 <main+0x170>
jmp    1350 <main+0x1a0>
add    $0x50,%r13d
test   %r12d,%r12d
js     1350 <main+0x1a0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13d,%ebx
mov    %r12d,%ebp
jmp    135c <main+0x1ac>
xor    %eax,%eax
call   10b0 <getmaxx@plt>
mov    %eax,%r12d
add    $0xfffffff6,%r12d
xor    %eax,%eax
call   1070 <getmaxy@plt>
mov    %eax,%r13d
add    $0xfffffff6,%r13d
test   %r12d,%r12d
jns    1320 <main+0x170>
nopl   0x0(%rax)
xor    %eax,%eax
call   10b0 <getmaxx@plt>
mov    %eax,%ebp
mov    %r13d,%ebx
xor    %eax,%eax
call   10b0 <getmaxx@plt>
cmp    %eax,%ebp
mov    %ebp,%r12d
mov    $0x0,%eax
cmovg  %eax,%r12d
cmp    $0x13,%ebx
jg     1240 <main+0x90>
xor    %eax,%eax
call   1070 <getmaxy@plt>
mov    %eax,%ebx
jmp    1240 <main+0x90>
xor    %eax,%eax
call   1090 <closegraph@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [31 x i8] c"Press movement keys (ESC=exit)\00"
@.str.2 = [14 x i8] c"Key code: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 11, i32* %3
store i32 7, i32* %4
%7 = call i32 @initgraph(i32* %3, i32* %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @setbkcolor(i32 0)
%9 = call i32 @setcolor(i32 14)
%10 = call i32 (...) @cleardevice()
%11 = call i32 (...) @getmaxx()
%12 = sdiv i32 %11, 2
store i32 %12, i32* %5
%13 = call i32 (...) @getmaxy()
%14 = sdiv i32 %13, 2
store i32 %14, i32* %6
%15 = call i32 @outtextxy(i32 0, i32 0, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %75, %0
%17 = call i32 @setcolor(i32 15)
%18 = load i32, i32* %5
%19 = load i32, i32* %6
%20 = call i32 @circle(i32 %18, i32 %19, i32 10)
%21 = call i32 (...) @getch()
store i32 %21, i32* %2
%22 = call i32 @setcolor(i32 4)
%23 = load i32, i32* %5
%24 = load i32, i32* %6
%25 = call i32 @circle(i32 %23, i32 %24, i32 10)
%26 = load i32, i32* %2
switch i32 %26, label %51 [
i32 82, label %27
i32 84, label %30
i32 81, label %33
i32 83, label %36
i32 80, label %39
i32 85, label %40
i32 86, label %43
i32 87, label %46
]
27: ; preds = %16
%28 = load i32, i32* %6
%29 = sub nsw i32 %28, 20
store i32 %29, i32* %6
br label %54
30: ; preds = %16
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 20
store i32 %32, i32* %6
br label %54
33: ; preds = %16
%34 = load i32, i32* %5
%35 = sub nsw i32 %34, 20
store i32 %35, i32* %5
br label %54
36: ; preds = %16
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 20
store i32 %38, i32* %5
br label %54
39: ; preds = %16
store i32 10, i32* %5
store i32 20, i32* %6
br label %54
40: ; preds = %16
%41 = load i32, i32* %6
%42 = sub nsw i32 %41, 80
store i32 %42, i32* %6
br label %54
43: ; preds = %16
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 80
store i32 %45, i32* %6
br label %54
46: ; preds = %16
%47 = call i32 (...) @getmaxx()
%48 = sub nsw i32 %47, 10
store i32 %48, i32* %5
%49 = call i32 (...) @getmaxy()
%50 = sub nsw i32 %49, 10
store i32 %50, i32* %6
br label %54
51: ; preds = %16
%52 = load i32, i32* %2
%53 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %52)
br label %54
54: ; preds = %51, %46, %43, %40, %39, %36, %33, %30, %27
%55 = load i32, i32* %5
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %54
%58 = call i32 (...) @getmaxx()
store i32 %58, i32* %5
br label %59
59: ; preds = %57, %54
%60 = load i32, i32* %5
%61 = call i32 (...) @getmaxx()
%62 = icmp sgt i32 %60, %61
br i1 %62, label %63, label %64
63: ; preds = %59
store i32 0, i32* %5
br label %64
64: ; preds = %63, %59
%65 = load i32, i32* %6
%66 = icmp slt i32 %65, 20
br i1 %66, label %67, label %69
67: ; preds = %64
%68 = call i32 (...) @getmaxy()
store i32 %68, i32* %6
br label %69
69: ; preds = %67, %64
%70 = load i32, i32* %6
%71 = call i32 (...) @getmaxy()
%72 = icmp sgt i32 %70, %71
br i1 %72, label %73, label %74
73: ; preds = %69
store i32 20, i32* %6
br label %74
74: ; preds = %73, %69
br label %75
75: ; preds = %74
%76 = load i32, i32* %2
%77 = icmp ne i32 %76, 27
br i1 %77, label %16, label %78
78: ; preds = %75
%79 = call i32 (...) @closegraph()
ret i32 0
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [31 x i8] c"Press movement keys (ESC=exit)\00"
@.str.2 = [14 x i8] c"Key code: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
store i32 11, i32* %1
store i32 7, i32* %2
%5 = call i32 @initgraph(i32* %1, i32* %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @setbkcolor(i32 0)
%7 = call i32 @setcolor(i32 14)
%8 = call i32 (...) @cleardevice()
%9 = call i32 (...) @getmaxx()
%10 = sdiv i32 %9, 2
%11 = call i32 (...) @getmaxy()
%12 = sdiv i32 %11, 2
%13 = call i32 @outtextxy(i32 0, i32 0, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %56, %0
%15 = phi i32 [ %10, %0 ], [ %52, %56 ]
%16 = phi i32 [ %12, %0 ], [ %60, %56 ]
%17 = call i32 @setcolor(i32 15)
%18 = call i32 @circle(i32 %15, i32 %16, i32 10)
%19 = call i32 (...) @getch()
%20 = call i32 @setcolor(i32 4)
%21 = call i32 @circle(i32 %15, i32 %16, i32 10)
switch i32 %19, label %39 [
i32 82, label %22
i32 84, label %24
i32 81, label %26
i32 83, label %28
i32 80, label %47
i32 85, label %30
i32 86, label %32
i32 87, label %34
]
22: ; preds = %14
%23 = add nsw i32 %16, -20
br label %41
24: ; preds = %14
%25 = add nsw i32 %16, 20
br label %41
26: ; preds = %14
%27 = add nsw i32 %15, -20
br label %41
28: ; preds = %14
%29 = add nsw i32 %15, 20
br label %41
30: ; preds = %14
%31 = add nsw i32 %16, -80
br label %41
32: ; preds = %14
%33 = add nsw i32 %16, 80
br label %41
34: ; preds = %14
%35 = call i32 (...) @getmaxx()
%36 = add nsw i32 %35, -10
%37 = call i32 (...) @getmaxy()
%38 = add nsw i32 %37, -10
br label %41
39: ; preds = %14
%40 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %41
41: ; preds = %39, %34, %32, %30, %28, %26, %24, %22
%42 = phi i32 [ %15, %39 ], [ %36, %34 ], [ %15, %32 ], [ %15, %30 ], [ %29, %28 ], [ %27, %26 ], [ %15, %24 ], [ %15, %22 ]
%43 = phi i32 [ %16, %39 ], [ %38, %34 ], [ %33, %32 ], [ %31, %30 ], [ %16, %28 ], [ %16, %26 ], [ %25, %24 ], [ %23, %22 ]
%44 = icmp slt i32 %42, 0
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = call i32 (...) @getmaxx()
br label %47
47: ; preds = %14, %45, %41
%48 = phi i32 [ %43, %45 ], [ %43, %41 ], [ 20, %14 ]
%49 = phi i32 [ %46, %45 ], [ %42, %41 ], [ 10, %14 ]
%50 = call i32 (...) @getmaxx()
%51 = icmp sgt i32 %49, %50
%52 = select i1 %51, i32 0, i32 %49
%53 = icmp slt i32 %48, 20
br i1 %53, label %54, label %56
54: ; preds = %47
%55 = call i32 (...) @getmaxy()
br label %56
56: ; preds = %54, %47
%57 = phi i32 [ %55, %54 ], [ %48, %47 ]
%58 = call i32 (...) @getmaxy()
%59 = icmp sgt i32 %57, %58
%60 = select i1 %59, i32 20, i32 %57
%61 = icmp eq i32 %19, 27
br i1 %61, label %62, label %14
62: ; preds = %56
%63 = call i32 (...) @closegraph()
ret i32 0
}