#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 M_PI;
double theta_func(double);
double root_find(double th) {
  int i;
  double X2a, X2b, X2c, tha, thb, thc;
  double dthdX2, dtheta_func(double y), theta_func(double y);
  if (th < M_PI / 2.) {
    X2a = 0. - 1.e-14;
    ;
    X2b = 0.5 + 1.e-14;
    ;
  } else {
    X2a = 0.5 - 1.e-14;
    ;
    X2b = 1. + 1.e-14;
    ;
  }
  tha = theta_func(X2a);
  thb = theta_func(X2b);
  for (i = 0; i < 8; i++) {
    X2c = 0.5 * (X2a + X2b);
    thc = theta_func(X2c);
    if ((thc - th) * (thb - th) < 0.)
      X2a = X2c;
    else
      X2b = X2c;
  }
  tha = theta_func(X2a);
  for (i = 0; i < 2; i++) {
    dthdX2 = dtheta_func(X2a);
    X2a -= (tha - th) / dthdX2;
    tha = theta_func(X2a);
  }
  return (X2a);
}


x86 assembly (clang, -O0):
<root_find>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm1
mov    0x2eaf(%rip),%rax
cvtsi2sdl (%rax),%xmm0
movsd  0xebb(%rip),%xmm2
divsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    1172 <root_find+0x52>
movsd  0xec5(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xeb0(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    118c <root_find+0x6c>
movsd  0xe96(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe81(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <theta_func@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <theta_func@plt>
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jge    1236 <root_find+0x116>
movsd  -0x18(%rbp),%xmm1
addsd  -0x20(%rbp),%xmm1
movsd  0xe5b(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <theta_func@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm1
subsd  -0x8(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    1219 <root_find+0xf9>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1223 <root_find+0x103>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1228 <root_find+0x108>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11b1 <root_find+0x91>
movsd  -0x18(%rbp),%xmm0
call   1030 <theta_func@plt>
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    129f <root_find+0x17f>
movsd  -0x18(%rbp),%xmm0
call   1040 <dtheta_func@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm1
subsd  -0x8(%rbp),%xmm1
divsd  -0x48(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <theta_func@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    124c <root_find+0x12c>
movsd  -0x18(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<root_find>:
push   %rbx
sub    $0x50,%rsp
mov    0x2ebc(%rip),%rax
cvtsi2sdl (%rax),%xmm1
movsd  %xmm0,0x8(%rsp)
mulsd  0xec2(%rip),%xmm1
xor    %ebx,%ebx
ucomisd %xmm0,%xmm1
seta   %bl
lea    0xec2(%rip),%rax
movsd  (%rax,%rbx,8),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xec1(%rip),%rax
movsd  (%rax,%rbx,8),%xmm0
movsd  %xmm0,0x40(%rsp)
call   1030 <theta_func@plt>
movapd 0x10(%rsp),%xmm0
call   1030 <theta_func@plt>
subsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
lea    0xea3(%rip),%rax
movsd  (%rax,%rbx,8),%xmm0
movapd %xmm0,0x30(%rsp)
call   1030 <theta_func@plt>
movapd %xmm0,%xmm1
subsd  0x8(%rsp),%xmm1
mulsd  0x20(%rsp),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
cmpltsd %xmm0,%xmm1
movapd 0x30(%rsp),%xmm3
movapd 0x10(%rsp),%xmm2
andpd  %xmm1,%xmm2
andnpd %xmm3,%xmm1
orpd   %xmm2,%xmm1
ja     11da <root_find+0xba>
movsd  0x40(%rsp),%xmm3
movapd %xmm1,%xmm0
movapd %xmm3,0x30(%rsp)
addsd  %xmm3,%xmm0
mulsd  0xe10(%rip),%xmm0
movapd %xmm0,0x10(%rsp)
movapd %xmm1,0x40(%rsp)
call   1030 <theta_func@plt>
movapd 0x10(%rsp),%xmm1
movapd %xmm0,%xmm2
subsd  0x8(%rsp),%xmm2
mulsd  0x20(%rsp),%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
cmpltsd %xmm0,%xmm2
movapd %xmm2,%xmm0
andpd  0x40(%rsp),%xmm0
andnpd %xmm1,%xmm2
orpd   %xmm0,%xmm2
ja     123e <root_find+0x11e>
movapd 0x30(%rsp),%xmm1
movapd %xmm2,%xmm0
movapd %xmm1,0x10(%rsp)
addsd  %xmm1,%xmm0
mulsd  0xdac(%rip),%xmm0
movapd %xmm0,0x30(%rsp)
movapd %xmm2,0x40(%rsp)
call   1030 <theta_func@plt>
movapd 0x30(%rsp),%xmm1
movapd %xmm0,%xmm2
subsd  0x8(%rsp),%xmm2
mulsd  0x20(%rsp),%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
cmpltsd %xmm0,%xmm2
movapd %xmm2,%xmm0
andpd  0x40(%rsp),%xmm0
andnpd %xmm1,%xmm2
orpd   %xmm0,%xmm2
ja     12a2 <root_find+0x182>
movapd 0x10(%rsp),%xmm1
movapd %xmm2,%xmm0
movapd %xmm1,0x30(%rsp)
addsd  %xmm1,%xmm0
mulsd  0xd48(%rip),%xmm0
movapd %xmm0,0x10(%rsp)
movapd %xmm2,0x40(%rsp)
call   1030 <theta_func@plt>
movapd 0x10(%rsp),%xmm1
movapd %xmm0,%xmm2
subsd  0x8(%rsp),%xmm2
mulsd  0x20(%rsp),%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
cmpltsd %xmm0,%xmm2
movapd %xmm2,%xmm0
andpd  0x40(%rsp),%xmm0
andnpd %xmm1,%xmm2
orpd   %xmm0,%xmm2
ja     1306 <root_find+0x1e6>
movapd 0x30(%rsp),%xmm1
movapd %xmm2,%xmm0
movapd %xmm1,0x10(%rsp)
addsd  %xmm1,%xmm0
mulsd  0xce4(%rip),%xmm0
movapd %xmm0,0x30(%rsp)
movapd %xmm2,0x40(%rsp)
call   1030 <theta_func@plt>
movapd 0x30(%rsp),%xmm1
movapd %xmm0,%xmm2
subsd  0x8(%rsp),%xmm2
mulsd  0x20(%rsp),%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
cmpltsd %xmm0,%xmm2
movapd %xmm2,%xmm0
andpd  0x40(%rsp),%xmm0
andnpd %xmm1,%xmm2
orpd   %xmm0,%xmm2
ja     136a <root_find+0x24a>
movapd 0x10(%rsp),%xmm1
movapd %xmm2,%xmm0
movapd %xmm1,0x30(%rsp)
addsd  %xmm1,%xmm0
mulsd  0xc80(%rip),%xmm0
movapd %xmm0,0x40(%rsp)
movapd %xmm2,0x10(%rsp)
call   1030 <theta_func@plt>
movapd 0x40(%rsp),%xmm1
movapd %xmm0,%xmm2
subsd  0x8(%rsp),%xmm2
mulsd  0x20(%rsp),%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
cmpltsd %xmm0,%xmm2
movapd %xmm2,%xmm0
andpd  0x10(%rsp),%xmm0
andnpd %xmm1,%xmm2
orpd   %xmm0,%xmm2
ja     13ce <root_find+0x2ae>
movapd 0x30(%rsp),%xmm1
movapd %xmm2,%xmm0
movapd %xmm1,0x40(%rsp)
addsd  %xmm1,%xmm0
mulsd  0xc1c(%rip),%xmm0
movapd %xmm0,0x10(%rsp)
movapd %xmm2,0x30(%rsp)
call   1030 <theta_func@plt>
movapd 0x10(%rsp),%xmm1
subsd  0x8(%rsp),%xmm0
mulsd  0x20(%rsp),%xmm0
xorpd  %xmm2,%xmm2
ucomisd %xmm0,%xmm2
cmpltsd %xmm2,%xmm0
movapd %xmm0,%xmm2
andpd  0x30(%rsp),%xmm2
andnpd %xmm1,%xmm0
orpd   %xmm2,%xmm0
ja     142e <root_find+0x30e>
movapd 0x40(%rsp),%xmm1
movapd %xmm1,0x10(%rsp)
addsd  %xmm1,%xmm0
mulsd  0xbc0(%rip),%xmm0
movapd %xmm0,0x30(%rsp)
call   1030 <theta_func@plt>
subsd  0x8(%rsp),%xmm0
mulsd  0x20(%rsp),%xmm0
cmpltsd 0xba8(%rip),%xmm0
movapd 0x30(%rsp),%xmm1
andpd  %xmm0,%xmm1
andnpd 0x10(%rsp),%xmm0
orpd   %xmm1,%xmm0
movapd %xmm0,0x20(%rsp)
call   1030 <theta_func@plt>
movsd  %xmm0,0x10(%rsp)
movapd 0x20(%rsp),%xmm0
call   1040 <dtheta_func@plt>
movsd  0x10(%rsp),%xmm1
subsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd 0x20(%rsp),%xmm0
subsd  %xmm1,%xmm0
movapd %xmm0,0x20(%rsp)
call   1030 <theta_func@plt>
movsd  %xmm0,0x10(%rsp)
movapd 0x20(%rsp),%xmm0
call   1040 <dtheta_func@plt>
movsd  0x10(%rsp),%xmm1
subsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd 0x20(%rsp),%xmm0
subsd  %xmm1,%xmm0
movapd %xmm0,0x20(%rsp)
call   1030 <theta_func@plt>
movaps 0x20(%rsp),%xmm0
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@M_PI = global i32 0
define double @root_find(double %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store double %0, double* %2
%11 = load double, double* %2
%12 = load i32, i32* @M_PI
%13 = sitofp i32 %12 to double
%14 = fdiv double %13, 2.000000e+00
%15 = fcmp olt double %11, %14
br i1 %15, label %16, label %17
16: ; preds = %1
store double 0xBD06849B86A12B9B, double* %4
store double 0x3FE000000000005A, double* %5
br label %18
17: ; preds = %1
store double 0x3FDFFFFFFFFFFF4C, double* %4
store double 0x3FF000000000002D, double* %5
br label %18
18: ; preds = %17, %16
%19 = load double, double* %4
%20 = call double @theta_func(double %19)
store double %20, double* %7
%21 = load double, double* %5
%22 = call double @theta_func(double %21)
store double %22, double* %8
store i32 0, i32* %3
br label %23
23: ; preds = %46, %18
%24 = load i32, i32* %3
%25 = icmp slt i32 %24, 8
br i1 %25, label %26, label %49
26: ; preds = %23
%27 = load double, double* %4
%28 = load double, double* %5
%29 = fadd double %27, %28
%30 = fmul double 5.000000e-01, %29
store double %30, double* %6
%31 = load double, double* %6
%32 = call double @theta_func(double %31)
store double %32, double* %9
%33 = load double, double* %9
%34 = load double, double* %2
%35 = fsub double %33, %34
%36 = load double, double* %8
%37 = load double, double* %2
%38 = fsub double %36, %37
%39 = fmul double %35, %38
%40 = fcmp olt double %39, 0.000000e+00
br i1 %40, label %41, label %43
41: ; preds = %26
%42 = load double, double* %6
store double %42, double* %4
br label %45
43: ; preds = %26
%44 = load double, double* %6
store double %44, double* %5
br label %45
45: ; preds = %43, %41
br label %46
46: ; preds = %45
%47 = load i32, i32* %3
%48 = add nsw i32 %47, 1
store i32 %48, i32* %3
br label %23
49: ; preds = %23
%50 = load double, double* %4
%51 = call double @theta_func(double %50)
store double %51, double* %7
store i32 0, i32* %3
br label %52
52: ; preds = %67, %49
%53 = load i32, i32* %3
%54 = icmp slt i32 %53, 2
br i1 %54, label %55, label %70
55: ; preds = %52
%56 = load double, double* %4
%57 = call double @dtheta_func(double %56)
store double %57, double* %10
%58 = load double, double* %7
%59 = load double, double* %2
%60 = fsub double %58, %59
%61 = load double, double* %10
%62 = fdiv double %60, %61
%63 = load double, double* %4
%64 = fsub double %63, %62
store double %64, double* %4
%65 = load double, double* %4
%66 = call double @theta_func(double %65)
store double %66, double* %7
br label %67
67: ; preds = %55
%68 = load i32, i32* %3
%69 = add nsw i32 %68, 1
store i32 %69, i32* %3
br label %52
70: ; preds = %52
%71 = load double, double* %4
ret double %71
}

LLVM IR (-O2):
@M_PI = global i32 0
define double @root_find(double %0) {
%2 = load i32, i32* @M_PI
%3 = sitofp i32 %2 to double
%4 = fmul double %3, 5.000000e-01
%5 = fcmp ogt double %4, %0
%6 = select i1 %5, double 0x3FE000000000005A, double 0x3FF000000000002D
%7 = select i1 %5, double 0xBD06849B86A12B9B, double 0x3FDFFFFFFFFFFF4C
%8 = tail call double @theta_func(double %7)
%9 = tail call double @theta_func(double %6)
%10 = fsub double %9, %0
%11 = select i1 %5, double 2.500000e-01, double 7.500000e-01
%12 = tail call double @theta_func(double %11)
%13 = fsub double %12, %0
%14 = fmul double %10, %13
%15 = fcmp olt double %14, 0.000000e+00
%16 = select i1 %15, double %6, double %11
%17 = select i1 %15, double %11, double %7
%18 = fadd double %16, %17
%19 = fmul double %18, 5.000000e-01
%20 = tail call double @theta_func(double %19)
%21 = fsub double %20, %0
%22 = fmul double %10, %21
%23 = fcmp olt double %22, 0.000000e+00
%24 = select i1 %23, double %16, double %19
%25 = select i1 %23, double %19, double %17
%26 = fadd double %24, %25
%27 = fmul double %26, 5.000000e-01
%28 = tail call double @theta_func(double %27)
%29 = fsub double %28, %0
%30 = fmul double %10, %29
%31 = fcmp olt double %30, 0.000000e+00
%32 = select i1 %31, double %24, double %27
%33 = select i1 %31, double %27, double %25
%34 = fadd double %32, %33
%35 = fmul double %34, 5.000000e-01
%36 = tail call double @theta_func(double %35)
%37 = fsub double %36, %0
%38 = fmul double %10, %37
%39 = fcmp olt double %38, 0.000000e+00
%40 = select i1 %39, double %32, double %35
%41 = select i1 %39, double %35, double %33
%42 = fadd double %40, %41
%43 = fmul double %42, 5.000000e-01
%44 = tail call double @theta_func(double %43)
%45 = fsub double %44, %0
%46 = fmul double %10, %45
%47 = fcmp olt double %46, 0.000000e+00
%48 = select i1 %47, double %40, double %43
%49 = select i1 %47, double %43, double %41
%50 = fadd double %48, %49
%51 = fmul double %50, 5.000000e-01
%52 = tail call double @theta_func(double %51)
%53 = fsub double %52, %0
%54 = fmul double %10, %53
%55 = fcmp olt double %54, 0.000000e+00
%56 = select i1 %55, double %48, double %51
%57 = select i1 %55, double %51, double %49
%58 = fadd double %56, %57
%59 = fmul double %58, 5.000000e-01
%60 = tail call double @theta_func(double %59)
%61 = fsub double %60, %0
%62 = fmul double %10, %61
%63 = fcmp olt double %62, 0.000000e+00
%64 = select i1 %63, double %56, double %59
%65 = select i1 %63, double %59, double %57
%66 = fadd double %64, %65
%67 = fmul double %66, 5.000000e-01
%68 = tail call double @theta_func(double %67)
%69 = fsub double %68, %0
%70 = fmul double %10, %69
%71 = fcmp olt double %70, 0.000000e+00
%72 = select i1 %71, double %67, double %65
%73 = tail call double @theta_func(double %72)
%74 = tail call double @dtheta_func(double %72)
%75 = fsub double %73, %0
%76 = fdiv double %75, %74
%77 = fsub double %72, %76
%78 = tail call double @theta_func(double %77)
%79 = tail call double @dtheta_func(double %77)
%80 = fsub double %78, %0
%81 = fdiv double %80, %79
%82 = fsub double %77, %81
%83 = tail call double @theta_func(double %82)
ret double %82
}