#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);
scalar_t__ log10(double);
int /*<<< orphan*/ printf(char *, ...);
void checkorth(double **mat, int n, int dim) {
  int i, j;
  double measure;
  double prod;
  double worst;
  int lim;
  int screenlim;
  int option;
  double dot();
  screenlim = 20;
  option = 3;
  if (option == 1) {
    printf("Orthogonality check:\n");
    for (i = 1; i <= dim; i++) {
      printf("%2d)", i);
      for (j = 1; j <= i; j++) {
        prod = dot(mat[i], 1, n, mat[j]);
        printf(" %2d", -(int)log10(prod));
      }
      printf("\n");
    }
  }
  if (option == 2) {
    printf("Frobenius orthogonality measure:");
    measure = 0;
    for (i = 1; i <= dim; i++) {
      for (j = i; j <= dim; j++) {
        prod = dot(mat[i], 1, n, mat[j]);
        if (i == j) {
          measure += fabs(1.0 - prod);
        } else {
          measure += 2.0 * fabs(prod);
        }
      }
    }
    printf("%g \n", measure);
  }
  if (option == 3) {
    printf("%3d) ", dim);
    lim = ((dim) < (screenlim) ? (dim) : (screenlim));
    worst = 0;
    for (i = 1; i <= dim; i++) {
      prod = dot(mat[i], 1, n, mat[dim]);
      if (i <= lim) {
        printf(" %2d", -(int)log10(fabs(prod)));
      }
      if ((i != dim) && (fabs(prod) > fabs(worst))) {
        worst = prod;
      }
    }
    printf(" worst %4.2e\n", worst);
  }
}


x86 assembly (clang, -O0):
<checkorth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x14,-0x38(%rbp)
movl   $0x3,-0x3c(%rbp)
cmpl   $0x1,-0x3c(%rbp)
jne    1216 <checkorth+0xe6>
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     1211 <checkorth+0xe1>
mov    -0x14(%rbp),%esi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11f5 <checkorth+0xc5>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    $0x1,%esi
mov    $0x0,%al
call   1030 <dot@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1050 <log10@plt>
xor    %esi,%esi
sub    %eax,%esi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1193 <checkorth+0x63>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116f <checkorth+0x3f>
jmp    1216 <checkorth+0xe6>
cmpl   $0x2,-0x3c(%rbp)
jne    1315 <checkorth+0x1e5>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     1302 <checkorth+0x1d2>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     12ef <checkorth+0x1bf>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    $0x1,%esi
mov    $0x0,%al
call   1030 <dot@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    12ba <checkorth+0x18a>
movsd  0xd75(%rip),%xmm0
subsd  -0x28(%rbp),%xmm0
movaps 0xd59(%rip),%xmm1
pand   %xmm1,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    12dc <checkorth+0x1ac>
movsd  -0x28(%rbp),%xmm0
movaps 0xd3a(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    12e1 <checkorth+0x1b1>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    124f <checkorth+0x11f>
jmp    12f4 <checkorth+0x1c4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    123d <checkorth+0x10d>
movsd  -0x20(%rbp),%xmm0
lea    0xd4b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
cmpl   $0x3,-0x3c(%rbp)
jne    1433 <checkorth+0x303>
mov    -0x10(%rbp),%esi
lea    0xd35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    1347 <checkorth+0x217>
mov    -0x10(%rbp),%eax
mov    %eax,-0x40(%rbp)
jmp    134d <checkorth+0x21d>
mov    -0x38(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x34(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     1420 <checkorth+0x2f0>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    $0x1,%esi
mov    $0x0,%al
call   1030 <dot@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x34(%rbp),%eax
jg     13cd <checkorth+0x29d>
movsd  -0x28(%rbp),%xmm0
movaps 0xc4e(%rip),%xmm1
pand   %xmm1,%xmm0
call   1050 <log10@plt>
xor    %esi,%esi
sub    %eax,%esi
lea    0xc6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     140d <checkorth+0x2dd>
movsd  -0x28(%rbp),%xmm0
movaps 0xc1b(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  -0x30(%rbp),%xmm1
movaps 0xc0b(%rip),%xmm2
pand   %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jbe    140d <checkorth+0x2dd>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1412 <checkorth+0x2e2>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1362 <checkorth+0x232>
movsd  -0x30(%rbp),%xmm0
lea    0xc38(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkorth>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r13d
mov    %esi,%r14d
mov    %rdi,%rbp
lea    0xec7(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r13d,%r13d
jle    1220 <checkorth+0xf0>
cmp    $0x14,%r13d
mov    $0x14,%r12d
cmovb  %r13d,%r12d
mov    %r13d,%ebx
add    $0x1,%r13d
xorpd  %xmm0,%xmm0
movapd %xmm0,(%rsp)
mov    $0x1,%r15d
jmp    119d <checkorth+0x6d>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r15
cmp    %r15,%r13
je     1229 <checkorth+0xf9>
mov    0x0(%rbp,%r15,8),%rdi
mov    0x0(%rbp,%rbx,8),%rcx
mov    $0x1,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1030 <dot@plt>
movapd %xmm0,%xmm3
cmp    %r12,%r15
ja     11ee <checkorth+0xbe>
movapd %xmm3,%xmm0
andpd  0xe35(%rip),%xmm0
movapd %xmm3,0x10(%rsp)
call   1050 <log10@plt>
neg    %eax
lea    0xe31(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movapd 0x10(%rsp),%xmm3
cmp    %r15,%rbx
je     1190 <checkorth+0x60>
movapd %xmm3,%xmm0
movapd 0xe01(%rip),%xmm2
andpd  %xmm2,%xmm0
movapd (%rsp),%xmm1
andpd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jbe    1190 <checkorth+0x60>
movapd %xmm3,(%rsp)
jmp    1190 <checkorth+0x60>
xorpd  %xmm0,%xmm0
movapd %xmm0,(%rsp)
lea    0xdeb(%rip),%rdi
movaps (%rsp),%xmm0
mov    $0x1,%al
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Orthogonality check:\0A\00"
@.str.1 = [5 x i8] c"%2d)\00"
@.str.2 = [5 x i8] c" %2d\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [33 x i8] c"Frobenius orthogonality measure:\00"
@.str.5 = [5 x i8] c"%g \0A\00"
@.str.6 = [6 x i8] c"%3d) \00"
@.str.7 = [14 x i8] c" worst %4.2e\0A\00"
define void @checkorth(double** %0, i32 %1, i32 %2) {
%4 = alloca double**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store double** %0, double*** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 20, i32* %13
store i32 3, i32* %14
%15 = load i32, i32* %14
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %57
17: ; preds = %3
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %7
br label %19
19: ; preds = %53, %17
%20 = load i32, i32* %7
%21 = load i32, i32* %6
%22 = icmp sle i32 %20, %21
br i1 %22, label %23, label %56
23: ; preds = %19
%24 = load i32, i32* %7
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %24)
store i32 1, i32* %8
br label %26
26: ; preds = %48, %23
%27 = load i32, i32* %8
%28 = load i32, i32* %7
%29 = icmp sle i32 %27, %28
br i1 %29, label %30, label %51
30: ; preds = %26
%31 = load double**, double*** %4
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double*, double** %31, i64 %33
%35 = load double*, double** %34
%36 = load i32, i32* %5
%37 = load double**, double*** %4
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double*, double** %37, i64 %39
%41 = load double*, double** %40
%42 = call double (double*, i32, i32, double*, ...) bitcast (double (...)* @dot to double (double*, i32, i32, double*, ...)*)(double* %35, i32 1, i32 %36, double* %41)
store double %42, double* %10
%43 = load double, double* %10
%44 = call i64 @log10(double %43)
%45 = trunc i64 %44 to i32
%46 = sub nsw i32 0, %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %30
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
br label %26
51: ; preds = %26
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %53
53: ; preds = %51
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
store i32 %55, i32* %7
br label %19
56: ; preds = %19
br label %57
57: ; preds = %56, %3
%58 = load i32, i32* %14
%59 = icmp eq i32 %58, 2
br i1 %59, label %60, label %110
60: ; preds = %57
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
store double 0.000000e+00, double* %9
store i32 1, i32* %7
br label %62
62: ; preds = %104, %60
%63 = load i32, i32* %7
%64 = load i32, i32* %6
%65 = icmp sle i32 %63, %64
br i1 %65, label %66, label %107
66: ; preds = %62
%67 = load i32, i32* %7
store i32 %67, i32* %8
br label %68
68: ; preds = %100, %66
%69 = load i32, i32* %8
%70 = load i32, i32* %6
%71 = icmp sle i32 %69, %70
br i1 %71, label %72, label %103
72: ; preds = %68
%73 = load double**, double*** %4
%74 = load i32, i32* %7
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds double*, double** %73, i64 %75
%77 = load double*, double** %76
%78 = load i32, i32* %5
%79 = load double**, double*** %4
%80 = load i32, i32* %8
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds double*, double** %79, i64 %81
%83 = load double*, double** %82
%84 = call double (double*, i32, i32, double*, ...) bitcast (double (...)* @dot to double (double*, i32, i32, double*, ...)*)(double* %77, i32 1, i32 %78, double* %83)
store double %84, double* %10
%85 = load i32, i32* %7
%86 = load i32, i32* %8
%87 = icmp eq i32 %85, %86
br i1 %87, label %88, label %94
88: ; preds = %72
%89 = load double, double* %10
%90 = fsub double 1.000000e+00, %89
%91 = call double @llvm.fabs.f64(double %90)
%92 = load double, double* %9
%93 = fadd double %92, %91
store double %93, double* %9
br label %99
94: ; preds = %72
%95 = load double, double* %10
%96 = call double @llvm.fabs.f64(double %95)
%97 = load double, double* %9
%98 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %96, double %97)
store double %98, double* %9
br label %99
99: ; preds = %94, %88
br label %100
100: ; preds = %99
%101 = load i32, i32* %8
%102 = add nsw i32 %101, 1
store i32 %102, i32* %8
br label %68
103: ; preds = %68
br label %104
104: ; preds = %103
%105 = load i32, i32* %7
%106 = add nsw i32 %105, 1
store i32 %106, i32* %7
br label %62
107: ; preds = %62
%108 = load double, double* %9
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), double %108)
br label %110
110: ; preds = %107, %57
%111 = load i32, i32* %14
%112 = icmp eq i32 %111, 3
br i1 %112, label %113, label %171
113: ; preds = %110
%114 = load i32, i32* %6
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %114)
%116 = load i32, i32* %6
%117 = load i32, i32* %13
%118 = icmp slt i32 %116, %117
br i1 %118, label %119, label %121
119: ; preds = %113
%120 = load i32, i32* %6
br label %123
121: ; preds = %113
%122 = load i32, i32* %13
br label %123
123: ; preds = %121, %119
%124 = phi i32 [ %120, %119 ], [ %122, %121 ]
store i32 %124, i32* %12
store double 0.000000e+00, double* %11
store i32 1, i32* %7
br label %125
125: ; preds = %165, %123
%126 = load i32, i32* %7
%127 = load i32, i32* %6
%128 = icmp sle i32 %126, %127
br i1 %128, label %129, label %168
129: ; preds = %125
%130 = load double**, double*** %4
%131 = load i32, i32* %7
%132 = sext i32 %131 to i64
%133 = getelementptr inbounds double*, double** %130, i64 %132
%134 = load double*, double** %133
%135 = load i32, i32* %5
%136 = load double**, double*** %4
%137 = load i32, i32* %6
%138 = sext i32 %137 to i64
%139 = getelementptr inbounds double*, double** %136, i64 %138
%140 = load double*, double** %139
%141 = call double (double*, i32, i32, double*, ...) bitcast (double (...)* @dot to double (double*, i32, i32, double*, ...)*)(double* %134, i32 1, i32 %135, double* %140)
store double %141, double* %10
%142 = load i32, i32* %7
%143 = load i32, i32* %12
%144 = icmp sle i32 %142, %143
br i1 %144, label %145, label %152
145: ; preds = %129
%146 = load double, double* %10
%147 = call double @llvm.fabs.f64(double %146)
%148 = call i64 @log10(double %147)
%149 = trunc i64 %148 to i32
%150 = sub nsw i32 0, %149
%151 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %150)
br label %152
152: ; preds = %145, %129
%153 = load i32, i32* %7
%154 = load i32, i32* %6
%155 = icmp ne i32 %153, %154
br i1 %155, label %156, label %164
156: ; preds = %152
%157 = load double, double* %10
%158 = call double @llvm.fabs.f64(double %157)
%159 = load double, double* %11
%160 = call double @llvm.fabs.f64(double %159)
%161 = fcmp ogt double %158, %160
br i1 %161, label %162, label %164
162: ; preds = %156
%163 = load double, double* %10
store double %163, double* %11
br label %164
164: ; preds = %162, %156, %152
br label %165
165: ; preds = %164
%166 = load i32, i32* %7
%167 = add nsw i32 %166, 1
store i32 %167, i32* %7
br label %125
168: ; preds = %125
%169 = load double, double* %11
%170 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), double %169)
br label %171
171: ; preds = %168, %110
ret void
}

LLVM IR (-O2):
@.str.2 = [5 x i8] c" %2d\00"
@.str.6 = [6 x i8] c"%3d) \00"
@.str.7 = [14 x i8] c" worst %4.2e\0A\00"
define void @checkorth(double** nocapture %0, i32 %1, i32 %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %2)
%5 = icmp slt i32 %2, 1
br i1 %5, label %40, label %6
6: ; preds = %3
%7 = icmp ult i32 %2, 20
%8 = select i1 %7, i32 %2, i32 20
%9 = zext i32 %2 to i64
%10 = getelementptr inbounds double*, double** %0, i64 %9
%11 = zext i32 %8 to i64
%12 = zext i32 %2 to i64
%13 = add nuw i32 %2, 1
%14 = zext i32 %13 to i64
br label %15
15: ; preds = %6, %36
%16 = phi i64 [ 1, %6 ], [ %38, %36 ]
%17 = phi double [ 0.000000e+00, %6 ], [ %37, %36 ]
%18 = getelementptr inbounds double*, double** %0, i64 %16
%19 = load double*, double** %18
%20 = load double*, double** %10
%21 = tail call double (double*, i32, i32, double*, ...) bitcast (double (...)* @dot to double (double*, i32, i32, double*, ...)*)(double* %19, i32 1, i32 %1, double* %20)
%22 = icmp ugt i64 %16, %11
br i1 %22, label %29, label %23
23: ; preds = %15
%24 = tail call double @llvm.fabs.f64(double %21)
%25 = tail call i64 @log10(double %24)
%26 = trunc i64 %25 to i32
%27 = sub nsw i32 0, %26
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %23, %15
%30 = icmp eq i64 %16, %12
br i1 %30, label %36, label %31
31: ; preds = %29
%32 = tail call double @llvm.fabs.f64(double %21)
%33 = tail call double @llvm.fabs.f64(double %17)
%34 = fcmp ogt double %32, %33
br i1 %34, label %35, label %36
35: ; preds = %31
br label %36
36: ; preds = %29, %31, %35
%37 = phi double [ %21, %35 ], [ %17, %31 ], [ %17, %29 ]
%38 = add nuw nsw i64 %16, 1
%39 = icmp eq i64 %38, %14
br i1 %39, label %40, label %15
40: ; preds = %36, %3
%41 = phi double [ 0.000000e+00, %3 ], [ %37, %36 ]
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), double %41)
ret void
}