#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 */
long inv_fast_sqrt(long);
long inv_q30_mult(long const, long const);
int inv_compute_scalar_part(const long *inQuat, long *outQuat) {
  long scalarPart = 0;
  scalarPart = inv_fast_sqrt((1L << 30) - inv_q30_mult(inQuat[0], inQuat[0]) -
                             inv_q30_mult(inQuat[1], inQuat[1]) -
                             inv_q30_mult(inQuat[2], inQuat[2]));
  outQuat[0] = scalarPart;
  outQuat[1] = inQuat[0];
  outQuat[2] = inQuat[1];
  outQuat[3] = inQuat[2];
  return 0;
}


x86 assembly (clang, -O0):
<inv_compute_scalar_part>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
call   1030 <inv_q30_mult@plt>
mov    %rax,%rcx
mov    $0x40000000,%eax
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <inv_q30_mult@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rsi
call   1030 <inv_q30_mult@plt>
mov    -0x20(%rbp),%rdi
sub    %rax,%rdi
call   1040 <inv_fast_sqrt@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x18(%rax)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inv_compute_scalar_part>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
mov    (%rdi),%rdi
mov    %rdi,%rsi
call   1030 <inv_q30_mult@plt>
mov    %rax,%r15
mov    0x8(%r12),%rdi
mov    %rdi,%rsi
call   1030 <inv_q30_mult@plt>
mov    %rax,%rbx
mov    0x10(%r12),%rdi
mov    %rdi,%rsi
call   1030 <inv_q30_mult@plt>
add    %r15,%rbx
add    %rax,%rbx
mov    $0x40000000,%edi
sub    %rbx,%rdi
call   1040 <inv_fast_sqrt@plt>
mov    %rax,(%r14)
mov    (%r12),%rax
mov    %rax,0x8(%r14)
mov    0x8(%r12),%rax
mov    %rax,0x10(%r14)
mov    0x10(%r12),%rax
mov    %rax,0x18(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @inv_compute_scalar_part(i64* %0, i64* %1) {
%3 = alloca i64*
%4 = alloca i64*
%5 = alloca i64
store i64* %0, i64** %3
store i64* %1, i64** %4
store i64 0, i64* %5
%6 = load i64*, i64** %3
%7 = getelementptr inbounds i64, i64* %6, i64 0
%8 = load i64, i64* %7
%9 = load i64*, i64** %3
%10 = getelementptr inbounds i64, i64* %9, i64 0
%11 = load i64, i64* %10
%12 = call i64 @inv_q30_mult(i64 %8, i64 %11)
%13 = sub nsw i64 1073741824, %12
%14 = load i64*, i64** %3
%15 = getelementptr inbounds i64, i64* %14, i64 1
%16 = load i64, i64* %15
%17 = load i64*, i64** %3
%18 = getelementptr inbounds i64, i64* %17, i64 1
%19 = load i64, i64* %18
%20 = call i64 @inv_q30_mult(i64 %16, i64 %19)
%21 = sub nsw i64 %13, %20
%22 = load i64*, i64** %3
%23 = getelementptr inbounds i64, i64* %22, i64 2
%24 = load i64, i64* %23
%25 = load i64*, i64** %3
%26 = getelementptr inbounds i64, i64* %25, i64 2
%27 = load i64, i64* %26
%28 = call i64 @inv_q30_mult(i64 %24, i64 %27)
%29 = sub nsw i64 %21, %28
%30 = call i64 @inv_fast_sqrt(i64 %29)
store i64 %30, i64* %5
%31 = load i64, i64* %5
%32 = load i64*, i64** %4
%33 = getelementptr inbounds i64, i64* %32, i64 0
store i64 %31, i64* %33
%34 = load i64*, i64** %3
%35 = getelementptr inbounds i64, i64* %34, i64 0
%36 = load i64, i64* %35
%37 = load i64*, i64** %4
%38 = getelementptr inbounds i64, i64* %37, i64 1
store i64 %36, i64* %38
%39 = load i64*, i64** %3
%40 = getelementptr inbounds i64, i64* %39, i64 1
%41 = load i64, i64* %40
%42 = load i64*, i64** %4
%43 = getelementptr inbounds i64, i64* %42, i64 2
store i64 %41, i64* %43
%44 = load i64*, i64** %3
%45 = getelementptr inbounds i64, i64* %44, i64 2
%46 = load i64, i64* %45
%47 = load i64*, i64** %4
%48 = getelementptr inbounds i64, i64* %47, i64 3
store i64 %46, i64* %48
ret i32 0
}

LLVM IR (-O2):
define i32 @inv_compute_scalar_part(i64* nocapture %0, i64* nocapture writeonly %1) {
%3 = load i64, i64* %0
%4 = tail call i64 @inv_q30_mult(i64 %3, i64 %3)
%5 = getelementptr inbounds i64, i64* %0, i64 1
%6 = load i64, i64* %5
%7 = tail call i64 @inv_q30_mult(i64 %6, i64 %6)
%8 = getelementptr inbounds i64, i64* %0, i64 2
%9 = load i64, i64* %8
%10 = tail call i64 @inv_q30_mult(i64 %9, i64 %9)
%11 = add i64 %4, %7
%12 = add i64 %11, %10
%13 = sub i64 1073741824, %12
%14 = tail call i64 @inv_fast_sqrt(i64 %13)
store i64 %14, i64* %1
%15 = load i64, i64* %0
%16 = getelementptr inbounds i64, i64* %1, i64 1
store i64 %15, i64* %16
%17 = load i64, i64* %5
%18 = getelementptr inbounds i64, i64* %1, i64 2
store i64 %17, i64* %18
%19 = load i64, i64* %8
%20 = getelementptr inbounds i64, i64* %1, i64 3
store i64 %19, i64* %20
ret i32 0
}