#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 joystickGetAnalog(int, int);
double sqrt(int);
double getJoyPolarSpeed() {
  double tmpSpeed = sqrt((joystickGetAnalog(1, 2) * joystickGetAnalog(1, 2)) +
                         (joystickGetAnalog(1, 1) * joystickGetAnalog(1, 1)));
  tmpSpeed /= 127;
  tmpSpeed = tmpSpeed > 1 ? 1 : tmpSpeed;
  return tmpSpeed;
}


x86 assembly (clang, -O0):
<getJoyPolarSpeed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x1,%edi
mov    $0x2,%esi
call   1030 <joystickGetAnalog@plt>
mov    %eax,-0x14(%rbp)
mov    $0x1,%edi
mov    $0x2,%esi
call   1030 <joystickGetAnalog@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    $0x1,%esi
mov    %esi,%edi
call   1030 <joystickGetAnalog@plt>
mov    %eax,-0xc(%rbp)
mov    $0x1,%esi
mov    %esi,%edi
call   1030 <joystickGetAnalog@plt>
mov    -0x10(%rbp),%edi
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
imul   %ecx,%eax
add    %eax,%edi
call   1040 <sqrt@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe75(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe57(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11c5 <getJoyPolarSpeed+0xa5>
movsd  0xe45(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11cf <getJoyPolarSpeed+0xaf>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getJoyPolarSpeed>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1,%edi
mov    $0x2,%esi
call   1030 <joystickGetAnalog@plt>
mov    %eax,%ebx
mov    $0x1,%edi
mov    $0x2,%esi
call   1030 <joystickGetAnalog@plt>
imul   %eax,%ebx
mov    $0x1,%edi
mov    $0x1,%esi
call   1030 <joystickGetAnalog@plt>
mov    %eax,%ebp
mov    $0x1,%edi
mov    $0x1,%esi
call   1030 <joystickGetAnalog@plt>
imul   %eax,%ebp
add    %ebx,%ebp
mov    %ebp,%edi
call   1040 <sqrt@plt>
divsd  0xe86(%rip),%xmm0
movsd  0xe86(%rip),%xmm1
minsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @getJoyPolarSpeed() {
%1 = alloca double
%2 = call i32 @joystickGetAnalog(i32 1, i32 2)
%3 = call i32 @joystickGetAnalog(i32 1, i32 2)
%4 = mul nsw i32 %2, %3
%5 = call i32 @joystickGetAnalog(i32 1, i32 1)
%6 = call i32 @joystickGetAnalog(i32 1, i32 1)
%7 = mul nsw i32 %5, %6
%8 = add nsw i32 %4, %7
%9 = call double @sqrt(i32 %8)
store double %9, double* %1
%10 = load double, double* %1
%11 = fdiv double %10, 1.270000e+02
store double %11, double* %1
%12 = load double, double* %1
%13 = fcmp ogt double %12, 1.000000e+00
br i1 %13, label %14, label %15
14: ; preds = %0
br label %17
15: ; preds = %0
%16 = load double, double* %1
br label %17
17: ; preds = %15, %14
%18 = phi double [ 1.000000e+00, %14 ], [ %16, %15 ]
store double %18, double* %1
%19 = load double, double* %1
ret double %19
}

LLVM IR (-O2):
define double @getJoyPolarSpeed() {
%1 = tail call i32 @joystickGetAnalog(i32 1, i32 2)
%2 = tail call i32 @joystickGetAnalog(i32 1, i32 2)
%3 = mul nsw i32 %2, %1
%4 = tail call i32 @joystickGetAnalog(i32 1, i32 1)
%5 = tail call i32 @joystickGetAnalog(i32 1, i32 1)
%6 = mul nsw i32 %5, %4
%7 = add nsw i32 %6, %3
%8 = tail call double @sqrt(i32 %7)
%9 = fdiv double %8, 1.270000e+02
%10 = fcmp ogt double %9, 1.000000e+00
%11 = select i1 %10, double 1.000000e+00, double %9
ret double %11
}