#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 normalizing_constant_Q(double **, double const *, size_t);
double normalize_Q(double **q, const double *freqs, size_t dim) {
  double normalizingConstant = normalizing_constant_Q(q, freqs, dim);
  for (size_t i = 0; i < dim; i++) {
    for (size_t j = 0; j < dim; j++) {
      q[i][j] /= normalizingConstant;
    }
  }
  return normalizingConstant;
}


x86 assembly (clang, -O0):
<normalize_Q>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <normalizing_constant_Q@plt>
movsd  %xmm0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11b0 <normalize_Q+0xa0>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    119a <normalize_Q+0x8a>
movsd  -0x20(%rbp),%xmm1
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1158 <normalize_Q+0x48>
jmp    119f <normalize_Q+0x8f>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1142 <normalize_Q+0x32>
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize_Q>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rdi,%r14
call   1030 <normalizing_constant_Q@plt>
test   %rbx,%rbx
je     11fc <normalize_Q+0xec>
lea    -0x2(%rbx),%r9
mov    %r9,%r10
shr    %r10
add    $0x1,%r10
mov    %rbx,%rdx
and    $0xfffffffffffffffe,%rdx
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
mov    %r10,%r8
and    $0xfffffffffffffffe,%r8
xor    %edi,%edi
jmp    115d <normalize_Q+0x4d>
add    $0x1,%rdi
cmp    %rbx,%rdi
je     11fc <normalize_Q+0xec>
mov    (%r14,%rdi,8),%rsi
cmp    $0x2,%rbx
jae    1170 <normalize_Q+0x60>
xor    %eax,%eax
jmp    11e0 <normalize_Q+0xd0>
nopl   0x0(%rax,%rax,1)
cmp    $0x2,%r9
jae    1180 <normalize_Q+0x70>
xor    %eax,%eax
jmp    11b8 <normalize_Q+0xa8>
nopw   0x0(%rax,%rax,1)
mov    %r8,%rcx
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nop
movupd (%rsi,%rax,8),%xmm2
movupd 0x10(%rsi,%rax,8),%xmm3
divpd  %xmm1,%xmm2
movupd %xmm2,(%rsi,%rax,8)
divpd  %xmm1,%xmm3
movupd %xmm3,0x10(%rsi,%rax,8)
add    $0x4,%rax
add    $0xfffffffffffffffe,%rcx
jne    1190 <normalize_Q+0x80>
test   $0x1,%r10b
je     11cc <normalize_Q+0xbc>
movupd (%rsi,%rax,8),%xmm2
divpd  %xmm1,%xmm2
movupd %xmm2,(%rsi,%rax,8)
mov    %rdx,%rax
cmp    %rbx,%rdx
je     1150 <normalize_Q+0x40>
nopl   0x0(%rax,%rax,1)
movsd  (%rsi,%rax,8),%xmm2
divsd  %xmm0,%xmm2
movsd  %xmm2,(%rsi,%rax,8)
add    $0x1,%rax
cmp    %rax,%rbx
jne    11e0 <normalize_Q+0xd0>
jmp    1150 <normalize_Q+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @normalize_Q(double** %0, double* %1, i64 %2) {
%4 = alloca double**
%5 = alloca double*
%6 = alloca i64
%7 = alloca double
%8 = alloca i64
%9 = alloca i64
store double** %0, double*** %4
store double* %1, double** %5
store i64 %2, i64* %6
%10 = load double**, double*** %4
%11 = load double*, double** %5
%12 = load i64, i64* %6
%13 = call double @normalizing_constant_Q(double** %10, double* %11, i64 %12)
store double %13, double* %7
store i64 0, i64* %8
br label %14
14: ; preds = %37, %3
%15 = load i64, i64* %8
%16 = load i64, i64* %6
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %40
18: ; preds = %14
store i64 0, i64* %9
br label %19
19: ; preds = %33, %18
%20 = load i64, i64* %9
%21 = load i64, i64* %6
%22 = icmp ult i64 %20, %21
br i1 %22, label %23, label %36
23: ; preds = %19
%24 = load double, double* %7
%25 = load double**, double*** %4
%26 = load i64, i64* %8
%27 = getelementptr inbounds double*, double** %25, i64 %26
%28 = load double*, double** %27
%29 = load i64, i64* %9
%30 = getelementptr inbounds double, double* %28, i64 %29
%31 = load double, double* %30
%32 = fdiv double %31, %24
store double %32, double* %30
br label %33
33: ; preds = %23
%34 = load i64, i64* %9
%35 = add i64 %34, 1
store i64 %35, i64* %9
br label %19
36: ; preds = %19
br label %37
37: ; preds = %36
%38 = load i64, i64* %8
%39 = add i64 %38, 1
store i64 %39, i64* %8
br label %14
40: ; preds = %14
%41 = load double, double* %7
ret double %41
}

LLVM IR (-O2):
define double @normalize_Q(double** %0, double* %1, i64 %2) {
%4 = tail call double @normalizing_constant_Q(double** %0, double* %1, i64 %2)
%5 = icmp eq i64 %2, 0
br i1 %5, label %52, label %6
6: ; preds = %3
%7 = add i64 %2, -2
%8 = lshr i64 %7, 1
%9 = add nuw i64 %8, 1
%10 = icmp ult i64 %2, 2
%11 = and i64 %2, -2
%12 = insertelement <2 x double> poison, double %4, i64 0
%13 = shufflevector <2 x double> %12, <2 x double> poison, <2 x i32> zeroinitializer
%14 = and i64 %9, 1
%15 = icmp ult i64 %7, 2
%16 = and i64 %9, -2
%17 = icmp eq i64 %14, 0
%18 = icmp eq i64 %11, %2
br label %19
19: ; preds = %6, %53
%20 = phi i64 [ %54, %53 ], [ 0, %6 ]
%21 = getelementptr inbounds double*, double** %0, i64 %20
%22 = load double*, double** %21
br i1 %10, label %50, label %23
23: ; preds = %19
br i1 %15, label %41, label %24
24: ; preds = %23, %24
%25 = phi i64 [ %38, %24 ], [ 0, %23 ]
%26 = phi i64 [ %39, %24 ], [ 0, %23 ]
%27 = getelementptr inbounds double, double* %22, i64 %25
%28 = bitcast double* %27 to <2 x double>*
%29 = load <2 x double>, <2 x double>* %28
%30 = fdiv <2 x double> %29, %13
%31 = bitcast double* %27 to <2 x double>*
store <2 x double> %30, <2 x double>* %31
%32 = or i64 %25, 2
%33 = getelementptr inbounds double, double* %22, i64 %32
%34 = bitcast double* %33 to <2 x double>*
%35 = load <2 x double>, <2 x double>* %34
%36 = fdiv <2 x double> %35, %13
%37 = bitcast double* %33 to <2 x double>*
store <2 x double> %36, <2 x double>* %37
%38 = add nuw i64 %25, 4
%39 = add nuw i64 %26, 2
%40 = icmp eq i64 %39, %16
br i1 %40, label %41, label %24
41: ; preds = %24, %23
%42 = phi i64 [ 0, %23 ], [ %38, %24 ]
br i1 %17, label %49, label %43
43: ; preds = %41
%44 = getelementptr inbounds double, double* %22, i64 %42
%45 = bitcast double* %44 to <2 x double>*
%46 = load <2 x double>, <2 x double>* %45
%47 = fdiv <2 x double> %46, %13
%48 = bitcast double* %44 to <2 x double>*
store <2 x double> %47, <2 x double>* %48
br label %49
49: ; preds = %41, %43
br i1 %18, label %53, label %50
50: ; preds = %19, %49
%51 = phi i64 [ 0, %19 ], [ %11, %49 ]
br label %56
52: ; preds = %53, %3
ret double %4
53: ; preds = %56, %49
%54 = add nuw i64 %20, 1
%55 = icmp eq i64 %54, %2
br i1 %55, label %52, label %19
56: ; preds = %50, %56
%57 = phi i64 [ %61, %56 ], [ %51, %50 ]
%58 = getelementptr inbounds double, double* %22, i64 %57
%59 = load double, double* %58
%60 = fdiv double %59, %4
store double %60, double* %58
%61 = add nuw i64 %57, 1
%62 = icmp eq i64 %61, %2
br i1 %62, label %53, label %56
}