#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 atan(float);
float sqrt(float);
short adxl345_convert_angle(short x, short y, short z, short *ax, short *ay,
                            short *az) {
  float temp;
  float fx, fy, fz;
  fx = (float)x;
  fy = (float)y;
  fz = (float)z;
  temp = sqrt((fx * fx + fy * fy)) / fz;
  *az = (short)(atan(temp) * 1800 / 3.14);
  temp = fx / sqrt((fy * fy + fz * fz));
  *ax = (short)(atan(temp) * 1800 / 3.14);
  temp = fy / sqrt((fx * fx + fz * fz));
  *ay = (short)(atan(temp) * 1800 / 3.14);
  return 0;
}


x86 assembly (clang, -O0):
<adxl345_convert_angle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dx,%ax
mov    %si,%dx
mov    %di,%si
mov    %si,-0x2(%rbp)
mov    %dx,-0x4(%rbp)
mov    %ax,-0x6(%rbp)
mov    %rcx,-0x10(%rbp)
mov    %r8,-0x18(%rbp)
mov    %r9,-0x20(%rbp)
movswl -0x2(%rbp),%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x28(%rbp)
movswl -0x4(%rbp),%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x2c(%rbp)
movswl -0x6(%rbp),%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x28(%rbp),%xmm0
movss  -0x2c(%rbp),%xmm1
mulss  %xmm1,%xmm1
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
call   1040 <sqrt@plt>
movss  -0x30(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
call   1030 <atan@plt>
imul   $0x708,%eax,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe4b(%rip),%xmm1
movsd  %xmm1,-0x38(%rbp)
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,%cx
mov    -0x20(%rbp),%rax
mov    %cx,(%rax)
movss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x40(%rbp)
movss  -0x2c(%rbp),%xmm0
movss  -0x30(%rbp),%xmm1
mulss  %xmm1,%xmm1
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movss  -0x40(%rbp),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
call   1030 <atan@plt>
movsd  -0x38(%rbp),%xmm1
imul   $0x708,%eax,%eax
cvtsi2sd %eax,%xmm0
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
movss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x28(%rbp),%xmm0
movss  -0x30(%rbp),%xmm1
mulss  %xmm1,%xmm1
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movss  -0x3c(%rbp),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
call   1030 <atan@plt>
movsd  -0x38(%rbp),%xmm1
imul   $0x708,%eax,%eax
cvtsi2sd %eax,%xmm0
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,%cx
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
xor    %eax,%eax
cwtl
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adxl345_convert_angle>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
cvtsi2ss %edi,%xmm2
cvtsi2ss %esi,%xmm0
cvtsi2ss %edx,%xmm1
movss  %xmm1,0xc(%rsp)
mov    %r9,%rbx
mov    %r8,%r14
mov    %rcx,%r15
movss  %xmm0,0x1c(%rsp)
movaps %xmm0,%xmm3
mulss  %xmm0,%xmm3
movss  %xmm2,0x14(%rsp)
movaps %xmm2,%xmm1
mulss  %xmm2,%xmm1
movaps %xmm1,%xmm0
movss  %xmm3,0x10(%rsp)
addss  %xmm3,%xmm0
xorps  %xmm2,%xmm2
ucomiss %xmm2,%xmm0
movss  %xmm1,0x18(%rsp)
jb     117f <adxl345_convert_angle+0x5f>
sqrtss %xmm0,%xmm0
jmp    1184 <adxl345_convert_angle+0x64>
call   1040 <sqrt@plt>
divss  0xc(%rsp),%xmm0
call   1030 <atan@plt>
imul   $0x708,%eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xe5c(%rip),%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,(%rbx)
movss  0xc(%rsp),%xmm1
mulss  %xmm1,%xmm1
movss  %xmm1,0xc(%rsp)
movss  0x10(%rsp),%xmm0
addss  %xmm1,%xmm0
ucomiss 0xe3c(%rip),%xmm0
jb     11d4 <adxl345_convert_angle+0xb4>
sqrtss %xmm0,%xmm0
jmp    11d9 <adxl345_convert_angle+0xb9>
call   1040 <sqrt@plt>
movss  0x14(%rsp),%xmm1
divss  %xmm0,%xmm1
movaps %xmm1,%xmm0
call   1030 <atan@plt>
imul   $0x708,%eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xe00(%rip),%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,(%r15)
movss  0x18(%rsp),%xmm0
addss  0xc(%rsp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     1222 <adxl345_convert_angle+0x102>
sqrtss %xmm0,%xmm0
jmp    1227 <adxl345_convert_angle+0x107>
call   1040 <sqrt@plt>
movss  0x1c(%rsp),%xmm1
divss  %xmm0,%xmm1
movaps %xmm1,%xmm0
call   1030 <atan@plt>
imul   $0x708,%eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xdb2(%rip),%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,(%r14)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define signext i16 @adxl345_convert_angle(i16 signext %0, i16 signext %1, i16 signext %2, i16* %3, i16* %4, i16* %5) {
%7 = alloca i16
%8 = alloca i16
%9 = alloca i16
%10 = alloca i16*
%11 = alloca i16*
%12 = alloca i16*
%13 = alloca float
%14 = alloca float
%15 = alloca float
%16 = alloca float
store i16 %0, i16* %7
store i16 %1, i16* %8
store i16 %2, i16* %9
store i16* %3, i16** %10
store i16* %4, i16** %11
store i16* %5, i16** %12
%17 = load i16, i16* %7
%18 = sitofp i16 %17 to float
store float %18, float* %14
%19 = load i16, i16* %8
%20 = sitofp i16 %19 to float
store float %20, float* %15
%21 = load i16, i16* %9
%22 = sitofp i16 %21 to float
store float %22, float* %16
%23 = load float, float* %14
%24 = load float, float* %14
%25 = load float, float* %15
%26 = load float, float* %15
%27 = fmul float %25, %26
%28 = call float @llvm.fmuladd.f32(float %23, float %24, float %27)
%29 = call float @sqrt(float %28)
%30 = load float, float* %16
%31 = fdiv float %29, %30
store float %31, float* %13
%32 = load float, float* %13
%33 = call i32 @atan(float %32)
%34 = mul nsw i32 %33, 1800
%35 = sitofp i32 %34 to double
%36 = fdiv double %35, 3.140000e+00
%37 = fptosi double %36 to i16
%38 = load i16*, i16** %12
store i16 %37, i16* %38
%39 = load float, float* %14
%40 = load float, float* %15
%41 = load float, float* %15
%42 = load float, float* %16
%43 = load float, float* %16
%44 = fmul float %42, %43
%45 = call float @llvm.fmuladd.f32(float %40, float %41, float %44)
%46 = call float @sqrt(float %45)
%47 = fdiv float %39, %46
store float %47, float* %13
%48 = load float, float* %13
%49 = call i32 @atan(float %48)
%50 = mul nsw i32 %49, 1800
%51 = sitofp i32 %50 to double
%52 = fdiv double %51, 3.140000e+00
%53 = fptosi double %52 to i16
%54 = load i16*, i16** %10
store i16 %53, i16* %54
%55 = load float, float* %15
%56 = load float, float* %14
%57 = load float, float* %14
%58 = load float, float* %16
%59 = load float, float* %16
%60 = fmul float %58, %59
%61 = call float @llvm.fmuladd.f32(float %56, float %57, float %60)
%62 = call float @sqrt(float %61)
%63 = fdiv float %55, %62
store float %63, float* %13
%64 = load float, float* %13
%65 = call i32 @atan(float %64)
%66 = mul nsw i32 %65, 1800
%67 = sitofp i32 %66 to double
%68 = fdiv double %67, 3.140000e+00
%69 = fptosi double %68 to i16
%70 = load i16*, i16** %11
store i16 %69, i16* %70
ret i16 0
}

LLVM IR (-O2):
define signext i16 @adxl345_convert_angle(i16 signext %0, i16 signext %1, i16 signext %2, i16* nocapture writeonly %3, i16* nocapture writeonly %4, i16* nocapture writeonly %5) {
%7 = sitofp i16 %0 to float
%8 = sitofp i16 %1 to float
%9 = sitofp i16 %2 to float
%10 = fmul float %8, %8
%11 = tail call float @llvm.fmuladd.f32(float %7, float %7, float %10)
%12 = tail call float @sqrt(float %11)
%13 = fdiv float %12, %9
%14 = tail call i32 @atan(float %13)
%15 = mul nsw i32 %14, 1800
%16 = sitofp i32 %15 to double
%17 = fdiv double %16, 3.140000e+00
%18 = fptosi double %17 to i16
store i16 %18, i16* %5
%19 = fmul float %9, %9
%20 = tail call float @llvm.fmuladd.f32(float %8, float %8, float %19)
%21 = tail call float @sqrt(float %20)
%22 = fdiv float %7, %21
%23 = tail call i32 @atan(float %22)
%24 = mul nsw i32 %23, 1800
%25 = sitofp i32 %24 to double
%26 = fdiv double %25, 3.140000e+00
%27 = fptosi double %26 to i16
store i16 %27, i16* %3
%28 = tail call float @llvm.fmuladd.f32(float %7, float %7, float %19)
%29 = tail call float @sqrt(float %28)
%30 = fdiv float %8, %29
%31 = tail call i32 @atan(float %30)
%32 = mul nsw i32 %31, 1800
%33 = sitofp i32 %32 to double
%34 = fdiv double %33, 3.140000e+00
%35 = fptosi double %34 to i16
store i16 %35, i16* %4
ret i16 0
}