#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 */
int /*<<< orphan*/ Exit(char *, double, double, int);
double det(double **, int);
int log(double);
double logdet(double **P, double *Pi1, double *Pi2) {
  int i;
  double returnValue, detP;
  detP = det(P, 4);
  if (0 >= detP) {
    return (5.00);
  }
  returnValue = -0.5 * log(detP);
  for (i = 0; i < 4; i++) {
    if ((0 >= Pi1[i]) || (0 >= Pi2[i]))
      Exit((char *)"Logdet value of Pi1[i] is %f, of Pi2[i] is %f, i is %d.",
           Pi1[i], Pi2[i], i);
    returnValue += (log(Pi1[i]) + log(Pi2[i])) / 8;
  }
  return (returnValue);
}


x86 assembly (clang, -O0):
<logdet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1050 <det@plt>
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x38(%rbp),%xmm0
jb     1177 <logdet+0x47>
movsd  0xe9b(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1258 <logdet+0x128>
movsd  -0x38(%rbp),%xmm0
call   1040 <log@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe73(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    124e <logdet+0x11e>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
xorps  %xmm0,%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jae    11d3 <logdet+0xa3>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
xorps  %xmm0,%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jb     11fc <logdet+0xcc>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x24(%rbp),%esi
lea    0xe19(%rip),%rdi
call   1030 <Exit@plt>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <log@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <log@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
add    %ecx,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119d <logdet+0x6d>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logdet>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    $0x4,%esi
call   1050 <det@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jae    130f <logdet+0x1df>
call   1040 <log@plt>
cvtsi2sd %eax,%xmm3
mulsd  0xea0(%rip),%xmm3
movsd  (%r14),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
movsd  (%r15),%xmm1
movsd  %xmm3,0x8(%rsp)
jae    118c <logdet+0x5c>
xorpd  %xmm2,%xmm2
ucomisd %xmm1,%xmm2
jb     119f <logdet+0x6f>
lea    0xe85(%rip),%rdi
xor    %esi,%esi
call   1030 <Exit@plt>
movsd  (%r14),%xmm0
call   1040 <log@plt>
mov    %eax,%ebx
movsd  (%r15),%xmm0
call   1040 <log@plt>
lea    (%rax,%rbx,1),%ecx
add    $0x7,%ecx
add    %ebx,%eax
cmovns %eax,%ecx
sar    $0x3,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  0x8(%rsp),%xmm3
addsd  %xmm0,%xmm3
movsd  0x8(%r14),%xmm0
xorpd  %xmm2,%xmm2
ucomisd %xmm0,%xmm2
movsd  0x8(%r15),%xmm1
movsd  %xmm3,0x8(%rsp)
jae    11f1 <logdet+0xc1>
ucomisd %xmm1,%xmm2
jb     1208 <logdet+0xd8>
lea    0xe20(%rip),%rdi
mov    $0x1,%esi
call   1030 <Exit@plt>
movsd  0x8(%r14),%xmm0
call   1040 <log@plt>
mov    %eax,%ebx
movsd  0x8(%r15),%xmm0
call   1040 <log@plt>
lea    (%rax,%rbx,1),%ecx
add    $0x7,%ecx
add    %ebx,%eax
cmovns %eax,%ecx
sar    $0x3,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  0x8(%rsp),%xmm3
addsd  %xmm0,%xmm3
movsd  0x10(%r14),%xmm0
xorpd  %xmm2,%xmm2
ucomisd %xmm0,%xmm2
movsd  0x10(%r15),%xmm1
movsd  %xmm3,0x8(%rsp)
jae    125b <logdet+0x12b>
ucomisd %xmm1,%xmm2
jb     1272 <logdet+0x142>
lea    0xdb6(%rip),%rdi
mov    $0x2,%esi
call   1030 <Exit@plt>
movsd  0x10(%r14),%xmm0
call   1040 <log@plt>
mov    %eax,%ebx
movsd  0x10(%r15),%xmm0
call   1040 <log@plt>
lea    (%rax,%rbx,1),%ecx
add    $0x7,%ecx
add    %ebx,%eax
cmovns %eax,%ecx
sar    $0x3,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  0x8(%rsp),%xmm3
addsd  %xmm0,%xmm3
movsd  0x18(%r14),%xmm0
xorpd  %xmm2,%xmm2
ucomisd %xmm0,%xmm2
movsd  0x18(%r15),%xmm1
movsd  %xmm3,0x8(%rsp)
jae    12c5 <logdet+0x195>
ucomisd %xmm1,%xmm2
jb     12dc <logdet+0x1ac>
lea    0xd4c(%rip),%rdi
mov    $0x3,%esi
call   1030 <Exit@plt>
movsd  0x18(%r14),%xmm0
call   1040 <log@plt>
mov    %eax,%ebx
movsd  0x18(%r15),%xmm0
call   1040 <log@plt>
lea    (%rax,%rbx,1),%ecx
add    $0x7,%ecx
add    %ebx,%eax
cmovns %eax,%ecx
sar    $0x3,%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
movsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
jmp    1317 <logdet+0x1e7>
movsd  0xce9(%rip),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [56 x i8] c"Logdet value of Pi1[i] is %f, of Pi2[i] is %f, i is %d.\00"
define double @logdet(double** %0, double* %1, double* %2) {
%4 = alloca double
%5 = alloca double**
%6 = alloca double*
%7 = alloca double*
%8 = alloca i32
%9 = alloca double
%10 = alloca double
store double** %0, double*** %5
store double* %1, double** %6
store double* %2, double** %7
%11 = load double**, double*** %5
%12 = call double @det(double** %11, i32 4)
store double %12, double* %10
%13 = load double, double* %10
%14 = fcmp oge double 0.000000e+00, %13
br i1 %14, label %15, label %16
15: ; preds = %3
store double 5.000000e+00, double* %4
br label %74
16: ; preds = %3
%17 = load double, double* %10
%18 = call i32 @log(double %17)
%19 = sitofp i32 %18 to double
%20 = fmul double -5.000000e-01, %19
store double %20, double* %9
store i32 0, i32* %8
br label %21
21: ; preds = %69, %16
%22 = load i32, i32* %8
%23 = icmp slt i32 %22, 4
br i1 %23, label %24, label %72
24: ; preds = %21
%25 = load double*, double** %6
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %25, i64 %27
%29 = load double, double* %28
%30 = fcmp oge double 0.000000e+00, %29
br i1 %30, label %38, label %31
31: ; preds = %24
%32 = load double*, double** %7
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
%36 = load double, double* %35
%37 = fcmp oge double 0.000000e+00, %36
br i1 %37, label %38, label %51
38: ; preds = %31, %24
%39 = load double*, double** %6
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %39, i64 %41
%43 = load double, double* %42
%44 = load double*, double** %7
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %44, i64 %46
%48 = load double, double* %47
%49 = load i32, i32* %8
%50 = call i32 @Exit(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), double %43, double %48, i32 %49)
br label %51
51: ; preds = %38, %31
%52 = load double*, double** %6
%53 = load i32, i32* %8
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %52, i64 %54
%56 = load double, double* %55
%57 = call i32 @log(double %56)
%58 = load double*, double** %7
%59 = load i32, i32* %8
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %58, i64 %60
%62 = load double, double* %61
%63 = call i32 @log(double %62)
%64 = add nsw i32 %57, %63
%65 = sdiv i32 %64, 8
%66 = sitofp i32 %65 to double
%67 = load double, double* %9
%68 = fadd double %67, %66
store double %68, double* %9
br label %69
69: ; preds = %51
%70 = load i32, i32* %8
%71 = add nsw i32 %70, 1
store i32 %71, i32* %8
br label %21
72: ; preds = %21
%73 = load double, double* %9
store double %73, double* %4
br label %74
74: ; preds = %72, %15
%75 = load double, double* %4
ret double %75
}

LLVM IR (-O2):
@.str = [56 x i8] c"Logdet value of Pi1[i] is %f, of Pi2[i] is %f, i is %d.\00"
define double @logdet(double** %0, double* nocapture %1, double* nocapture %2) {
%4 = tail call double @det(double** %0, i32 4)
%5 = fcmp ugt double %4, 0.000000e+00
br i1 %5, label %6, label %87
6: ; preds = %3
%7 = tail call i32 @log(double %4)
%8 = sitofp i32 %7 to double
%9 = fmul double %8, -5.000000e-01
%10 = load double, double* %1
%11 = fcmp ugt double %10, 0.000000e+00
%12 = load double, double* %2
%13 = fcmp ugt double %12, 0.000000e+00
%14 = select i1 %11, i1 %13, i1 false
br i1 %14, label %18, label %15
15: ; preds = %6
%16 = tail call i32 @Exit(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), double %10, double %12, i32 0)
%17 = load double, double* %1
br label %18
18: ; preds = %6, %15
%19 = phi double [ %17, %15 ], [ %10, %6 ]
%20 = tail call i32 @log(double %19)
%21 = load double, double* %2
%22 = tail call i32 @log(double %21)
%23 = add nsw i32 %22, %20
%24 = sdiv i32 %23, 8
%25 = sitofp i32 %24 to double
%26 = fadd double %9, %25
%27 = getelementptr inbounds double, double* %1, i64 1
%28 = load double, double* %27
%29 = fcmp ugt double %28, 0.000000e+00
%30 = getelementptr inbounds double, double* %2, i64 1
%31 = load double, double* %30
%32 = fcmp ugt double %31, 0.000000e+00
%33 = select i1 %29, i1 %32, i1 false
br i1 %33, label %37, label %34
34: ; preds = %18
%35 = tail call i32 @Exit(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), double %28, double %31, i32 1)
%36 = load double, double* %27
br label %37
37: ; preds = %18, %34
%38 = phi double [ %36, %34 ], [ %28, %18 ]
%39 = tail call i32 @log(double %38)
%40 = getelementptr inbounds double, double* %2, i64 1
%41 = load double, double* %40
%42 = tail call i32 @log(double %41)
%43 = add nsw i32 %42, %39
%44 = sdiv i32 %43, 8
%45 = sitofp i32 %44 to double
%46 = fadd double %26, %45
%47 = getelementptr inbounds double, double* %1, i64 2
%48 = load double, double* %47
%49 = fcmp ugt double %48, 0.000000e+00
%50 = getelementptr inbounds double, double* %2, i64 2
%51 = load double, double* %50
%52 = fcmp ugt double %51, 0.000000e+00
%53 = select i1 %49, i1 %52, i1 false
br i1 %53, label %57, label %54
54: ; preds = %37
%55 = tail call i32 @Exit(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), double %48, double %51, i32 2)
%56 = load double, double* %47
br label %57
57: ; preds = %37, %54
%58 = phi double [ %56, %54 ], [ %48, %37 ]
%59 = tail call i32 @log(double %58)
%60 = getelementptr inbounds double, double* %2, i64 2
%61 = load double, double* %60
%62 = tail call i32 @log(double %61)
%63 = add nsw i32 %62, %59
%64 = sdiv i32 %63, 8
%65 = sitofp i32 %64 to double
%66 = fadd double %46, %65
%67 = getelementptr inbounds double, double* %1, i64 3
%68 = load double, double* %67
%69 = fcmp ugt double %68, 0.000000e+00
%70 = getelementptr inbounds double, double* %2, i64 3
%71 = load double, double* %70
%72 = fcmp ugt double %71, 0.000000e+00
%73 = select i1 %69, i1 %72, i1 false
br i1 %73, label %77, label %74
74: ; preds = %57
%75 = tail call i32 @Exit(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), double %68, double %71, i32 3)
%76 = load double, double* %67
br label %77
77: ; preds = %57, %74
%78 = phi double [ %76, %74 ], [ %68, %57 ]
%79 = tail call i32 @log(double %78)
%80 = getelementptr inbounds double, double* %2, i64 3
%81 = load double, double* %80
%82 = tail call i32 @log(double %81)
%83 = add nsw i32 %82, %79
%84 = sdiv i32 %83, 8
%85 = sitofp i32 %84 to double
%86 = fadd double %66, %85
br label %87
87: ; preds = %77, %3
%88 = phi double [ 5.000000e+00, %3 ], [ %86, %77 ]
ret double %88
}