void orthogvec(double *vec1, int beg, int end, double *vec2) {
  double alpha;
  double dot();
  void scadd();
  alpha = -dot(vec1, beg, end, vec2) / dot(vec2, beg, end, vec2);
  scadd(vec1, beg, end, alpha, vec2);
}


x86 assembly (clang, -O0):
<orthogvec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x0,%al
call   1030 <dot@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x0,%al
call   1030 <dot@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
movsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rcx
mov    $0x1,%al
call   1040 <scadd@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<orthogvec>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
xor    %eax,%eax
call   1030 <dot@plt>
xorpd  0xebc(%rip),%xmm0
movapd %xmm0,(%rsp)
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   1030 <dot@plt>
movapd (%rsp),%xmm1
divsd  %xmm0,%xmm1
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
movapd %xmm1,%xmm0
mov    %rbx,%rcx
mov    $0x1,%al
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <scadd@plt>

LLVM IR (-O0):
define void @orthogvec(double* %0, i32 %1, i32 %2, double* %3) {
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca double*
%9 = alloca double
store double* %0, double** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store double* %3, double** %8
%10 = load double*, double** %5
%11 = load i32, i32* %6
%12 = load i32, i32* %7
%13 = load double*, double** %8
%14 = call double (double*, i32, i32, double*, ...) bitcast (double (...)* @dot to double (double*, i32, i32, double*, ...)*)(double* %10, i32 %11, i32 %12, double* %13)
%15 = fneg double %14
%16 = load double*, double** %8
%17 = load i32, i32* %6
%18 = load i32, i32* %7
%19 = load double*, double** %8
%20 = call double (double*, i32, i32, double*, ...) bitcast (double (...)* @dot to double (double*, i32, i32, double*, ...)*)(double* %16, i32 %17, i32 %18, double* %19)
%21 = fdiv double %15, %20
store double %21, double* %9
%22 = load double*, double** %5
%23 = load i32, i32* %6
%24 = load i32, i32* %7
%25 = load double, double* %9
%26 = load double*, double** %8
ret void
}

LLVM IR (-O2):
define void @orthogvec(double* %0, i32 %1, i32 %2, double* %3) {
%5 = tail call double (double*, i32, i32, double*, ...) bitcast (double (...)* @dot to double (double*, i32, i32, double*, ...)*)(double* %0, i32 %1, i32 %2, double* %3)
%6 = fneg double %5
%7 = tail call double (double*, i32, i32, double*, ...) bitcast (double (...)* @dot to double (double*, i32, i32, double*, ...)*)(double* %3, i32 %1, i32 %2, double* %3)
%8 = fdiv double %6, %7
tail call void (double*, i32, i32, double, double*, ...) bitcast (void (...)* @scadd to void (double*, i32, i32, double, double*, ...)*)(double* %0, i32 %1, i32 %2, double %8, double* %3)
ret void
}