#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 */
double fabs(double const);
void renormalize_weights(const double src_lats[4], double wgts[4]) {
  int n;
  double sum_wgts = 0.0;
  for (n = 0; n < 4; ++n)
    sum_wgts += fabs(src_lats[n]);
  for (n = 0; n < 4; ++n)
    wgts[n] = fabs(src_lats[n]) / sum_wgts;
}


x86 assembly (clang, -O0):
<renormalize_weights>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    1155 <renormalize_weights+0x55>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movaps 0xec7(%rip),%xmm1
pand   %xmm1,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    111b <renormalize_weights+0x1b>
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    119e <renormalize_weights+0x9e>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movaps 0xe86(%rip),%xmm1
pand   %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115c <renormalize_weights+0x5c>
pop    %rbp
ret

x86 assembly (clang, -O2):
<renormalize_weights>:
movsd  (%rdi),%xmm1
movsd  0x8(%rdi),%xmm2
movsd  0x10(%rdi),%xmm3
movsd  0x18(%rdi),%xmm0
movapd 0xee5(%rip),%xmm4
andpd  %xmm4,%xmm1
andpd  %xmm4,%xmm2
addsd  %xmm1,%xmm2
andpd  %xmm4,%xmm3
addsd  %xmm2,%xmm3
andpd  %xmm4,%xmm0
addsd  %xmm3,%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsi)
movsd  0x8(%rdi),%xmm1
andpd  %xmm4,%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsi)
movsd  0x10(%rdi),%xmm1
andpd  %xmm4,%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsi)
movsd  0x18(%rdi),%xmm1
andpd  %xmm4,%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsi)
ret

LLVM IR (-O0):
define void @renormalize_weights(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
%5 = alloca i32
%6 = alloca double
store double* %0, double** %3
store double* %1, double** %4
store double 0.000000e+00, double* %6
store i32 0, i32* %5
br label %7
7: ; preds = %19, %2
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 4
br i1 %9, label %10, label %22
10: ; preds = %7
%11 = load double*, double** %3
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds double, double* %11, i64 %13
%15 = load double, double* %14
%16 = call double @llvm.fabs.f64(double %15)
%17 = load double, double* %6
%18 = fadd double %17, %16
store double %18, double* %6
br label %19
19: ; preds = %10
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
br label %7
22: ; preds = %7
store i32 0, i32* %5
br label %23
23: ; preds = %39, %22
%24 = load i32, i32* %5
%25 = icmp slt i32 %24, 4
br i1 %25, label %26, label %42
26: ; preds = %23
%27 = load double*, double** %3
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = load double, double* %30
%32 = call double @llvm.fabs.f64(double %31)
%33 = load double, double* %6
%34 = fdiv double %32, %33
%35 = load double*, double** %4
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
store double %34, double* %38
br label %39
39: ; preds = %26
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %23
42: ; preds = %23
ret void
}

LLVM IR (-O2):
define void @renormalize_weights(double* nocapture %0, double* nocapture writeonly %1) {
%3 = load double, double* %0
%4 = tail call double @llvm.fabs.f64(double %3)
%5 = getelementptr inbounds double, double* %0, i64 1
%6 = load double, double* %5
%7 = tail call double @llvm.fabs.f64(double %6)
%8 = fadd double %4, %7
%9 = getelementptr inbounds double, double* %0, i64 2
%10 = load double, double* %9
%11 = tail call double @llvm.fabs.f64(double %10)
%12 = fadd double %8, %11
%13 = getelementptr inbounds double, double* %0, i64 3
%14 = load double, double* %13
%15 = tail call double @llvm.fabs.f64(double %14)
%16 = fadd double %12, %15
%17 = fdiv double %4, %16
store double %17, double* %1
%18 = load double, double* %5
%19 = tail call double @llvm.fabs.f64(double %18)
%20 = fdiv double %19, %16
%21 = getelementptr inbounds double, double* %1, i64 1
store double %20, double* %21
%22 = load double, double* %9
%23 = tail call double @llvm.fabs.f64(double %22)
%24 = fdiv double %23, %16
%25 = getelementptr inbounds double, double* %1, i64 2
store double %24, double* %25
%26 = load double, double* %13
%27 = tail call double @llvm.fabs.f64(double %26)
%28 = fdiv double %27, %16
%29 = getelementptr inbounds double, double* %1, i64 3
store double %28, double* %29
ret void
}