#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 h1(int **);
double h2(int **);
double h3(int **);
int h4(int m[4][4], double p1, double p2, double p3) {
  int answer;
  if (p1 + p2 + p3 != 1) {
    answer = -1;
  } else {
    int r1 = p1 * h1(m);
    int r2 = p2 * h2(m);
    int r3 = p3 * h3(m);
    answer = r1 + r2 + r3;
  }
  return answer;
}


x86 assembly (clang, -O0):
<h4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  0xe9e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1177 <h4+0x47>
jp     1177 <h4+0x47>
jmp    1183 <h4+0x53>
movl   $0xffffffff,-0x24(%rbp)
jmp    1201 <h4+0xd1>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <h1@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <h2@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x2c(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <h3@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%eax
add    -0x2c(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<h4>:
push   %rbx
sub    $0x40,%rsp
movapd %xmm0,%xmm3
addsd  %xmm1,%xmm3
addsd  %xmm2,%xmm3
mov    $0xffffffff,%eax
ucomisd 0xeb2(%rip),%xmm3
jne    11bd <h4+0x8d>
jp     11bd <h4+0x8d>
mov    %rdi,%rbx
movsd  %xmm2,0x18(%rsp)
movapd %xmm1,0x30(%rsp)
movapd %xmm0,(%rsp)
call   1050 <h1@plt>
movapd %xmm0,0x20(%rsp)
mov    %rbx,%rdi
call   1030 <h2@plt>
unpcklpd 0x20(%rsp),%xmm0
movapd 0x30(%rsp),%xmm1
unpcklpd (%rsp),%xmm1
mulpd  %xmm0,%xmm1
cvttpd2dq %xmm1,%xmm0
movapd %xmm0,(%rsp)
mov    %rbx,%rdi
call   1040 <h3@plt>
mulsd  0x18(%rsp),%xmm0
cvttsd2si %xmm0,%ecx
movdqa (%rsp),%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%eax
add    %ecx,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @h4([4 x i32]* %0, double %1, double %2, double %3) {
%5 = alloca [4 x i32]*
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store [4 x i32]* %0, [4 x i32]** %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
%13 = load double, double* %6
%14 = load double, double* %7
%15 = fadd double %13, %14
%16 = load double, double* %8
%17 = fadd double %15, %16
%18 = fcmp une double %17, 1.000000e+00
br i1 %18, label %19, label %20
19: ; preds = %4
store i32 -1, i32* %9
br label %44
20: ; preds = %4
%21 = load double, double* %6
%22 = load [4 x i32]*, [4 x i32]** %5
%23 = bitcast [4 x i32]* %22 to i32**
%24 = call double @h1(i32** %23)
%25 = fmul double %21, %24
%26 = fptosi double %25 to i32
store i32 %26, i32* %10
%27 = load double, double* %7
%28 = load [4 x i32]*, [4 x i32]** %5
%29 = bitcast [4 x i32]* %28 to i32**
%30 = call double @h2(i32** %29)
%31 = fmul double %27, %30
%32 = fptosi double %31 to i32
store i32 %32, i32* %11
%33 = load double, double* %8
%34 = load [4 x i32]*, [4 x i32]** %5
%35 = bitcast [4 x i32]* %34 to i32**
%36 = call double @h3(i32** %35)
%37 = fmul double %33, %36
%38 = fptosi double %37 to i32
store i32 %38, i32* %12
%39 = load i32, i32* %10
%40 = load i32, i32* %11
%41 = add nsw i32 %39, %40
%42 = load i32, i32* %12
%43 = add nsw i32 %41, %42
store i32 %43, i32* %9
br label %44
44: ; preds = %20, %19
%45 = load i32, i32* %9
ret i32 %45
}

LLVM IR (-O2):
define i32 @h4([4 x i32]* %0, double %1, double %2, double %3) {
%5 = fadd double %1, %2
%6 = fadd double %5, %3
%7 = fcmp une double %6, 1.000000e+00
br i1 %7, label %25, label %8
8: ; preds = %4
%9 = bitcast [4 x i32]* %0 to i32**
%10 = tail call double @h1(i32** %9)
%11 = tail call double @h2(i32** %9)
%12 = insertelement <2 x double> poison, double %11, i64 0
%13 = insertelement <2 x double> %12, double %10, i64 1
%14 = insertelement <2 x double> poison, double %2, i64 0
%15 = insertelement <2 x double> %14, double %1, i64 1
%16 = fmul <2 x double> %13, %15
%17 = fptosi <2 x double> %16 to <2 x i32>
%18 = tail call double @h3(i32** %9)
%19 = fmul double %18, %3
%20 = fptosi double %19 to i32
%21 = shufflevector <2 x i32> %17, <2 x i32> poison, <2 x i32> <i32 1, i32 undef>
%22 = add nsw <2 x i32> %21, %17
%23 = extractelement <2 x i32> %22, i64 0
%24 = add nsw i32 %23, %20
br label %25
25: ; preds = %4, %8
%26 = phi i32 [ %24, %8 ], [ -1, %4 ]
ret i32 %26
}