#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 fabs(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, double, double, int);
int /*<<< orphan*/ stdout;
double brute(double (*f)(double), double a, double b, double eps) {
  int i, n;
  double x, xmin = 1e6, fx, fxmin = 1e6;
  n = (int)((b - a) / eps);
  for (i = 0; i < n; i++) {
    x = a + (i * eps);
    fx = f(x);
    if (fabs(fx) < fxmin) {
      fxmin = fabs(fx);
      xmin = x;
    }
  }
  fprintf(stdout, "Brute: %f %f %d\n", fxmin, xmin, i);
  return xmin;
}


x86 assembly (clang, -O0):
<brute>:
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  0xecd(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xec0(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11eb <brute+0xdb>
movsd  -0x10(%rbp),%xmm1
cvtsi2sdl -0x24(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x30(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm1
movaps 0xe6a(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11d8 <brute+0xc8>
movsd  -0x40(%rbp),%xmm0
movaps 0xe4b(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    11dd <brute+0xcd>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1162 <brute+0x52>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
movsd  -0x48(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
mov    -0x24(%rbp),%edx
lea    0xe18(%rip),%rsi
call   1030 <fprintf@plt>
movsd  -0x38(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<brute>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
subsd  %xmm0,%xmm1
divsd  %xmm2,%xmm1
cvttsd2si %xmm1,%r14d
test   %r14d,%r14d
jle    11d4 <brute+0xc4>
movapd %xmm0,%xmm3
mov    %rdi,%rbx
xorpd  %xmm4,%xmm4
movsd  0xebf(%rip),%xmm0
mov    %r14d,%ebp
movapd %xmm0,%xmm1
movsd  %xmm2,0x18(%rsp)
movsd  %xmm3,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movapd %xmm1,(%rsp)
movsd  %xmm4,0x28(%rsp)
movsd  %xmm0,0x20(%rsp)
movapd %xmm4,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm3,%xmm0
movapd %xmm0,0x30(%rsp)
call   *%rbx
movsd  0x28(%rsp),%xmm4
movsd  0x10(%rsp),%xmm3
movsd  0x18(%rsp),%xmm2
andpd  0xe71(%rip),%xmm0
movapd %xmm0,%xmm1
movsd  0x20(%rsp),%xmm5
cmpltsd %xmm5,%xmm1
movapd 0x30(%rsp),%xmm6
andpd  %xmm1,%xmm6
andnpd (%rsp),%xmm1
orpd   %xmm6,%xmm1
minsd  %xmm5,%xmm0
addsd  0xe3b(%rip),%xmm4
add    $0xffffffff,%ebp
jne    1160 <brute+0x50>
jmp    11e3 <brute+0xd3>
xor    %r14d,%r14d
movsd  0xe21(%rip),%xmm1
movapd %xmm1,%xmm0
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
lea    0xe2d(%rip),%rsi
movapd %xmm1,(%rsp)
mov    %r14d,%edx
call   1030 <fprintf@plt>
movaps (%rsp),%xmm0
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [17 x i8] c"Brute: %f %f %d\0A\00"
define double @brute(double (double)* %0, double %1, double %2, double %3) {
%5 = alloca double (double)*
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
store double (double)* %0, double (double)** %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
store double 1.000000e+06, double* %12
store double 1.000000e+06, double* %14
%15 = load double, double* %7
%16 = load double, double* %6
%17 = fsub double %15, %16
%18 = load double, double* %8
%19 = fdiv double %17, %18
%20 = fptosi double %19 to i32
store i32 %20, i32* %10
store i32 0, i32* %9
br label %21
21: ; preds = %43, %4
%22 = load i32, i32* %9
%23 = load i32, i32* %10
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %46
25: ; preds = %21
%26 = load double, double* %6
%27 = load i32, i32* %9
%28 = sitofp i32 %27 to double
%29 = load double, double* %8
%30 = call double @llvm.fmuladd.f64(double %28, double %29, double %26)
store double %30, double* %11
%31 = load double (double)*, double (double)** %5
%32 = load double, double* %11
%33 = call double %31(double %32)
store double %33, double* %13
%34 = load double, double* %13
%35 = call double @llvm.fabs.f64(double %34)
%36 = load double, double* %14
%37 = fcmp olt double %35, %36
br i1 %37, label %38, label %42
38: ; preds = %25
%39 = load double, double* %13
%40 = call double @llvm.fabs.f64(double %39)
store double %40, double* %14
%41 = load double, double* %11
store double %41, double* %12
br label %42
42: ; preds = %38, %25
br label %43
43: ; preds = %42
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
store i32 %45, i32* %9
br label %21
46: ; preds = %21
%47 = load i32, i32* @stdout
%48 = load double, double* %14
%49 = load double, double* %12
%50 = load i32, i32* %9
%51 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), double %48, double %49, i32 %50)
%52 = load double, double* %12
ret double %52
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [17 x i8] c"Brute: %f %f %d\0A\00"
define double @brute(double (double)* nocapture %0, double %1, double %2, double %3) {
%5 = fsub double %2, %1
%6 = fdiv double %5, %3
%7 = fptosi double %6 to i32
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %22
9: ; preds = %4, %9
%10 = phi double [ %19, %9 ], [ 1.000000e+06, %4 ]
%11 = phi i32 [ %20, %9 ], [ 0, %4 ]
%12 = phi double [ %18, %9 ], [ 1.000000e+06, %4 ]
%13 = sitofp i32 %11 to double
%14 = tail call double @llvm.fmuladd.f64(double %13, double %3, double %1)
%15 = tail call double %0(double %14)
%16 = tail call double @llvm.fabs.f64(double %15)
%17 = fcmp olt double %16, %10
%18 = select i1 %17, double %14, double %12
%19 = select i1 %17, double %16, double %10
%20 = add nuw nsw i32 %11, 1
%21 = icmp eq i32 %20, %7
br i1 %21, label %22, label %9
22: ; preds = %9, %4
%23 = phi double [ 1.000000e+06, %4 ], [ %18, %9 ]
%24 = phi i32 [ 0, %4 ], [ %7, %9 ]
%25 = phi double [ 1.000000e+06, %4 ], [ %19, %9 ]
%26 = load i32, i32* @stdout
%27 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), double %25, double %23, i32 %24)
ret double %23
}