#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 best_wf(int, int, int, int, int *, double *);
double cout_total(int, int, int, int /*<<< orphan*/, int /*<<< orphan*/);
double workfactor(int n, int k, int t) {
  int p, l, lmin, pmin;
  double min, lwf, mem, memmin;
  pmin = 1;
  min = cout_total(n, k, t, 0, 0);
  lmin = 0;
  memmin = 0;
  for (p = pmin; p <= t / 2; ++p) {
    lwf = best_wf(n, k + 1, t, p, &l, &mem);
    if (lwf < 0)
      break;
    if ((min == 0) || (lwf < min)) {
      min = lwf;
      pmin = p;
      lmin = l;
      memmin = mem;
    }
    if (p >= pmin + 2)
      break;
  }
  return min;
}


x86 assembly (clang, -O0):
<workfactor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1040 <cout_total@plt>
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
cmp    %ecx,%eax
jg     1232 <workfactor+0x112>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
add    $0x1,%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    -0x14(%rbp),%r8
lea    -0x38(%rbp),%r9
call   1030 <best_wf@plt>
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    11b8 <workfactor+0x98>
jmp    1232 <workfactor+0x112>
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11d5 <workfactor+0xb5>
jp     11d5 <workfactor+0xb5>
jmp    11e9 <workfactor+0xc9>
movsd  -0x30(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1209 <workfactor+0xe9>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jl     121f <workfactor+0xff>
jmp    1232 <workfactor+0x112>
jmp    1224 <workfactor+0x104>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1166 <workfactor+0x46>
movsd  -0x28(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<workfactor>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
mov    %esi,%r15d
mov    %edi,%r14d
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <cout_total@plt>
movapd %xmm0,%xmm1
cmp    $0x2,%ebx
jge    1152 <workfactor+0x32>
movapd %xmm1,%xmm0
jmp    11d9 <workfactor+0xb9>
add    $0x1,%r15d
mov    %ebx,%r12d
shr    %r12d
mov    $0x1,%ebp
mov    $0x1,%r13d
nopw   0x0(%rax,%rax,1)
movsd  %xmm1,(%rsp)
mov    %r14d,%edi
mov    %r15d,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
lea    0xc(%rsp),%r8
lea    0x10(%rsp),%r9
call   1030 <best_wf@plt>
xorpd  %xmm2,%xmm2
ucomisd %xmm0,%xmm2
ja     11d4 <workfactor+0xb4>
movsd  (%rsp),%xmm1
ucomisd %xmm2,%xmm1
setnp  %al
sete   %cl
and    %al,%cl
ucomisd %xmm0,%xmm1
seta   %al
or     %cl,%al
cmovne %ebp,%r13d
jne    11bc <workfactor+0x9c>
movapd %xmm1,%xmm0
lea    0x2(%r13),%eax
cmp    %eax,%ebp
jge    11d9 <workfactor+0xb9>
lea    0x1(%rbp),%eax
movapd %xmm0,%xmm1
cmp    %ebp,%r12d
mov    %eax,%ebp
jne    1170 <workfactor+0x50>
jmp    11d9 <workfactor+0xb9>
movsd  (%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @workfactor(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 1, i32* %10
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = call double @cout_total(i32 %15, i32 %16, i32 %17, i32 0, i32 0)
store double %18, double* %11
store i32 0, i32* %9
store double 0.000000e+00, double* %14
%19 = load i32, i32* %10
store i32 %19, i32* %7
br label %20
20: ; preds = %54, %3
%21 = load i32, i32* %7
%22 = load i32, i32* %6
%23 = sdiv i32 %22, 2
%24 = icmp sle i32 %21, %23
br i1 %24, label %25, label %57
25: ; preds = %20
%26 = load i32, i32* %4
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
%29 = load i32, i32* %6
%30 = load i32, i32* %7
%31 = call double @best_wf(i32 %26, i32 %28, i32 %29, i32 %30, i32* %8, double* %13)
store double %31, double* %12
%32 = load double, double* %12
%33 = fcmp olt double %32, 0.000000e+00
br i1 %33, label %34, label %35
34: ; preds = %25
br label %57
35: ; preds = %25
%36 = load double, double* %11
%37 = fcmp oeq double %36, 0.000000e+00
br i1 %37, label %42, label %38
38: ; preds = %35
%39 = load double, double* %12
%40 = load double, double* %11
%41 = fcmp olt double %39, %40
br i1 %41, label %42, label %47
42: ; preds = %38, %35
%43 = load double, double* %12
store double %43, double* %11
%44 = load i32, i32* %7
store i32 %44, i32* %10
%45 = load i32, i32* %8
store i32 %45, i32* %9
%46 = load double, double* %13
store double %46, double* %14
br label %47
47: ; preds = %42, %38
%48 = load i32, i32* %7
%49 = load i32, i32* %10
%50 = add nsw i32 %49, 2
%51 = icmp sge i32 %48, %50
br i1 %51, label %52, label %53
52: ; preds = %47
br label %57
53: ; preds = %47
br label %54
54: ; preds = %53
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
br label %20
57: ; preds = %52, %34, %20
%58 = load double, double* %11
ret double %58
}

LLVM IR (-O2):
define double @workfactor(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca double
%6 = bitcast i32* %4 to i8*
%7 = bitcast double* %5 to i8*
%8 = tail call double @cout_total(i32 %0, i32 %1, i32 %2, i32 0, i32 0)
%9 = add nsw i32 %1, 1
%10 = icmp slt i32 %2, 2
br i1 %10, label %30, label %11
11: ; preds = %3
%12 = lshr i32 %2, 1
br label %13
13: ; preds = %19, %11
%14 = phi i32 [ 1, %11 ], [ %27, %19 ]
%15 = phi double [ %8, %11 ], [ %24, %19 ]
%16 = phi i32 [ 1, %11 ], [ %23, %19 ]
%17 = call double @best_wf(i32 %0, i32 %9, i32 %2, i32 %14, i32* %4, double* %5)
%18 = fcmp olt double %17, 0.000000e+00
br i1 %18, label %30, label %19
19: ; preds = %13
%20 = fcmp oeq double %15, 0.000000e+00
%21 = fcmp olt double %17, %15
%22 = select i1 %20, i1 true, i1 %21
%23 = select i1 %22, i32 %14, i32 %16
%24 = select i1 %22, double %17, double %15
%25 = add nsw i32 %23, 2
%26 = icmp sge i32 %14, %25
%27 = add nuw nsw i32 %14, 1
%28 = icmp eq i32 %14, %12
%29 = or i1 %26, %28
br i1 %29, label %30, label %13
30: ; preds = %13, %19, %3
%31 = phi double [ %8, %3 ], [ %24, %19 ], [ %15, %13 ]
ret double %31
}