#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 int /*<<< orphan*/ GLdouble;

/* Variables and functions */
int /*<<< orphan*/ matrixAddScaled(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                   int /*<<< orphan*/ *, int);
int /*<<< orphan*/ matrixScalarProduct(int /*<<< orphan*/ *,
                                       int /*<<< orphan*/ *, int);
void matrixOrtVectorToBasis(GLdouble *basis, GLdouble *vector, int basisDim,
                            int spaceDim) {
  int i;
  for (i = 0; i < basisDim; i++)
    matrixAddScaled(
        vector, -matrixScalarProduct(vector, basis + i * spaceDim, spaceDim),
        basis + i * spaceDim, spaceDim);
}


x86 assembly (clang, -O0):
<matrixOrtVectorToBasis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a3 <matrixOrtVectorToBasis+0x83>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%eax
imul   -0x18(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x18(%rbp),%edx
call   1030 <matrixScalarProduct@plt>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
sub    %eax,%esi
mov    -0x8(%rbp),%rdx
mov    -0x1c(%rbp),%eax
imul   -0x18(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rdx
mov    -0x18(%rbp),%ecx
call   1040 <matrixAddScaled@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113d <matrixOrtVectorToBasis+0x1d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrixOrtVectorToBasis>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edx,%edx
jle    1169 <matrixOrtVectorToBasis+0x49>
mov    %ecx,%r14d
mov    %rsi,%r12
mov    %rdi,%rbp
movslq %ecx,%r15
mov    %edx,%ebx
shl    $0x2,%r15
xchg   %ax,%ax
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1030 <matrixScalarProduct@plt>
neg    %eax
mov    %r12,%rdi
mov    %eax,%esi
mov    %rbp,%rdx
mov    %r14d,%ecx
call   1040 <matrixAddScaled@plt>
add    %r15,%rbp
add    $0xffffffffffffffff,%rbx
jne    1140 <matrixOrtVectorToBasis+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @matrixOrtVectorToBasis(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
br label %10
10: ; preds = %34, %4
%11 = load i32, i32* %9
%12 = load i32, i32* %7
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %37
14: ; preds = %10
%15 = load i32*, i32** %6
%16 = load i32*, i32** %6
%17 = load i32*, i32** %5
%18 = load i32, i32* %9
%19 = load i32, i32* %8
%20 = mul nsw i32 %18, %19
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %17, i64 %21
%23 = load i32, i32* %8
%24 = call i32 @matrixScalarProduct(i32* %16, i32* %22, i32 %23)
%25 = sub nsw i32 0, %24
%26 = load i32*, i32** %5
%27 = load i32, i32* %9
%28 = load i32, i32* %8
%29 = mul nsw i32 %27, %28
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %26, i64 %30
%32 = load i32, i32* %8
%33 = call i32 @matrixAddScaled(i32* %15, i32 %25, i32* %31, i32 %32)
br label %34
34: ; preds = %14
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
store i32 %36, i32* %9
br label %10
37: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @matrixOrtVectorToBasis(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %18
6: ; preds = %4
%7 = sext i32 %3 to i64
%8 = zext i32 %2 to i64
br label %9
9: ; preds = %6, %9
%10 = phi i64 [ 0, %6 ], [ %16, %9 ]
%11 = mul nsw i64 %10, %7
%12 = getelementptr inbounds i32, i32* %0, i64 %11
%13 = tail call i32 @matrixScalarProduct(i32* %1, i32* %12, i32 %3)
%14 = sub nsw i32 0, %13
%15 = tail call i32 @matrixAddScaled(i32* %1, i32 %14, i32* %12, i32 %3)
%16 = add nuw nsw i64 %10, 1
%17 = icmp eq i64 %16, %8
br i1 %17, label %18, label %9
18: ; preds = %9, %4
ret void
}