// File: /workspace/github_c_makefile_star2_O3/jrrk[P]cbzone/c_graphics.c
// Function: joystick
void joystick (position, sens, pl)
     int* position;
     Genericp pl;
     Bool sens;
{
  static float sscale[] = {0.06, 0.03};
  static float rscale[] = {0.00013, 0.000065};
  static int destorigin[] = {845, 550};
  static short stick[8] = {0};
  static Bool first = True;
  static Bool draw = True;
  int ind;
  float scrot, sctot, scale, xl, yl, tl, xoff, yoff;

  if (sens)
    ind = 0;
  else
    ind = 1;
  pl->speed = -(position[1] - 355.0) * sscale[ind];
  pl->rotate = (position[0] - 500.0) * rscale[ind];
  if (fabs(pl->speed) > 10.0)
    pl->speed = sign(10.0, pl->speed);
  if (fabs(pl->rotate) > 0.030)
    pl->rotate = sign(0.030, pl->rotate);
  scrot = pl->rotate * 10.0 / 0.030;
  sctot = sqrt(pl->speed*pl->speed + scrot*scrot);
  if (sctot > 10.0) {
    scale = 10.0 / sctot;
    pl->speed *= scale;
    pl->rotate *= scale;
  }
  if (draw) {
    gprsetclippingactive(False);
    if (!first) {
      gprsetdrawvalue(opt->cpi[COLOR_BG]);
      removepixmap(1, destorigin);
      multiline(stick, 2);
    }
    else
      first = False;
    destorigin[0] =  35.0 * (pl->rotate / 0.03) + 845.0;
    destorigin[1] = -35.0 * (pl->speed  / 10.0)  + 550.0;
    putpixmap(1, destorigin);
    xl = pl->rotate / 0.030;
    yl = pl->speed / 10.0;
    tl = sqrt(xl*xl + yl*yl);
    if (tl > 0.05) {
      yoff = xl / tl * 9.0;
      xoff = yl / tl * 9.0;
    }
    else {
      yoff = 0.0;
      xoff = 0.0;
    }
    stick[0] = stick[4] = 855;
    stick[2] = destorigin[0] + 10 + xoff / 2;
    stick[6] = destorigin[0] + 10 - xoff / 2;
    stick[1] = stick[5] = 560;
    stick[3] = destorigin[1] + 10 + yoff / 2;;
    stick[7] = destorigin[1] + 10 - yoff / 2;
    gprsetdrawvalue(opt->cpi[COLOR_JOYSTICK]);
    multiline(stick, 2);
    gprsetclippingactive(True);
  }
  draw = !draw;
  pl->rotate = -pl->rotate;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
xorl %eax, %eax
testl %esi, %esi
sete %al
cvtsi2sdl 0x4(%rdi), %xmm0
addsd 0x63df(%rip), %xmm0     # 0xe5c8
xorpd 0x644f(%rip), %xmm0     # 0xe640
shll $0x2, %eax
leaq 0x643d(%rip), %rcx      # 0xe638
movss (%rax,%rcx), %xmm1
leaq 0x6429(%rip), %rcx      # 0xe630
movss (%rax,%rcx), %xmm2
unpcklps %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
xorps %xmm1, %xmm1
cvtsi2sdl (%rdi), %xmm1
addsd 0x63b2(%rip), %xmm1     # 0xe5d0
cvtps2pd %xmm2, %xmm2
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
mulpd %xmm0, %xmm2
cvtpd2ps %xmm2, %xmm0
movq %rdx, %rbx
movlpd %xmm0, 0x2c(%rdx)
movapd 0x5e13(%rip), %xmm1     # 0xe050
andpd %xmm0, %xmm1
ucomiss 0x5dbc(%rip), %xmm1     # 0xe004
movapd %xmm0, %xmm1
jbe 0x826b
xorpd %xmm1, %xmm1
xorl %eax, %eax
ucomiss %xmm0, %xmm1
seta %al
leaq 0x6377(%rip), %rcx      # 0xe5d8
movss (%rcx,%rax,4), %xmm1
movss %xmm1, 0x2c(%rbx)
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movaps %xmm0, %xmm2
andps 0x5dd7(%rip), %xmm2     # 0xe050
cvtss2sd %xmm2, %xmm2
ucomisd 0x635b(%rip), %xmm2     # 0xe5e0
jbe 0x82a3
xorps %xmm2, %xmm2
xorl %eax, %eax
ucomiss %xmm0, %xmm2
seta %al
leaq 0x634f(%rip), %rcx      # 0xe5e8
movss (%rcx,%rax,4), %xmm0
movss %xmm0, 0x30(%rbx)
xorps %xmm2, %xmm2
cvtss2sd %xmm0, %xmm2
mulsd 0x633e(%rip), %xmm2     # 0xe5f0
divsd 0x6326(%rip), %xmm2     # 0xe5e0
cvtsd2ss %xmm2, %xmm2
mulss %xmm2, %xmm2
movapd %xmm1, %xmm3
mulss %xmm1, %xmm3
addss %xmm2, %xmm3
xorps %xmm2, %xmm2
sqrtss %xmm3, %xmm2
ucomiss 0x5d28(%rip), %xmm2     # 0xe004
jbe 0x82fc
movss 0x5d1e(%rip), %xmm3     # 0xe004
divss %xmm2, %xmm3
mulss %xmm3, %xmm1
movss %xmm1, 0x2c(%rbx)
mulss %xmm3, %xmm0
movss %xmm0, 0x30(%rbx)
cmpl $0x0, 0xc07d(%rip)      # 0x14380
je 0x8356
xorl %edi, %edi
xorl %eax, %eax
callq 0x7212
cmpb $0x1, 0xc46b(%rip)      # 0x14780
jne 0x8360
leaq 0xc262(%rip), %rax      # 0x14580
movq (%rax), %rax
movl 0xf0(%rax), %edi
xorl %eax, %eax
callq 0x7660
leaq 0xc043(%rip), %rsi      # 0x14378
movl $0x1, %edi
xorl %eax, %eax
callq 0x7a06
leaq 0xc428(%rip), %rdi      # 0x14770
movl $0x2, %esi
xorl %eax, %eax
callq 0x6ed0
jmp 0x8367
movl $0x1, %eax
jmp 0x84a6
movb $0x1, 0xc419(%rip)      # 0x14780
cvtps2pd 0x2c(%rbx), %xmm0
divpd 0x62dd(%rip), %xmm0     # 0xe650
mulpd 0x62e5(%rip), %xmm0     # 0xe660
addpd 0x62ed(%rip), %xmm0     # 0xe670
cvttpd2dq %xmm0, %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, 0xbfe4(%rip)     # 0x14378
leaq 0xbfdd(%rip), %rsi      # 0x14378
movl $0x1, %edi
xorl %eax, %eax
callq 0x7961
xorps %xmm0, %xmm0
cvtss2sd 0x30(%rbx), %xmm0
divsd 0x6229(%rip), %xmm0     # 0xe5e0
xorps %xmm2, %xmm2
cvtsd2ss %xmm0, %xmm2
movss 0x2c(%rbx), %xmm0
divss 0x5c39(%rip), %xmm0     # 0xe004
movaps %xmm0, %xmm1
mulss %xmm0, %xmm1
movaps %xmm2, %xmm3
mulss %xmm2, %xmm3
addss %xmm1, %xmm3
sqrtss %xmm3, %xmm3
cvtss2sd %xmm3, %xmm4
xorps %xmm1, %xmm1
ucomisd 0x6208(%rip), %xmm4     # 0xe5f8
jbe 0x840d
unpcklps %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
shufps $0x0, %xmm3, %xmm3      # xmm3 = xmm3[0,0,0,0]
divps %xmm3, %xmm0
mulps 0x627d(%rip), %xmm0     # 0xe680
mulps 0x6286(%rip), %xmm0     # 0xe690
movaps %xmm0, %xmm1
movl $0x2300357, %eax        # imm = 0x2300357
movl %eax, 0xc360(%rip)      # 0x14778
leaq 0xc351(%rip), %r14      # 0x14770
movl %eax, 0xc34b(%rip)      # 0x14770
movq 0xbf4b(%rip), %xmm0     # 0x14378
paddd 0x626b(%rip), %xmm0     # 0xe6a0
cvtdq2ps %xmm0, %xmm0
movaps %xmm1, %xmm2
addps %xmm0, %xmm2
cvttps2dq %xmm2, %xmm2
pshuflw $0xe8, %xmm2, %xmm2     # xmm2 = xmm2[0,2,2,3,4,5,6,7]
movd %xmm2, 0xc325(%rip)     # 0x14774
subps %xmm1, %xmm0
cvttps2dq %xmm0, %xmm0
pshuflw $0xe8, %xmm0, %xmm0     # xmm0 = xmm0[0,2,2,3,4,5,6,7]
movd %xmm0, 0xc319(%rip)     # 0x1477c
leaq 0xc116(%rip), %rax      # 0x14580
movq (%rax), %rax
movl 0x118(%rax), %edi
xorl %eax, %eax
callq 0x7660
movq %r14, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x6ed0
movl $0x1, %edi
xorl %eax, %eax
callq 0x7212
movss 0x30(%rbx), %xmm0
xorl %eax, %eax
cmpl $0x0, 0xbedd(%rip)      # 0x14380
sete %al
movl %eax, 0xbed4(%rip)      # 0x14380
xorps 0x5b5d(%rip), %xmm0     # 0xe010
movss %xmm0, 0x30(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq