#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_new_8x8IntraBlocks(int, double, int *);
scalar_t__ floor(double);
int Mode_Decision_for_new_Intra8x8Macroblock(double lambda, int *min_cost) {
  int cbp = 0, b8, cost8x8;
  *min_cost = (int)floor(6.0 * lambda + 0.4999);
  for (b8 = 0; b8 < 4; b8++) {
    if (Mode_Decision_for_new_8x8IntraBlocks(b8, lambda, &cost8x8)) {
      cbp |= (1 << b8);
    }
    *min_cost += cost8x8;
  }
  return cbp;
}


x86 assembly (clang, -O0):
<Mode_Decision_for_new_Intra8x8Macroblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xebb(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xeb7(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1040 <floor@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    11b7 <Mode_Decision_for_new_Intra8x8Macroblock+0x97>
mov    -0x18(%rbp),%edi
movsd  -0x8(%rbp),%xmm0
lea    -0x1c(%rbp),%rsi
call   1030 <Mode_Decision_for_new_8x8IntraBlocks@plt>
cmp    $0x0,%rax
je     119e <Mode_Decision_for_new_Intra8x8Macroblock+0x7e>
mov    -0x18(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1169 <Mode_Decision_for_new_Intra8x8Macroblock+0x49>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Mode_Decision_for_new_Intra8x8Macroblock>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
movapd %xmm0,%xmm1
movsd  %xmm0,0x8(%rsp)
movsd  0xec2(%rip),%xmm0
mulsd  %xmm1,%xmm0
addsd  0xebe(%rip),%xmm0
call   1040 <floor@plt>
mov    %eax,(%r15)
lea    0x4(%rsp),%r14
xor    %edi,%edi
movsd  0x8(%rsp),%xmm0
mov    %r14,%rsi
call   1030 <Mode_Decision_for_new_8x8IntraBlocks@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
mov    0x4(%rsp),%eax
add    %eax,(%r15)
mov    $0x1,%edi
movsd  0x8(%rsp),%xmm0
mov    %r14,%rsi
call   1030 <Mode_Decision_for_new_8x8IntraBlocks@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    (%rbx,%rcx,2),%ebx
mov    0x4(%rsp),%eax
add    %eax,(%r15)
mov    $0x2,%edi
movsd  0x8(%rsp),%xmm0
mov    %r14,%rsi
call   1030 <Mode_Decision_for_new_8x8IntraBlocks@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    (%rbx,%rcx,4),%ebx
mov    0x4(%rsp),%eax
add    %eax,(%r15)
mov    $0x3,%edi
movsd  0x8(%rsp),%xmm0
mov    %r14,%rsi
call   1030 <Mode_Decision_for_new_8x8IntraBlocks@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    (%rbx,%rcx,8),%eax
mov    0x4(%rsp),%ecx
add    %ecx,(%r15)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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