#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 log10(double);
double vp8_mse2psnr(double samples, double peak, double mse) {
  const int kMaxPSNR = 100;
  double psnr = kMaxPSNR;
  if (mse > 0.0)
    psnr = 10.0 * log10(peak * peak * samples / mse);
  if (psnr > kMaxPSNR)
    psnr = kMaxPSNR;
  return psnr;
}


x86 assembly (clang, -O0):
<vp8_mse2psnr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movl   $0x64,-0x1c(%rbp)
movsd  0xeca(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    117a <vp8_mse2psnr+0x6a>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1030 <log10@plt>
movaps %xmm0,%xmm1
movsd  0xe97(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xe79(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    119e <vp8_mse2psnr+0x8e>
movsd  0xe67(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vp8_mse2psnr>:
push   %rax
movsd  0xee7(%rip),%xmm4
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm2
movapd %xmm4,%xmm3
jbe    1150 <vp8_mse2psnr+0x40>
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm1
divsd  %xmm2,%xmm1
movapd %xmm1,%xmm0
call   1030 <log10@plt>
movsd  0xebc(%rip),%xmm4
movapd %xmm0,%xmm3
mulsd  0xeb8(%rip),%xmm3
minsd  %xmm3,%xmm4
movapd %xmm4,%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @vp8_mse2psnr(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca double
store double %0, double* %4
store double %1, double* %5
store double %2, double* %6
store i32 100, i32* %7
store double 1.000000e+02, double* %8
%9 = load double, double* %6
%10 = fcmp ogt double %9, 0.000000e+00
br i1 %10, label %11, label %21
11: ; preds = %3
%12 = load double, double* %5
%13 = load double, double* %5
%14 = fmul double %12, %13
%15 = load double, double* %4
%16 = fmul double %14, %15
%17 = load double, double* %6
%18 = fdiv double %16, %17
%19 = call double @log10(double %18)
%20 = fmul double 1.000000e+01, %19
store double %20, double* %8
br label %21
21: ; preds = %11, %3
%22 = load double, double* %8
%23 = fcmp ogt double %22, 1.000000e+02
br i1 %23, label %24, label %25
24: ; preds = %21
store double 1.000000e+02, double* %8
br label %25
25: ; preds = %24, %21
%26 = load double, double* %8
ret double %26
}

LLVM IR (-O2):
define double @vp8_mse2psnr(double %0, double %1, double %2) {
%4 = fcmp ogt double %2, 0.000000e+00
br i1 %4, label %5, label %11
5: ; preds = %3
%6 = fmul double %1, %1
%7 = fmul double %6, %0
%8 = fdiv double %7, %2
%9 = tail call double @log10(double %8)
%10 = fmul double %9, 1.000000e+01
br label %11
11: ; preds = %5, %3
%12 = phi double [ %10, %5 ], [ 1.000000e+02, %3 ]
%13 = fcmp ogt double %12, 1.000000e+02
%14 = select i1 %13, double 1.000000e+02, double %12
ret double %14
}