#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 dmodule(double *, int);
double *multiply_double_vector_matrix(double *, double **, int, int);
double *compute_qs(double **S, int s, int n, double **v, int inx) {
  double *p = v[inx];
  double *sp = multiply_double_vector_matrix(p, S, s, n);
  double nor = dmodule(sp, n);
  int i = 0;
  if (nor > 0)
    for (i = 1; i <= n; i++)
      sp[i] = sp[i] / nor;
  return sp;
}


x86 assembly (clang, -O0):
<compute_qs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1040 <multiply_double_vector_matrix@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1030 <dmodule@plt>
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movsd  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11d0 <compute_qs+0xb0>
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11cb <compute_qs+0xab>
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  -0x38(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1192 <compute_qs+0x72>
jmp    11d0 <compute_qs+0xb0>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_qs>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%edx
mov    %rdi,%rsi
movslq %r8d,%rax
mov    (%rcx,%rax,8),%rdi
mov    %ebp,%ecx
call   1040 <multiply_double_vector_matrix@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %ebp,%esi
call   1030 <dmodule@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1207 <compute_qs+0xe7>
test   %ebp,%ebp
jle    1207 <compute_qs+0xe7>
mov    %ebp,%eax
mov    $0x1,%ecx
cmp    $0x2,%ebp
jb     11e7 <compute_qs+0xc7>
mov    %eax,%ecx
and    $0xfffffffe,%ecx
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
lea    -0x2(%rcx),%rsi
mov    %rsi,%rdx
shr    %rdx
add    $0x1,%rdx
test   %rsi,%rsi
je     1211 <compute_qs+0xf1>
mov    %rdx,%rdi
and    $0xfffffffffffffffe,%rdi
mov    $0x1,%esi
nopl   0x0(%rax,%rax,1)
movupd (%rbx,%rsi,8),%xmm2
movupd 0x10(%rbx,%rsi,8),%xmm3
divpd  %xmm1,%xmm2
movupd %xmm2,(%rbx,%rsi,8)
divpd  %xmm1,%xmm3
movupd %xmm3,0x10(%rbx,%rsi,8)
add    $0x4,%rsi
add    $0xfffffffffffffffe,%rdi
jne    11a0 <compute_qs+0x80>
test   $0x1,%dl
je     11db <compute_qs+0xbb>
movupd (%rbx,%rsi,8),%xmm2
divpd  %xmm1,%xmm2
movupd %xmm2,(%rbx,%rsi,8)
cmp    %rcx,%rax
je     1207 <compute_qs+0xe7>
mov    %rax,%rcx
or     $0x1,%rcx
add    $0x1,%rax
nopl   0x0(%rax,%rax,1)
movsd  (%rbx,%rcx,8),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    11f0 <compute_qs+0xd0>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    $0x1,%esi
test   $0x1,%dl
jne    11cd <compute_qs+0xad>
jmp    11db <compute_qs+0xbb>

LLVM IR (-O0):
define double* @compute_qs(double** %0, i32 %1, i32 %2, double** %3, i32 %4) {
%6 = alloca double**
%7 = alloca i32
%8 = alloca i32
%9 = alloca double**
%10 = alloca i32
%11 = alloca double*
%12 = alloca double*
%13 = alloca double
%14 = alloca i32
store double** %0, double*** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store double** %3, double*** %9
store i32 %4, i32* %10
%15 = load double**, double*** %9
%16 = load i32, i32* %10
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds double*, double** %15, i64 %17
%19 = load double*, double** %18
store double* %19, double** %11
%20 = load double*, double** %11
%21 = load double**, double*** %6
%22 = load i32, i32* %7
%23 = load i32, i32* %8
%24 = call double* @multiply_double_vector_matrix(double* %20, double** %21, i32 %22, i32 %23)
store double* %24, double** %12
%25 = load double*, double** %12
%26 = load i32, i32* %8
%27 = call double @dmodule(double* %25, i32 %26)
store double %27, double* %13
store i32 0, i32* %14
%28 = load double, double* %13
%29 = fcmp ogt double %28, 0.000000e+00
br i1 %29, label %30, label %51
30: ; preds = %5
store i32 1, i32* %14
br label %31
31: ; preds = %47, %30
%32 = load i32, i32* %14
%33 = load i32, i32* %8
%34 = icmp sle i32 %32, %33
br i1 %34, label %35, label %50
35: ; preds = %31
%36 = load double*, double** %12
%37 = load i32, i32* %14
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %36, i64 %38
%40 = load double, double* %39
%41 = load double, double* %13
%42 = fdiv double %40, %41
%43 = load double*, double** %12
%44 = load i32, i32* %14
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %43, i64 %45
store double %42, double* %46
br label %47
47: ; preds = %35
%48 = load i32, i32* %14
%49 = add nsw i32 %48, 1
store i32 %49, i32* %14
br label %31
50: ; preds = %31
br label %51
51: ; preds = %50, %5
%52 = load double*, double** %12
ret double* %52
}

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