#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 */
size_t maximise(double (*f)(size_t), size_t min_n, size_t max_n) {
  size_t n, best_n = 0;
  double f_n, f_best_n = -1.0;
  for (n = min_n; n < max_n; n++) {
    f_n = f(n);
    if (f_n > f_best_n) {
      f_best_n = f_n;
      best_n = n;
    }
  }
  return best_n;
}


x86 assembly (clang, -O0):
<maximise>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movsd  0xedc(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1186 <maximise+0x86>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rdi
call   *%rax
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    1170 <maximise+0x70>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1175 <maximise+0x75>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1131 <maximise+0x31>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<maximise>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    %rdx,%rsi
jae    1157 <maximise+0x57>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r12
movsd  0xee2(%rip),%xmm0
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
call   *%r12
movsd  (%rsp),%xmm1
ucomisd %xmm1,%xmm0
cmova  %rbx,%r15
maxsd  %xmm1,%xmm0
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1130 <maximise+0x30>
jmp    115a <maximise+0x5a>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @maximise(double (i64)* %0, i64 %1, i64 %2) {
%4 = alloca double (i64)*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca double
%10 = alloca double
store double (i64)* %0, double (i64)** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
store i64 0, i64* %8
store double -1.000000e+00, double* %10
%11 = load i64, i64* %5
store i64 %11, i64* %7
br label %12
12: ; preds = %27, %3
%13 = load i64, i64* %7
%14 = load i64, i64* %6
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %30
16: ; preds = %12
%17 = load double (i64)*, double (i64)** %4
%18 = load i64, i64* %7
%19 = call double %17(i64 %18)
store double %19, double* %9
%20 = load double, double* %9
%21 = load double, double* %10
%22 = fcmp ogt double %20, %21
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = load double, double* %9
store double %24, double* %10
%25 = load i64, i64* %7
store i64 %25, i64* %8
br label %26
26: ; preds = %23, %16
br label %27
27: ; preds = %26
%28 = load i64, i64* %7
%29 = add i64 %28, 1
store i64 %29, i64* %7
br label %12
30: ; preds = %12
%31 = load i64, i64* %8
ret i64 %31
}

LLVM IR (-O2):
define i64 @maximise(double (i64)* nocapture %0, i64 %1, i64 %2) {
%4 = icmp ult i64 %1, %2
br i1 %4, label %5, label %15
5: ; preds = %3, %5
%6 = phi double [ %12, %5 ], [ -1.000000e+00, %3 ]
%7 = phi i64 [ %13, %5 ], [ %1, %3 ]
%8 = phi i64 [ %11, %5 ], [ 0, %3 ]
%9 = tail call double %0(i64 %7)
%10 = fcmp ogt double %9, %6
%11 = select i1 %10, i64 %7, i64 %8
%12 = select i1 %10, double %9, double %6
%13 = add i64 %7, 1
%14 = icmp eq i64 %13, %2
br i1 %14, label %15, label %5
15: ; preds = %5, %3
%16 = phi i64 [ 0, %3 ], [ %11, %5 ]
ret i64 %16
}