#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 */
struct GTOBasis_t {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
double eval_chi(int, struct GTOBasis_t *, double, double, double);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
double uhf_mo(int nBasis, struct GTOBasis_t *gto, double *C, int n, double x,
              double y, double z) {
  int i;
  double sum;
  if (n >= nBasis || n < 0) {
    printf("uhf_mo: error invalid molecular orbital index\n");
    exit(EXIT_FAILURE);
  }
  sum = 0.0;
  for (i = 0; i < nBasis; i++) {
    sum += C[n * nBasis + i] * eval_chi(i, gto, x, y, z);
  }
  return sum;
}


x86 assembly (clang, -O0):
<uhf_mo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movsd  %xmm0,-0x28(%rbp)
movsd  %xmm1,-0x30(%rbp)
movsd  %xmm2,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    116b <uhf_mo+0x3b>
cmpl   $0x0,-0x1c(%rbp)
jge    1185 <uhf_mo+0x55>
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11fe <uhf_mo+0xce>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
imul   -0x4(%rbp),%ecx
add    -0x3c(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x3c(%rbp),%edi
mov    -0x10(%rbp),%rsi
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
call   1040 <eval_chi@plt>
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1194 <uhf_mo+0x64>
movsd  -0x48(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uhf_mo>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
cmp    %edi,%ecx
jge    11dc <uhf_mo+0xac>
test   %ecx,%ecx
js     11dc <uhf_mo+0xac>
test   %edi,%edi
jle    11c8 <uhf_mo+0x98>
mov    %rsi,%r14
imul   %edi,%ecx
movslq %ecx,%rax
mov    %edi,%r15d
lea    (%rdx,%rax,8),%r12
xorpd  %xmm3,%xmm3
xor    %ebx,%ebx
movsd  %xmm2,0x10(%rsp)
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
cs nopw 0x0(%rax,%rax,1)
movsd  %xmm3,0x20(%rsp)
movsd  (%r12,%rbx,8),%xmm0
movsd  %xmm0,0x18(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
call   1040 <eval_chi@plt>
movsd  0x20(%rsp),%xmm3
mulsd  0x18(%rsp),%xmm0
addsd  %xmm0,%xmm3
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1180 <uhf_mo+0x50>
jmp    11cc <uhf_mo+0x9c>
xorpd  %xmm3,%xmm3
movapd %xmm3,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe1d(%rip),%rdi
call   1030 <puts@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.GTOBasis_t = type { i32 }
@.str = [47 x i8] c"uhf_mo: error invalid molecular orbital index\0A\00"
@EXIT_FAILURE = global i32 0
define double @uhf_mo(i32 %0, %struct.GTOBasis_t* %1, double* %2, i32 %3, double %4, double %5, double %6) {
%8 = alloca i32
%9 = alloca %struct.GTOBasis_t*
%10 = alloca double*
%11 = alloca i32
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca i32
%16 = alloca double
store i32 %0, i32* %8
store %struct.GTOBasis_t* %1, %struct.GTOBasis_t** %9
store double* %2, double** %10
store i32 %3, i32* %11
store double %4, double* %12
store double %5, double* %13
store double %6, double* %14
%17 = load i32, i32* %11
%18 = load i32, i32* %8
%19 = icmp sge i32 %17, %18
br i1 %19, label %23, label %20
20: ; preds = %7
%21 = load i32, i32* %11
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %20, %7
%24 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %20
store double 0.000000e+00, double* %16
store i32 0, i32* %15
br label %28
28: ; preds = %50, %27
%29 = load i32, i32* %15
%30 = load i32, i32* %8
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %53
32: ; preds = %28
%33 = load double*, double** %10
%34 = load i32, i32* %11
%35 = load i32, i32* %8
%36 = mul nsw i32 %34, %35
%37 = load i32, i32* %15
%38 = add nsw i32 %36, %37
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %33, i64 %39
%41 = load double, double* %40
%42 = load i32, i32* %15
%43 = load %struct.GTOBasis_t*, %struct.GTOBasis_t** %9
%44 = load double, double* %12
%45 = load double, double* %13
%46 = load double, double* %14
%47 = call double @eval_chi(i32 %42, %struct.GTOBasis_t* %43, double %44, double %45, double %46)
%48 = load double, double* %16
%49 = call double @llvm.fmuladd.f64(double %41, double %47, double %48)
store double %49, double* %16
br label %50
50: ; preds = %32
%51 = load i32, i32* %15
%52 = add nsw i32 %51, 1
store i32 %52, i32* %15
br label %28
53: ; preds = %28
%54 = load double, double* %16
ret double %54
}

LLVM IR (-O2):
%struct.GTOBasis_t = type { i32 }
@EXIT_FAILURE = global i32 0
@str = [46 x i8] c"uhf_mo: error invalid molecular orbital index\00"
define double @uhf_mo(i32 %0, %struct.GTOBasis_t* %1, double* nocapture %2, i32 %3, double %4, double %5, double %6) {
%8 = icmp sge i32 %3, %0
%9 = icmp slt i32 %3, 0
%10 = or i1 %8, %9
br i1 %10, label %17, label %11
11: ; preds = %7
%12 = icmp sgt i32 %0, 0
br i1 %12, label %13, label %32
13: ; preds = %11
%14 = mul nsw i32 %3, %0
%15 = sext i32 %14 to i64
%16 = zext i32 %0 to i64
br label %21
17: ; preds = %7
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @exit(i32 %19)
unreachable
21: ; preds = %13, %21
%22 = phi i64 [ 0, %13 ], [ %30, %21 ]
%23 = phi double [ 0.000000e+00, %13 ], [ %29, %21 ]
%24 = add nsw i64 %22, %15
%25 = getelementptr inbounds double, double* %2, i64 %24
%26 = load double, double* %25
%27 = trunc i64 %22 to i32
%28 = tail call double @eval_chi(i32 %27, %struct.GTOBasis_t* %1, double %4, double %5, double %6)
%29 = tail call double @llvm.fmuladd.f64(double %26, double %28, double %23)
%30 = add nuw nsw i64 %22, 1
%31 = icmp eq i64 %30, %16
br i1 %31, label %32, label %21
32: ; preds = %21, %11
%33 = phi double [ 0.000000e+00, %11 ], [ %29, %21 ]
ret double %33
}