#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 */
typedef size_t uint32_t;

/* Variables and functions */
void cross_vector(double a[], double b[], double x[], uint32_t vector_len) {
  uint32_t i = 0;
  for (i = 0; i < vector_len; i++) {
    x[i] = a[(i + 1) % vector_len] * b[(i + 2) % vector_len] -
           a[(i + 2) % vector_len] * b[(i + 1) % vector_len];
  }
}


x86 assembly (clang, -O0):
<cross_vector>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11f3 <cross_vector+0xf3>
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x20(%rbp)
mov    -0x48(%rbp),%rax
movsd  (%rax,%rdx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
add    $0x2,%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x20(%rbp)
mov    -0x40(%rbp),%rax
movsd  (%rax,%rdx,8),%xmm2
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
add    $0x2,%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x20(%rbp)
mov    -0x38(%rbp),%rax
movsd  (%rax,%rdx,8),%xmm1
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x20(%rbp)
mov    -0x30(%rbp),%rax
mulsd  (%rax,%rdx,8),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1124 <cross_vector+0x24>
pop    %rbp
ret

x86 assembly (clang, -O2):
<cross_vector>:
push   %r14
push   %rbx
test   %rcx,%rcx
je     1180 <cross_vector+0x80>
mov    %rdx,%r8
mov    %rcx,%r10
neg    %r10
mov    $0x1,%ebx
xor    %r11d,%r11d
jmp    1154 <cross_vector+0x54>
nopl   0x0(%rax,%rax,1)
mov    %r9,%rax
xor    %edx,%edx
div    %rcx
movsd  (%rsi,%r14,8),%xmm1
mulsd  (%rdi,%rdx,8),%xmm1
mulsd  (%rsi,%rdx,8),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%r8,%rbx,8)
lea    (%r10,%rbx,1),%rax
add    $0x1,%rax
mov    %r9,%rbx
cmp    $0x1,%rax
je     1180 <cross_vector+0x80>
mov    %r10,%rax
add    %rbx,%rax
mov    %rbx,%r14
cmove  %r11,%r14
movsd  (%rdi,%r14,8),%xmm0
lea    0x1(%rbx),%r9
mov    %r9,%rax
or     %rcx,%rax
shr    $0x20,%rax
jne    1120 <cross_vector+0x20>
mov    %r9d,%eax
xor    %edx,%edx
div    %ecx
jmp    1128 <cross_vector+0x28>
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @cross_vector(double* %0, double* %1, double* %2, i64 %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca i64
%9 = alloca i64
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
store i64 %3, i64* %8
store i64 0, i64* %9
store i64 0, i64* %9
br label %10
10: ; preds = %49, %4
%11 = load i64, i64* %9
%12 = load i64, i64* %8
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %52
14: ; preds = %10
%15 = load double*, double** %5
%16 = load i64, i64* %9
%17 = add i64 %16, 1
%18 = load i64, i64* %8
%19 = urem i64 %17, %18
%20 = getelementptr inbounds double, double* %15, i64 %19
%21 = load double, double* %20
%22 = load double*, double** %6
%23 = load i64, i64* %9
%24 = add i64 %23, 2
%25 = load i64, i64* %8
%26 = urem i64 %24, %25
%27 = getelementptr inbounds double, double* %22, i64 %26
%28 = load double, double* %27
%29 = load double*, double** %5
%30 = load i64, i64* %9
%31 = add i64 %30, 2
%32 = load i64, i64* %8
%33 = urem i64 %31, %32
%34 = getelementptr inbounds double, double* %29, i64 %33
%35 = load double, double* %34
%36 = load double*, double** %6
%37 = load i64, i64* %9
%38 = add i64 %37, 1
%39 = load i64, i64* %8
%40 = urem i64 %38, %39
%41 = getelementptr inbounds double, double* %36, i64 %40
%42 = load double, double* %41
%43 = fmul double %35, %42
%44 = fneg double %43
%45 = call double @llvm.fmuladd.f64(double %21, double %28, double %44)
%46 = load double*, double** %7
%47 = load i64, i64* %9
%48 = getelementptr inbounds double, double* %46, i64 %47
store double %45, double* %48
br label %49
49: ; preds = %14
%50 = load i64, i64* %9
%51 = add i64 %50, 1
store i64 %51, i64* %9
br label %10
52: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @cross_vector(double* nocapture %0, double* nocapture %1, double* nocapture writeonly %2, i64 %3) {
%5 = icmp eq i64 %3, 0
br i1 %5, label %26, label %6
6: ; preds = %4, %6
%7 = phi i64 [ %8, %6 ], [ 0, %4 ]
%8 = add nuw i64 %7, 1
%9 = icmp eq i64 %8, %3
%10 = select i1 %9, i64 0, i64 %8
%11 = getelementptr inbounds double, double* %0, i64 %10
%12 = load double, double* %11
%13 = add i64 %7, 2
%14 = urem i64 %13, %3
%15 = getelementptr inbounds double, double* %1, i64 %14
%16 = load double, double* %15
%17 = getelementptr inbounds double, double* %0, i64 %14
%18 = load double, double* %17
%19 = getelementptr inbounds double, double* %1, i64 %10
%20 = load double, double* %19
%21 = fneg double %18
%22 = fmul double %20, %21
%23 = tail call double @llvm.fmuladd.f64(double %12, double %16, double %22)
%24 = getelementptr inbounds double, double* %2, i64 %7
store double %23, double* %24
%25 = icmp eq i64 %8, %3
br i1 %25, label %26, label %6
26: ; preds = %6, %4
ret void
}