#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 func1(double);
double func2(double);
double getabs(double);
int pow(int, int);
int /*<<< orphan*/ printf(char *, double);
main() {
  double x = -1.0;
  int i = 1;
  int sign;
  double y1, y2, delta, currentDelta;
  double previousDelta = 1.0;
  double finalDelta = pow(10, -12);
  while (1) {
    currentDelta = pow(10, -1 * i);
    y1 = func1(x);
    y2 = func2(x);
    delta = getabs(y1 - y2);
    if (delta < finalDelta) {
      printf("%.12lf\n", y1);
      break;
    }
    if (delta < currentDelta) {
      i++;
    }
    if (previousDelta > delta) {
      sign = 1;
    } else {
      sign = -1;
    }
    x += sign * pow(10, -1 * (i + 1));
    previousDelta = delta;
    if (x > 0) {
      break;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xea1(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movsd  0xe85(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    $0xa,%edi
mov    $0xfffffff4,%esi
call   1070 <pow@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x48(%rbp)
imul   $0xffffffff,-0x14(%rbp),%esi
mov    $0xa,%edi
call   1070 <pow@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <func1@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <func2@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
call   1040 <getabs@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    120e <main+0xbe>
movsd  -0x20(%rbp),%xmm0
lea    0xe0c(%rip),%rdi
call   1050 <printf@plt>
jmp    12a6 <main+0x156>
movsd  -0x30(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    122b <main+0xdb>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movsd  -0x40(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    1247 <main+0xf7>
movl   $0x1,-0x18(%rbp)
jmp    124e <main+0xfe>
movl   $0xffffffff,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
imul   $0xffffffff,%eax,%esi
mov    $0xa,%edi
call   1070 <pow@plt>
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    12a1 <main+0x151>
jmp    12a6 <main+0x156>
jmp    1198 <main+0x48>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    $0xa,%edi
mov    $0xfffffff4,%esi
call   1070 <pow@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0xe89(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0xe83(%rip),%xmm0
mov    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x20(%rsp)
mov    %ebp,%esi
neg    %esi
mov    $0xa,%edi
call   1070 <pow@plt>
mov    %eax,%ebx
movsd  0x10(%rsp),%xmm0
call   1030 <func1@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1060 <func2@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1040 <getabs@plt>
movapd %xmm0,%xmm1
movsd  0x18(%rsp),%xmm0
ucomisd %xmm1,%xmm0
ja     124d <main+0xfd>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
xor    %eax,%eax
ucomisd %xmm1,%xmm0
seta   %al
add    %eax,%ebp
mov    %ebp,%esi
not    %esi
mov    $0xa,%edi
movsd  %xmm1,0x8(%rsp)
call   1070 <pow@plt>
mov    %eax,%ecx
neg    %ecx
movsd  0x20(%rsp),%xmm0
movsd  0x8(%rsp),%xmm2
ucomisd %xmm2,%xmm0
cmova  %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
ucomisd 0xdcf(%rip),%xmm1
movapd %xmm2,%xmm0
jbe    1190 <main+0x40>
jmp    125f <main+0x10f>
lea    0xdc4(%rip),%rdi
movsd  0x8(%rsp),%xmm0
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%.12lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store i32 0, i32* %1
store double -1.000000e+00, double* %2
store i32 1, i32* %3
store double 1.000000e+00, double* %9
%11 = call i32 @pow(i32 10, i32 -12)
%12 = sitofp i32 %11 to double
store double %12, double* %10
br label %13
13: ; preds = %0, %59
%14 = load i32, i32* %3
%15 = mul nsw i32 -1, %14
%16 = call i32 @pow(i32 10, i32 %15)
%17 = sitofp i32 %16 to double
store double %17, double* %8
%18 = load double, double* %2
%19 = call double @func1(double %18)
store double %19, double* %5
%20 = load double, double* %2
%21 = call double @func2(double %20)
store double %21, double* %6
%22 = load double, double* %5
%23 = load double, double* %6
%24 = fsub double %22, %23
%25 = call double @getabs(double %24)
store double %25, double* %7
%26 = load double, double* %7
%27 = load double, double* %10
%28 = fcmp olt double %26, %27
br i1 %28, label %29, label %32
29: ; preds = %13
%30 = load double, double* %5
%31 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %30)
br label %60
32: ; preds = %13
%33 = load double, double* %7
%34 = load double, double* %8
%35 = fcmp olt double %33, %34
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 1
store i32 %38, i32* %3
br label %39
39: ; preds = %36, %32
%40 = load double, double* %9
%41 = load double, double* %7
%42 = fcmp ogt double %40, %41
br i1 %42, label %43, label %44
43: ; preds = %39
store i32 1, i32* %4
br label %45
44: ; preds = %39
store i32 -1, i32* %4
br label %45
45: ; preds = %44, %43
%46 = load i32, i32* %4
%47 = load i32, i32* %3
%48 = add nsw i32 %47, 1
%49 = mul nsw i32 -1, %48
%50 = call i32 @pow(i32 10, i32 %49)
%51 = mul nsw i32 %46, %50
%52 = sitofp i32 %51 to double
%53 = load double, double* %2
%54 = fadd double %53, %52
store double %54, double* %2
%55 = load double, double* %7
store double %55, double* %9
%56 = load double, double* %2
%57 = fcmp ogt double %56, 0.000000e+00
br i1 %57, label %58, label %59
58: ; preds = %45
br label %60
59: ; preds = %45
br label %13
60: ; preds = %58, %29
%61 = load i32, i32* %1
ret i32 %61
}

LLVM IR (-O2):
@.str = [8 x i8] c"%.12lf\0A\00"
define i32 @main() {
%1 = tail call i32 @pow(i32 10, i32 -12)
%2 = sitofp i32 %1 to double
br label %3
3: ; preds = %16, %0
%4 = phi i32 [ 1, %0 ], [ %20, %16 ]
%5 = phi double [ 1.000000e+00, %0 ], [ %12, %16 ]
%6 = phi double [ -1.000000e+00, %0 ], [ %27, %16 ]
%7 = sub nsw i32 0, %4
%8 = tail call i32 @pow(i32 10, i32 %7)
%9 = tail call double @func1(double %6)
%10 = tail call double @func2(double %6)
%11 = fsub double %9, %10
%12 = tail call double @getabs(double %11)
%13 = fcmp olt double %12, %2
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %9)
br label %29
16: ; preds = %3
%17 = sitofp i32 %8 to double
%18 = fcmp olt double %12, %17
%19 = zext i1 %18 to i32
%20 = add nuw nsw i32 %4, %19
%21 = fcmp ogt double %5, %12
%22 = xor i32 %20, -1
%23 = tail call i32 @pow(i32 10, i32 %22)
%24 = sub nsw i32 0, %23
%25 = select i1 %21, i32 %23, i32 %24
%26 = sitofp i32 %25 to double
%27 = fadd double %6, %26
%28 = fcmp ogt double %27, 0.000000e+00
br i1 %28, label %29, label %3
29: ; preds = %16, %14
ret i32 0
}