#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 */
scalar_t__ Mode_Decision_for_4x4IntraBlocks(int, int, double, int *);
scalar_t__ floor(double);
int Mode_Decision_for_8x8IntraBlocks(int b8, double lambda, int *cost) {
  int nonzero = 0, b4;
  int cost4x4;
  *cost = (int)floor(6.0 * lambda + 0.4999);
  for (b4 = 0; b4 < 4; b4++) {
    if (Mode_Decision_for_4x4IntraBlocks(b8, b4, lambda, &cost4x4)) {
      nonzero = 1;
    }
    *cost += cost4x4;
  }
  return nonzero;
}


x86 assembly (clang, -O0):
<Mode_Decision_for_8x8IntraBlocks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xeb8(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xeb4(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1040 <floor@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x20(%rbp)
cmpl   $0x4,-0x20(%rbp)
jge    11b4 <Mode_Decision_for_8x8IntraBlocks+0x94>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%esi
movsd  -0x10(%rbp),%xmm0
lea    -0x24(%rbp),%rdx
call   1030 <Mode_Decision_for_4x4IntraBlocks@plt>
cmp    $0x0,%rax
je     119b <Mode_Decision_for_8x8IntraBlocks+0x7b>
movl   $0x1,-0x1c(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    116c <Mode_Decision_for_8x8IntraBlocks+0x4c>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Mode_Decision_for_8x8IntraBlocks>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
movapd %xmm0,%xmm1
movsd  %xmm0,0x10(%rsp)
mov    %edi,%ebp
movsd  0xebb(%rip),%xmm0
mulsd  %xmm1,%xmm0
addsd  0xeb7(%rip),%xmm0
call   1040 <floor@plt>
mov    %eax,(%rbx)
lea    0xc(%rsp),%r15
mov    %ebp,%edi
xor    %esi,%esi
movsd  0x10(%rsp),%xmm0
mov    %r15,%rdx
call   1030 <Mode_Decision_for_4x4IntraBlocks@plt>
mov    %rax,%r14
mov    0xc(%rsp),%eax
add    %eax,(%rbx)
mov    %ebp,%edi
mov    $0x1,%esi
movsd  0x10(%rsp),%xmm0
mov    %r15,%rdx
call   1030 <Mode_Decision_for_4x4IntraBlocks@plt>
mov    %rax,%r12
mov    0xc(%rsp),%eax
add    %eax,(%rbx)
mov    %ebp,%edi
mov    $0x2,%esi
movsd  0x10(%rsp),%xmm0
mov    %r15,%rdx
call   1030 <Mode_Decision_for_4x4IntraBlocks@plt>
mov    %rax,%r13
mov    0xc(%rsp),%eax
add    %eax,(%rbx)
mov    %ebp,%edi
mov    $0x3,%esi
movsd  0x10(%rsp),%xmm0
mov    %r15,%rdx
call   1030 <Mode_Decision_for_4x4IntraBlocks@plt>
or     %r13,%rax
or     %r12,%rax
xor    %ecx,%ecx
or     %r14,%rax
setne  %cl
mov    0xc(%rsp),%eax
add    %eax,(%rbx)
mov    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @Mode_Decision_for_8x8IntraBlocks(i32 %0, double %1, i32* %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store double %1, double* %5
store i32* %2, i32** %6
store i32 0, i32* %7
%10 = load double, double* %5
%11 = call double @llvm.fmuladd.f64(double 6.000000e+00, double %10, double 4.999000e-01)
%12 = call i64 @floor(double %11)
%13 = trunc i64 %12 to i32
%14 = load i32*, i32** %6
store i32 %13, i32* %14
store i32 0, i32* %8
br label %15
15: ; preds = %30, %3
%16 = load i32, i32* %8
%17 = icmp slt i32 %16, 4
br i1 %17, label %18, label %33
18: ; preds = %15
%19 = load i32, i32* %4
%20 = load i32, i32* %8
%21 = load double, double* %5
%22 = call i64 @Mode_Decision_for_4x4IntraBlocks(i32 %19, i32 %20, double %21, i32* %9)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %18
store i32 1, i32* %7
br label %25
25: ; preds = %24, %18
%26 = load i32, i32* %9
%27 = load i32*, i32** %6
%28 = load i32, i32* %27
%29 = add nsw i32 %28, %26
store i32 %29, i32* %27
br label %30
30: ; preds = %25
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %15
33: ; preds = %15
%34 = load i32, i32* %7
ret i32 %34
}

LLVM IR (-O2):
define i32 @Mode_Decision_for_8x8IntraBlocks(i32 %0, double %1, i32* nocapture %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call double @llvm.fmuladd.f64(double %1, double 6.000000e+00, double 4.999000e-01)
%7 = tail call i64 @floor(double %6)
%8 = trunc i64 %7 to i32
store i32 %8, i32* %2
%9 = call i64 @Mode_Decision_for_4x4IntraBlocks(i32 %0, i32 0, double %1, i32* %4)
%10 = icmp ne i64 %9, 0
%11 = load i32, i32* %4
%12 = load i32, i32* %2
%13 = add nsw i32 %12, %11
store i32 %13, i32* %2
%14 = call i64 @Mode_Decision_for_4x4IntraBlocks(i32 %0, i32 1, double %1, i32* %4)
%15 = icmp ne i64 %14, 0
%16 = load i32, i32* %4
%17 = load i32, i32* %2
%18 = add nsw i32 %17, %16
store i32 %18, i32* %2
%19 = call i64 @Mode_Decision_for_4x4IntraBlocks(i32 %0, i32 2, double %1, i32* %4)
%20 = icmp ne i64 %19, 0
%21 = load i32, i32* %4
%22 = load i32, i32* %2
%23 = add nsw i32 %22, %21
store i32 %23, i32* %2
%24 = call i64 @Mode_Decision_for_4x4IntraBlocks(i32 %0, i32 3, double %1, i32* %4)
%25 = icmp ne i64 %24, 0
%26 = select i1 %25, i1 true, i1 %20
%27 = select i1 %26, i1 true, i1 %15
%28 = select i1 %27, i1 true, i1 %10
%29 = zext i1 %28 to i32
%30 = load i32, i32* %4
%31 = load i32, i32* %2
%32 = add nsw i32 %31, %30
store i32 %32, i32* %2
ret i32 %29
}