#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*/ cannon(int, int);
int damage();
int /*<<< orphan*/ new_corner();
int plot_course(int, int);
int scan(int, int);
int rmain() {
  while (1) {
    int range;
    int hit;
    int dir, sc;
    int d;
    new_corner();
    d = damage();
    sc = plot_course(500, 500);
    dir = sc - 46;
    hit = 0;
    do {
      dir += 2;
      if (dir >= sc + 45) {
        if (!hit)
          break;
        dir = sc - 45;
      }
      range = scan(dir, 1);
      while (range <= 700 && range > 0 && damage() <= d + 15) {
        hit = 1;
        cannon(dir, range);
        range = scan(dir, 1);
      }
      if (hit) {
        dir = ((dir - 10) > (sc - 45) ? (dir - 10) : (sc - 45));
        hit = 0;
      }
    } while (d == damage());
  }
}


x86 assembly (clang, -O0):
<rmain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1040 <new_corner@plt>
mov    $0x0,%al
call   1070 <damage@plt>
mov    %eax,-0x14(%rbp)
mov    $0x1f4,%esi
mov    %esi,%edi
call   1030 <plot_course@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x2e,%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
add    $0x2d,%ecx
cmp    %ecx,%eax
jl     11ba <rmain+0x6a>
cmpl   $0x0,-0x8(%rbp)
jne    11b1 <rmain+0x61>
jmp    1298 <rmain+0x148>
mov    -0x10(%rbp),%eax
sub    $0x2d,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x1,%esi
call   1050 <scan@plt>
mov    %eax,-0x4(%rbp)
xor    %eax,%eax
cmpl   $0x2bc,-0x4(%rbp)
mov    %al,-0x15(%rbp)
jg     1200 <rmain+0xb0>
xor    %eax,%eax
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0x15(%rbp)
jle    1200 <rmain+0xb0>
mov    $0x0,%al
call   1070 <damage@plt>
mov    -0x14(%rbp),%ecx
add    $0xf,%ecx
cmp    %ecx,%eax
setle  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1210 <rmain+0xc0>
jmp    1237 <rmain+0xe7>
movl   $0x1,-0x8(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1060 <cannon@plt>
mov    -0xc(%rbp),%edi
mov    $0x1,%esi
call   1050 <scan@plt>
mov    %eax,-0x4(%rbp)
jmp    11ca <rmain+0x7a>
cmpl   $0x0,-0x8(%rbp)
je     1279 <rmain+0x129>
mov    -0xc(%rbp),%eax
sub    $0xa,%eax
mov    -0x10(%rbp),%ecx
sub    $0x2d,%ecx
cmp    %ecx,%eax
jle    1263 <rmain+0x113>
mov    -0xc(%rbp),%eax
sub    $0xa,%eax
mov    %eax,-0x1c(%rbp)
jmp    126c <rmain+0x11c>
mov    -0x10(%rbp),%eax
sub    $0x2d,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
jmp    127e <rmain+0x12e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1070 <damage@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
je     1188 <rmain+0x38>
jmp    1158 <rmain+0x8>

x86 assembly (clang, -O2):
<rmain>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <new_corner@plt>
xor    %eax,%eax
call   1070 <damage@plt>
mov    %eax,%r12d
mov    $0x1f4,%edi
mov    $0x1f4,%esi
call   1030 <plot_course@plt>
lea    -0x2e(%rax),%r13d
lea    0x2b(%rax),%r15d
lea    0xf(%r12),%r14d
add    $0xffffffd3,%eax
mov    %rax,0x10(%rsp)
mov    %r15d,0xc(%rsp)
jmp    11af <rmain+0x5f>
nopl   0x0(%rax)
mov    %ebp,%r13d
xor    %eax,%eax
call   1070 <damage@plt>
cmp    %eax,%r12d
jne    1160 <rmain+0x10>
lea    0x2(%r13),%ebp
cmp    %r15d,%r13d
jge    1160 <rmain+0x10>
mov    %ebp,%edi
mov    $0x1,%esi
call   1050 <scan@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%eax
cmp    $0x2bb,%eax
ja     11a0 <rmain+0x50>
mov    %r12,%r15
xor    %eax,%eax
call   1070 <damage@plt>
mov    %eax,%r12d
cmp    %r14d,%eax
jg     121d <rmain+0xcd>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %ebx,%esi
call   1060 <cannon@plt>
mov    %ebp,%edi
mov    $0x1,%esi
call   1050 <scan@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%eax
cmp    $0x2bc,%eax
jae    1243 <rmain+0xf3>
xor    %eax,%eax
call   1070 <damage@plt>
cmp    %r14d,%eax
jle    11f0 <rmain+0xa0>
add    $0xfffffff8,%r13d
mov    0x10(%rsp),%rax
cmp    %eax,%r13d
cmovle %eax,%r13d
cmp    %r14d,%r12d
mov    %r15,%r12
mov    0xc(%rsp),%r15d
jg     11a0 <rmain+0x50>
jmp    11a3 <rmain+0x53>
add    $0xfffffff8,%r13d
mov    0x10(%rsp),%rax
cmp    %eax,%r13d
cmovle %eax,%r13d
mov    %r15,%r12
mov    0xc(%rsp),%r15d
jmp    11a3 <rmain+0x53>

LLVM IR (-O0):
define i32 @rmain() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
br label %6
6: ; preds = %0, %70
%7 = call i32 (...) @new_corner()
%8 = call i32 (...) @damage()
store i32 %8, i32* %5
%9 = call i32 @plot_course(i32 500, i32 500)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = sub nsw i32 %10, 46
store i32 %11, i32* %3
store i32 0, i32* %2
br label %12
12: ; preds = %66, %6
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 2
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 45
%18 = icmp sge i32 %15, %17
br i1 %18, label %19, label %26
19: ; preds = %12
%20 = load i32, i32* %2
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %19
br label %70
23: ; preds = %19
%24 = load i32, i32* %4
%25 = sub nsw i32 %24, 45
store i32 %25, i32* %3
br label %26
26: ; preds = %23, %12
%27 = load i32, i32* %3
%28 = call i32 @scan(i32 %27, i32 1)
store i32 %28, i32* %1
br label %29
29: ; preds = %42, %26
%30 = load i32, i32* %1
%31 = icmp sle i32 %30, 700
br i1 %31, label %32, label %40
32: ; preds = %29
%33 = load i32, i32* %1
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = call i32 (...) @damage()
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 15
%39 = icmp sle i32 %36, %38
br label %40
40: ; preds = %35, %32, %29
%41 = phi i1 [ false, %32 ], [ false, %29 ], [ %39, %35 ]
br i1 %41, label %42, label %48
42: ; preds = %40
store i32 1, i32* %2
%43 = load i32, i32* %3
%44 = load i32, i32* %1
%45 = call i32 @cannon(i32 %43, i32 %44)
%46 = load i32, i32* %3
%47 = call i32 @scan(i32 %46, i32 1)
store i32 %47, i32* %1
br label %29
48: ; preds = %40
%49 = load i32, i32* %2
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %65
51: ; preds = %48
%52 = load i32, i32* %3
%53 = sub nsw i32 %52, 10
%54 = load i32, i32* %4
%55 = sub nsw i32 %54, 45
%56 = icmp sgt i32 %53, %55
br i1 %56, label %57, label %60
57: ; preds = %51
%58 = load i32, i32* %3
%59 = sub nsw i32 %58, 10
br label %63
60: ; preds = %51
%61 = load i32, i32* %4
%62 = sub nsw i32 %61, 45
br label %63
63: ; preds = %60, %57
%64 = phi i32 [ %59, %57 ], [ %62, %60 ]
store i32 %64, i32* %3
store i32 0, i32* %2
br label %65
65: ; preds = %63, %48
br label %66
66: ; preds = %65
%67 = load i32, i32* %5
%68 = call i32 (...) @damage()
%69 = icmp eq i32 %67, %68
br i1 %69, label %12, label %70
70: ; preds = %66, %22
br label %6
}

LLVM IR (-O2):
define i32 @rmain() {
br label %2
1: ; preds = %10, %39
br label %2
2: ; preds = %1, %0
%3 = tail call i32 (...) @new_corner()
%4 = tail call i32 (...) @damage()
%5 = tail call i32 @plot_course(i32 500, i32 500)
%6 = add nsw i32 %5, -46
%7 = add nsw i32 %5, 43
%8 = add nsw i32 %4, 15
%9 = add nsw i32 %5, -45
br label %10
10: ; preds = %39, %2
%11 = phi i32 [ %6, %2 ], [ %40, %39 ]
%12 = add nsw i32 %11, 2
%13 = icmp slt i32 %11, %7
br i1 %13, label %14, label %1
14: ; preds = %10
%15 = tail call i32 @scan(i32 %12, i32 1)
%16 = add i32 %15, -1
%17 = icmp ult i32 %16, 700
br i1 %17, label %18, label %38
18: ; preds = %14
%19 = tail call i32 (...) @damage()
%20 = icmp sgt i32 %19, %8
br i1 %20, label %34, label %24
21: ; preds = %24
%22 = tail call i32 (...) @damage()
%23 = icmp sgt i32 %22, %8
br i1 %23, label %34, label %24
24: ; preds = %18, %21
%25 = phi i32 [ %27, %21 ], [ %15, %18 ]
%26 = tail call i32 @cannon(i32 %12, i32 %25)
%27 = tail call i32 @scan(i32 %12, i32 1)
%28 = add i32 %27, -1
%29 = icmp ult i32 %28, 700
br i1 %29, label %21, label %30
30: ; preds = %24
%31 = add nsw i32 %11, -8
%32 = icmp sgt i32 %31, %9
%33 = select i1 %32, i32 %31, i32 %9
br label %39
34: ; preds = %21, %18
%35 = add nsw i32 %11, -8
%36 = icmp sgt i32 %35, %9
%37 = select i1 %36, i32 %35, i32 %9
br i1 %20, label %38, label %39
38: ; preds = %14, %34
br label %39
39: ; preds = %30, %34, %38
%40 = phi i32 [ %12, %38 ], [ %37, %34 ], [ %33, %30 ]
%41 = tail call i32 (...) @damage()
%42 = icmp eq i32 %4, %41
br i1 %42, label %10, label %1
}