#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 */
int /*<<< orphan*/ exit(int);
double fabs(double);
int /*<<< orphan*/ printf(char *);
void stub1(double, double *, double *);
double rtnewt(void (*funcd)(double, double *, double *), double x1, double x2,
              double xacc) {
  int j;
  double df, dx, f, rtn;
  rtn = 0.5 * (x1 + x2);
  for (j = 0; j < 20; j++) {
    (*funcd)(rtn, &f, &df);
    dx = f / df;
    rtn -= dx;
    if ((x1 - rtn) * (rtn - x2) < 0.0) {
      printf("\n\nError in function rtnewt():");
      printf("\nJump out of interval bracket\n");
      exit(1);
    }
    if (fabs(dx) < xacc)
      return rtn;
  }
  printf("\n\nError in function rtnewt():");
  printf("\nToo many iterations!!!\n");
  exit(1);
}


x86 assembly (clang, -O0):
<rtnewt>:
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  -0x10(%rbp),%xmm1
addsd  -0x18(%rbp),%xmm1
movsd  0xeb3(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x14,-0x24(%rbp)
jge    1220 <rtnewt+0x100>
mov    -0x8(%rbp),%rax
movsd  -0x48(%rbp),%xmm0
lea    -0x40(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   *%rax
movsd  -0x40(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm1
subsd  -0x48(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    11e3 <rtnewt+0xc3>
lea    0xe58(%rip),%rdi
call   1030 <printf@plt>
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
movsd  -0x38(%rbp),%xmm1
movaps 0xe21(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    120d <rtnewt+0xed>
movsd  -0x48(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret
jmp    1212 <rtnewt+0xf2>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115d <rtnewt+0x3d>
lea    0xdf9(%rip),%rdi
call   1030 <printf@plt>
lea    0xe2a(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<rtnewt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
movsd  %xmm2,0x8(%rsp)
mov    %rdi,%rbx
movsd  %xmm0,0x10(%rsp)
movsd  %xmm1,0x18(%rsp)
addsd  %xmm1,%xmm0
mulsd  0xea5(%rip),%xmm0
mov    $0x14,%ebp
lea    0x28(%rsp),%r14
lea    0x30(%rsp),%r15
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x20(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
call   *%rbx
movsd  0x20(%rsp),%xmm0
movsd  0x28(%rsp),%xmm3
divsd  0x30(%rsp),%xmm3
subsd  %xmm3,%xmm0
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm0,%xmm2
subsd  0x18(%rsp),%xmm2
mulsd  %xmm1,%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm2,%xmm1
ja     11ef <rtnewt+0xbf>
andpd  0xe52(%rip),%xmm3
movsd  0x8(%rsp),%xmm1
ucomisd %xmm3,%xmm1
ja     11e4 <rtnewt+0xb4>
add    $0xffffffff,%ebp
jne    1170 <rtnewt+0x40>
lea    0xe4a(%rip),%rdi
call   1040 <printf@plt>
lea    0xe5c(%rip),%rdi
jmp    1202 <rtnewt+0xd2>
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe2a(%rip),%rdi
call   1040 <printf@plt>
lea    0xe54(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"\0A\0AError in function rtnewt():\00"
@.str.1 = [31 x i8] c"\0AJump out of interval bracket\0A\00"
@.str.2 = [25 x i8] c"\0AToo many iterations!!!\0A\00"
define double @rtnewt(void (double, double*, double*)* %0, double %1, double %2, double %3) {
%5 = alloca void (double, double*, double*)*
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
store void (double, double*, double*)* %0, void (double, double*, double*)** %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
%14 = load double, double* %6
%15 = load double, double* %7
%16 = fadd double %14, %15
%17 = fmul double 5.000000e-01, %16
store double %17, double* %13
store i32 0, i32* %9
br label %18
18: ; preds = %50, %4
%19 = load i32, i32* %9
%20 = icmp slt i32 %19, 20
br i1 %20, label %21, label %53
21: ; preds = %18
%22 = load void (double, double*, double*)*, void (double, double*, double*)** %5
%23 = load double, double* %13
%24 = load double, double* %12
%25 = load double, double* %10
%26 = fdiv double %24, %25
store double %26, double* %11
%27 = load double, double* %11
%28 = load double, double* %13
%29 = fsub double %28, %27
store double %29, double* %13
%30 = load double, double* %6
%31 = load double, double* %13
%32 = fsub double %30, %31
%33 = load double, double* %13
%34 = load double, double* %7
%35 = fsub double %33, %34
%36 = fmul double %32, %35
%37 = fcmp olt double %36, 0.000000e+00
br i1 %37, label %38, label %42
38: ; preds = %21
%39 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%40 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %21
%43 = load double, double* %11
%44 = call double @llvm.fabs.f64(double %43)
%45 = load double, double* %8
%46 = fcmp olt double %44, %45
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = load double, double* %13
ret double %48
49: ; preds = %42
br label %50
50: ; preds = %49
%51 = load i32, i32* %9
%52 = add nsw i32 %51, 1
store i32 %52, i32* %9
br label %18
53: ; preds = %18
%54 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%55 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [30 x i8] c"\0A\0AError in function rtnewt():\00"
@str = [24 x i8] c"\0AToo many iterations!!!\00"
@str.3 = [30 x i8] c"\0AJump out of interval bracket\00"
define double @rtnewt(void (double, double*, double*)* nocapture %0, double %1, double %2, double %3) {
%5 = alloca double
%6 = alloca double
%7 = bitcast double* %5 to i8*
%8 = bitcast double* %6 to i8*
%9 = fadd double %1, %2
%10 = fmul double %9, 5.000000e-01
br label %14
11: ; preds = %29
%12 = add nuw nsw i32 %16, 1
%13 = icmp eq i32 %12, 20
br i1 %13, label %33, label %14
14: ; preds = %4, %11
%15 = phi double [ %10, %4 ], [ %20, %11 ]
%16 = phi i32 [ 0, %4 ], [ %12, %11 ]
%17 = load double, double* %6
%18 = load double, double* %5
%19 = fdiv double %17, %18
%20 = fsub double %15, %19
%21 = fsub double %1, %20
%22 = fsub double %20, %2
%23 = fmul double %21, %22
%24 = fcmp olt double %23, 0.000000e+00
br i1 %24, label %25, label %29
25: ; preds = %14
%26 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.3, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %14
%30 = call double @llvm.fabs.f64(double %19)
%31 = fcmp olt double %30, %3
br i1 %31, label %32, label %11
32: ; preds = %29
ret double %20
33: ; preds = %11
%34 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
}