#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*/ backface(int);
int /*<<< orphan*/ clear();
int /*<<< orphan*/ color(int);
float cos(double);
int /*<<< orphan*/ doublebuffer();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ gconfig();
scalar_t__ getvaluator(int);
int /*<<< orphan*/ gexit();
int /*<<< orphan*/ lookat(double, double, int, double, double, double,
                          int /*<<< orphan*/);
int /*<<< orphan*/ makecyl();
int /*<<< orphan*/ perspective(int, double, double, double);
int /*<<< orphan*/ piston(float);
int /*<<< orphan*/ polymode(int);
int /*<<< orphan*/ popmatrix();
int /*<<< orphan*/ pushmatrix();
int /*<<< orphan*/ qdevice(int);
int qread(short *);
scalar_t__ qtest();
int /*<<< orphan*/ rotate(int, char);
int /*<<< orphan*/ swapbuffers();
int /*<<< orphan*/ unqdevice(int);
int /*<<< orphan*/ vinit(char *);
int /*<<< orphan*/ winopen(char *);
main() {
  int i, itest, dobackface, dofill, dodouble;
  char buf[100];
  float H;
  short idata;
  int xr, yr;
  vinit("mswin");
  winopen("piston");
  while (qread(&idata) != 261)
    ;
  doublebuffer();
  gconfig();
  unqdevice(262);
  qdevice('Q');
  qdevice('F');
  qdevice('B');
  qdevice('\033');
  qdevice(261);
  makecyl();
  polymode(1);
  backface(1);
  perspective(400, 1.5, 0.1, 600.0);
  lookat(0.0, -6.0, 4., 0.0, 0.0, 0.0, 0);
  xr = yr = 0;
  while (1) {
    for (i = 0; i < 360; i += 5) {
      color(0);
      clear();
      color(1);
      H = 1.0 + cos(2.0 * 3.14159265 * i / 180.0);
      yr = 500 - (int)getvaluator(2);
      xr = 500 - (int)getvaluator(1);
      yr = 500 - (int)getvaluator(2);
      xr *= 3;
      yr *= 3;
      pushmatrix();
      rotate(xr, 'x');
      rotate(yr, 'y');
      piston(H);
      popmatrix();
      if (dodouble)
        swapbuffers();
      if (qtest()) {
        itest = qread(&idata);
        itest = qread(&idata);
        if (itest == 'B') {
          dobackface = !dobackface;
          backface(dobackface);
        } else if (itest == 'F') {
          dofill = !dofill;
          if (dofill)
            polymode(1);
          else
            polymode(0);
        } else if (itest == 'Q' || itest == '\033') {
          gexit();
          exit(0);
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xd9f(%rip),%rdi
call   1120 <vinit@plt>
lea    0xd99(%rip),%rdi
call   10e0 <winopen@plt>
lea    -0x86(%rbp),%rdi
call   1180 <qread@plt>
cmp    $0x105,%eax
je     12c6 <main+0x46>
jmp    12aa <main+0x2a>
mov    $0x0,%al
call   1140 <doublebuffer@plt>
mov    $0x0,%al
call   1160 <gconfig@plt>
mov    $0x106,%edi
call   10c0 <unqdevice@plt>
mov    $0x51,%edi
call   1060 <qdevice@plt>
mov    $0x46,%edi
call   1060 <qdevice@plt>
mov    $0x42,%edi
call   1060 <qdevice@plt>
mov    $0x1b,%edi
call   1060 <qdevice@plt>
mov    $0x105,%edi
call   1060 <qdevice@plt>
mov    $0x0,%al
call   10d0 <makecyl@plt>
mov    $0x1,%edi
call   10b0 <polymode@plt>
mov    $0x1,%edi
call   1030 <backface@plt>
mov    $0x190,%edi
movsd  0xcd0(%rip),%xmm0
movsd  0xcd0(%rip),%xmm1
movsd  0xcd0(%rip),%xmm2
call   1090 <perspective@plt>
xorps  %xmm4,%xmm4
movsd  0xca8(%rip),%xmm1
mov    $0x4,%edi
xor    %esi,%esi
movaps %xmm4,%xmm0
movaps %xmm4,%xmm2
movaps %xmm4,%xmm3
call   1080 <lookat@plt>
movl   $0x0,-0x90(%rbp)
movl   $0x0,-0x8c(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x168,-0x8(%rbp)
jge    1577 <main+0x2f7>
xor    %edi,%edi
call   1100 <color@plt>
mov    $0x0,%al
call   1190 <clear@plt>
mov    $0x1,%edi
call   1100 <color@plt>
cvtsi2sdl -0x8(%rbp),%xmm1
movsd  0xc76(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xc62(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1130 <cos@plt>
cvtss2sd %xmm0,%xmm1
movsd  0xc45(%rip),%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x84(%rbp)
ff
mov    $0x2,%edi
call   10a0 <getvaluator@plt>
mov    %eax,%ecx
mov    $0x1f4,%eax
sub    %ecx,%eax
mov    %eax,-0x90(%rbp)
mov    $0x1,%edi
call   10a0 <getvaluator@plt>
mov    %eax,%ecx
mov    $0x1f4,%eax
sub    %ecx,%eax
mov    %eax,-0x8c(%rbp)
mov    $0x2,%edi
call   10a0 <getvaluator@plt>
mov    %eax,%ecx
mov    $0x1f4,%eax
sub    %ecx,%eax
mov    %eax,-0x90(%rbp)
imul   $0x3,-0x8c(%rbp),%eax
mov    %eax,-0x8c(%rbp)
imul   $0x3,-0x90(%rbp),%eax
mov    %eax,-0x90(%rbp)
mov    $0x0,%al
call   11a0 <pushmatrix@plt>
mov    -0x8c(%rbp),%edi
mov    $0x78,%esi
call   10f0 <rotate@plt>
mov    -0x90(%rbp),%edi
mov    $0x79,%esi
call   10f0 <rotate@plt>
movss  -0x84(%rbp),%xmm0
ff
call   1150 <piston@plt>
mov    $0x0,%al
call   1040 <popmatrix@plt>
cmpl   $0x0,-0x18(%rbp)
je     149c <main+0x21c>
mov    $0x0,%al
call   1110 <swapbuffers@plt>
mov    $0x0,%al
call   1050 <qtest@plt>
cmp    $0x0,%rax
je     1564 <main+0x2e4>
lea    -0x86(%rbp),%rdi
call   1180 <qread@plt>
mov    %eax,-0xc(%rbp)
lea    -0x86(%rbp),%rdi
call   1180 <qread@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x42,-0xc(%rbp)
jne    14f3 <main+0x273>
cmpl   $0x0,-0x10(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <backface@plt>
jmp    155f <main+0x2df>
cmpl   $0x46,-0xc(%rbp)
jne    1533 <main+0x2b3>
cmpl   $0x0,-0x14(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1527 <main+0x2a7>
mov    $0x1,%edi
call   10b0 <polymode@plt>
jmp    152e <main+0x2ae>
xor    %edi,%edi
call   10b0 <polymode@plt>
jmp    155a <main+0x2da>
cmpl   $0x51,-0xc(%rbp)
je     1547 <main+0x2c7>
cmpl   $0x1b,-0xc(%rbp)
jne    1555 <main+0x2d5>
mov    $0x0,%al
call   1070 <gexit@plt>
xor    %edi,%edi
call   1170 <exit@plt>
jmp    155a <main+0x2da>
jmp    155f <main+0x2df>
jmp    1564 <main+0x2e4>
jmp    1569 <main+0x2e9>
mov    -0x8(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x8(%rbp)
jmp    1388 <main+0x108>
jmp    1381 <main+0x101>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xdb2(%rip),%rdi
call   1110 <vinit@plt>
lea    0xdac(%rip),%rdi
call   10e0 <winopen@plt>
lea    0x2(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1170 <qread@plt>
cmp    $0x105,%eax
jne    12a0 <main+0x30>
xor    %eax,%eax
call   1130 <doublebuffer@plt>
xor    %eax,%eax
call   1150 <gconfig@plt>
mov    $0x106,%edi
call   10c0 <unqdevice@plt>
mov    $0x51,%edi
call   1060 <qdevice@plt>
mov    $0x46,%edi
call   1060 <qdevice@plt>
mov    $0x42,%edi
call   1060 <qdevice@plt>
mov    $0x1b,%edi
call   1060 <qdevice@plt>
mov    $0x105,%edi
call   1060 <qdevice@plt>
xor    %eax,%eax
call   10d0 <makecyl@plt>
mov    $0x1,%edi
call   10b0 <polymode@plt>
mov    $0x1,%edi
call   1030 <backface@plt>
movsd  0xce4(%rip),%xmm0
movsd  0xce4(%rip),%xmm1
movsd  0xce4(%rip),%xmm2
mov    $0x190,%edi
call   1090 <perspective@plt>
movsd  0xcda(%rip),%xmm1
xorps  %xmm0,%xmm0
xorps  %xmm2,%xmm2
xorps  %xmm3,%xmm3
xorps  %xmm4,%xmm4
mov    $0x4,%edi
xor    %esi,%esi
call   1080 <lookat@plt>
lea    0x2(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    $0xfffffffb,%r15d
jmp    1394 <main+0x124>
nopl   0x0(%rax,%rax,1)
cmp    $0x42,%eax
jne    1486 <main+0x216>
xor    %ebx,%ebx
test   %r13d,%r13d
sete   %bl
mov    %ebx,%edi
call   1030 <backface@plt>
mov    %ebx,%r13d
cmp    $0x163,%r15d
jae    1360 <main+0xf0>
add    $0x5,%r15d
xor    %edi,%edi
call   1100 <color@plt>
xor    %eax,%eax
call   1180 <clear@plt>
mov    $0x1,%edi
call   1100 <color@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
mulsd  0xc60(%rip),%xmm0
divsd  0xc60(%rip),%xmm0
call   1120 <cos@plt>
addss  0xc5b(%rip),%xmm0
movss  %xmm0,0x4(%rsp)
mov    $0x2,%edi
call   10a0 <getvaluator@plt>
mov    $0x1,%edi
call   10a0 <getvaluator@plt>
mov    $0x1f4,%ebx
sub    %eax,%ebx
mov    $0x2,%edi
call   10a0 <getvaluator@plt>
mov    $0x1f4,%ecx
sub    %eax,%ecx
lea    (%rbx,%rbx,2),%ebp
lea    (%rcx,%rcx,2),%ebx
xor    %eax,%eax
call   1190 <pushmatrix@plt>
mov    %ebp,%edi
mov    $0x78,%esi
call   10f0 <rotate@plt>
mov    %ebx,%edi
mov    $0x79,%esi
call   10f0 <rotate@plt>
movss  0x4(%rsp),%xmm0
call   1140 <piston@plt>
xor    %eax,%eax
call   1040 <popmatrix@plt>
xor    %eax,%eax
call   1050 <qtest@plt>
test   %rax,%rax
je     138b <main+0x11b>
mov    %r14,%rdi
call   1170 <qread@plt>
mov    %r14,%rdi
call   1170 <qread@plt>
cmp    $0x45,%eax
jle    1370 <main+0x100>
cmp    $0x46,%eax
jne    1491 <main+0x221>
test   %r12d,%r12d
jne    149c <main+0x22c>
mov    $0x1,%r12d
mov    $0x1,%edi
call   10b0 <polymode@plt>
jmp    138b <main+0x11b>
cmp    $0x1b,%eax
jne    138b <main+0x11b>
jmp    14ab <main+0x23b>
cmp    $0x51,%eax
jne    138b <main+0x11b>
jmp    14ab <main+0x23b>
xor    %r12d,%r12d
xor    %edi,%edi
call   10b0 <polymode@plt>
jmp    138b <main+0x11b>
xor    %eax,%eax
call   1070 <gexit@plt>
xor    %edi,%edi
call   1160 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"mswin\00"
@.str.1 = [7 x i8] c"piston\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [100 x i8]
%8 = alloca float
%9 = alloca i16
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %1
%12 = call i32 @vinit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @winopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %17, %0
%15 = call i32 @qread(i16* %9)
%16 = icmp ne i32 %15, 261
br i1 %16, label %17, label %18
17: ; preds = %14
br label %14
18: ; preds = %14
%19 = call i32 (...) @doublebuffer()
%20 = call i32 (...) @gconfig()
%21 = call i32 @unqdevice(i32 262)
%22 = call i32 @qdevice(i32 81)
%23 = call i32 @qdevice(i32 70)
%24 = call i32 @qdevice(i32 66)
%25 = call i32 @qdevice(i32 27)
%26 = call i32 @qdevice(i32 261)
%27 = call i32 (...) @makecyl()
%28 = call i32 @polymode(i32 1)
%29 = call i32 @backface(i32 1)
%30 = call i32 @perspective(i32 400, double 1.500000e+00, double 1.000000e-01, double 6.000000e+02)
%31 = call i32 @lookat(double 0.000000e+00, double -6.000000e+00, i32 4, double 0.000000e+00, double 0.000000e+00, double 0.000000e+00, i32 0)
store i32 0, i32* %11
store i32 0, i32* %10
br label %32
32: ; preds = %18, %119
store i32 0, i32* %2
br label %33
33: ; preds = %116, %32
%34 = load i32, i32* %2
%35 = icmp slt i32 %34, 360
br i1 %35, label %36, label %119
36: ; preds = %33
%37 = call i32 @color(i32 0)
%38 = call i32 (...) @clear()
%39 = call i32 @color(i32 1)
%40 = load i32, i32* %2
%41 = sitofp i32 %40 to double
%42 = fmul double 0x401921FB53C8D4F1, %41
%43 = fdiv double %42, 1.800000e+02
%44 = call float @cos(double %43)
%45 = fpext float %44 to double
%46 = fadd double 1.000000e+00, %45
%47 = fptrunc double %46 to float
store float %47, float* %8
%48 = call i64 @getvaluator(i32 2)
%49 = trunc i64 %48 to i32
%50 = sub nsw i32 500, %49
store i32 %50, i32* %11
%51 = call i64 @getvaluator(i32 1)
%52 = trunc i64 %51 to i32
%53 = sub nsw i32 500, %52
store i32 %53, i32* %10
%54 = call i64 @getvaluator(i32 2)
%55 = trunc i64 %54 to i32
%56 = sub nsw i32 500, %55
store i32 %56, i32* %11
%57 = load i32, i32* %10
%58 = mul nsw i32 %57, 3
store i32 %58, i32* %10
%59 = load i32, i32* %11
%60 = mul nsw i32 %59, 3
store i32 %60, i32* %11
%61 = call i32 (...) @pushmatrix()
%62 = load i32, i32* %10
%63 = call i32 @rotate(i32 %62, i8 signext 120)
%64 = load i32, i32* %11
%65 = call i32 @rotate(i32 %64, i8 signext 121)
%66 = load float, float* %8
%67 = call i32 @piston(float %66)
%68 = call i32 (...) @popmatrix()
%69 = load i32, i32* %6
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %36
%72 = call i32 (...) @swapbuffers()
br label %73
73: ; preds = %71, %36
%74 = call i64 (...) @qtest()
%75 = icmp ne i64 %74, 0
br i1 %75, label %76, label %115
76: ; preds = %73
%77 = call i32 @qread(i16* %9)
store i32 %77, i32* %3
%78 = call i32 @qread(i16* %9)
store i32 %78, i32* %3
%79 = load i32, i32* %3
%80 = icmp eq i32 %79, 66
br i1 %80, label %81, label %88
81: ; preds = %76
%82 = load i32, i32* %4
%83 = icmp ne i32 %82, 0
%84 = xor i1 %83, true
%85 = zext i1 %84 to i32
store i32 %85, i32* %4
%86 = load i32, i32* %4
%87 = call i32 @backface(i32 %86)
br label %114
88: ; preds = %76
%89 = load i32, i32* %3
%90 = icmp eq i32 %89, 70
br i1 %90, label %91, label %103
91: ; preds = %88
%92 = load i32, i32* %5
%93 = icmp ne i32 %92, 0
%94 = xor i1 %93, true
%95 = zext i1 %94 to i32
store i32 %95, i32* %5
%96 = load i32, i32* %5
%97 = icmp ne i32 %96, 0
br i1 %97, label %98, label %100
98: ; preds = %91
%99 = call i32 @polymode(i32 1)
br label %102
100: ; preds = %91
%101 = call i32 @polymode(i32 0)
br label %102
102: ; preds = %100, %98
br label %113
103: ; preds = %88
%104 = load i32, i32* %3
%105 = icmp eq i32 %104, 81
br i1 %105, label %109, label %106
106: ; preds = %103
%107 = load i32, i32* %3
%108 = icmp eq i32 %107, 27
br i1 %108, label %109, label %112
109: ; preds = %106, %103
%110 = call i32 (...) @gexit()
%111 = call i32 @exit(i32 0)
unreachable
112: ; preds = %106
br label %113
113: ; preds = %112, %102
br label %114
114: ; preds = %113, %81
br label %115
115: ; preds = %114, %73
br label %116
116: ; preds = %115
%117 = load i32, i32* %2
%118 = add nsw i32 %117, 5
store i32 %118, i32* %2
br label %33
119: ; preds = %33
br label %32
}

LLVM IR (-O2):
@.str = [6 x i8] c"mswin\00"
@.str.1 = [7 x i8] c"piston\00"
define i32 @main() {
%1 = alloca i16
%2 = bitcast i16* %1 to i8*
%3 = tail call i32 @vinit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @winopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %5
5: ; preds = %5, %0
%6 = call i32 @qread(i16* %1)
%7 = icmp eq i32 %6, 261
br i1 %7, label %8, label %5
8: ; preds = %5
%9 = call i32 (...) @doublebuffer()
%10 = call i32 (...) @gconfig()
%11 = call i32 @unqdevice(i32 262)
%12 = call i32 @qdevice(i32 81)
%13 = call i32 @qdevice(i32 70)
%14 = call i32 @qdevice(i32 66)
%15 = call i32 @qdevice(i32 27)
%16 = call i32 @qdevice(i32 261)
%17 = call i32 (...) @makecyl()
%18 = call i32 @polymode(i32 1)
%19 = call i32 @backface(i32 1)
%20 = call i32 @perspective(i32 400, double 1.500000e+00, double 1.000000e-01, double 6.000000e+02)
%21 = call i32 @lookat(double 0.000000e+00, double -6.000000e+00, i32 4, double 0.000000e+00, double 0.000000e+00, double 0.000000e+00, i32 0)
br label %22
22: ; preds = %69, %8
%23 = phi i32 [ undef, %8 ], [ %70, %69 ]
%24 = phi i32 [ undef, %8 ], [ %71, %69 ]
br label %25
25: ; preds = %22, %69
%26 = phi i32 [ 0, %22 ], [ %72, %69 ]
%27 = phi i32 [ %24, %22 ], [ %71, %69 ]
%28 = phi i32 [ %23, %22 ], [ %70, %69 ]
%29 = call i32 @color(i32 0)
%30 = call i32 (...) @clear()
%31 = call i32 @color(i32 1)
%32 = sitofp i32 %26 to double
%33 = fmul double %32, 0x401921FB53C8D4F1
%34 = fdiv double %33, 1.800000e+02
%35 = call float @cos(double %34)
%36 = fadd float %35, 1.000000e+00
%37 = call i64 @getvaluator(i32 2)
%38 = call i64 @getvaluator(i32 1)
%39 = trunc i64 %38 to i32
%40 = sub nsw i32 500, %39
%41 = call i64 @getvaluator(i32 2)
%42 = trunc i64 %41 to i32
%43 = sub nsw i32 500, %42
%44 = mul nsw i32 %40, 3
%45 = mul nsw i32 %43, 3
%46 = call i32 (...) @pushmatrix()
%47 = call i32 @rotate(i32 %44, i8 signext 120)
%48 = call i32 @rotate(i32 %45, i8 signext 121)
%49 = call i32 @piston(float %36)
%50 = call i32 (...) @popmatrix()
%51 = call i64 (...) @qtest()
%52 = icmp eq i64 %51, 0
br i1 %52, label %69, label %53
53: ; preds = %25
%54 = call i32 @qread(i16* %1)
%55 = call i32 @qread(i16* %1)
switch i32 %55, label %69 [
i32 66, label %56
i32 70, label %60
i32 81, label %66
i32 27, label %66
]
56: ; preds = %53
%57 = icmp eq i32 %27, 0
%58 = zext i1 %57 to i32
%59 = call i32 @backface(i32 %58)
br label %69
60: ; preds = %53
%61 = icmp eq i32 %28, 0
br i1 %61, label %62, label %64
62: ; preds = %60
%63 = call i32 @polymode(i32 1)
br label %69
64: ; preds = %60
%65 = call i32 @polymode(i32 0)
br label %69
66: ; preds = %53, %53
%67 = call i32 (...) @gexit()
%68 = call i32 @exit(i32 0)
unreachable
69: ; preds = %53, %25, %64, %62, %56
%70 = phi i32 [ %28, %56 ], [ 1, %62 ], [ 0, %64 ], [ %28, %25 ], [ %28, %53 ]
%71 = phi i32 [ %58, %56 ], [ %27, %62 ], [ %27, %64 ], [ %27, %25 ], [ %27, %53 ]
%72 = add nuw nsw i32 %26, 5
%73 = icmp ult i32 %26, 355
br i1 %73, label %25, label %22
}