#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 GetInitialEstimateSolarTerms(int, int);
double GetSunEclipticLongitudeEC(double);
double fabs(double);
int /*<<< orphan*/ printf(char *, double, ...);
double CalculateSolarTerms(int year, int angle) {
  double JD0, JD1, stDegree, stDegreep;
  JD1 = GetInitialEstimateSolarTerms(year, angle);
  printf("jd1 -> %f \n", JD1);
  do {
    JD0 = JD1;
    stDegree = GetSunEclipticLongitudeEC(JD0);
    printf("stDegree -> %f\n", stDegree);
    stDegree =
        ((angle == 0) && (stDegree > 345.0)) ? stDegree - 360.0 : stDegree;
    stDegreep = (GetSunEclipticLongitudeEC(JD0 + 0.000005) -
                 GetSunEclipticLongitudeEC(JD0 - 0.000005)) /
                0.00001;
    JD1 = JD0 - (stDegree - angle) / stDegreep;
    printf("jd0 -> %f, jd1 -> %f\n", JD0, JD1);
  } while ((fabs(JD1 - JD0) > 0.0000001));
  return JD1;
}


x86 assembly (clang, -O0):
<CalculateSolarTerms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <GetInitialEstimateSolarTerms@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xee6(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <GetSunEclipticLongitudeEC@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xec6(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    11c9 <CalculateSolarTerms+0x99>
movsd  -0x20(%rbp),%xmm0
movsd  0xe5c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11c9 <CalculateSolarTerms+0x99>
movsd  -0x20(%rbp),%xmm0
movsd  0xe4d(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11d3 <CalculateSolarTerms+0xa3>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe33(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
call   1050 <GetSunEclipticLongitudeEC@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe17(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1050 <GetSunEclipticLongitudeEC@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  0xdf2(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
cvtsi2sdl -0x8(%rbp),%xmm2
subsd  %xmm2,%xmm1
divsd  -0x28(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
lea    0xe03(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movaps 0xdbf(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xda3(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     1161 <CalculateSolarTerms+0x31>
movsd  -0x18(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CalculateSolarTerms>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %esi,%ebx
call   1040 <GetInitialEstimateSolarTerms@plt>
movsd  %xmm0,0x8(%rsp)
lea    0xef3(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm2
cvtsi2sd %ebx,%xmm1
movsd  %xmm1,0x20(%rsp)
lea    0xee1(%rip),%r14
lea    0xeea(%rip),%r15
jmp    1229 <CalculateSolarTerms+0xf9>
nopw   0x0(%rax,%rax,1)
movsd  0x8(%rsp),%xmm0
subsd  0x20(%rsp),%xmm2
movapd %xmm2,0x10(%rsp)
addsd  0xe76(%rip),%xmm0
call   1050 <GetSunEclipticLongitudeEC@plt>
movsd  %xmm0,0x28(%rsp)
movsd  0x8(%rsp),%xmm0
addsd  0xe65(%rip),%xmm0
call   1050 <GetSunEclipticLongitudeEC@plt>
movsd  0x28(%rsp),%xmm1
subsd  %xmm0,%xmm1
divsd  0xe56(%rip),%xmm1
movapd 0x10(%rsp),%xmm0
divsd  %xmm1,%xmm0
movapd %xmm0,0x10(%rsp)
movapd 0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm1,%xmm0
movapd %xmm0,0x10(%rsp)
mov    %r15,%rdi
movapd %xmm1,%xmm0
movaps 0x10(%rsp),%xmm1
mov    $0x2,%al
call   1030 <printf@plt>
movapd 0x10(%rsp),%xmm0
movapd %xmm0,%xmm1
subsd  0x8(%rsp),%xmm1
andpd  0xe15(%rip),%xmm1
ucomisd 0xe05(%rip),%xmm1
movapd %xmm0,%xmm2
jbe    1284 <CalculateSolarTerms+0x154>
movsd  %xmm2,0x8(%rsp)
movapd %xmm2,%xmm0
call   1050 <GetSunEclipticLongitudeEC@plt>
movapd %xmm0,0x10(%rsp)
mov    %r14,%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movapd 0x10(%rsp),%xmm2
movapd %xmm2,%xmm0
addsd  0xda6(%rip),%xmm0
test   %ebx,%ebx
jne    1180 <CalculateSolarTerms+0x50>
movsd  0xd9e(%rip),%xmm1
cmpltsd %xmm2,%xmm1
andpd  %xmm1,%xmm0
andnpd %xmm2,%xmm1
orpd   %xmm0,%xmm1
movapd %xmm1,%xmm2
jmp    1180 <CalculateSolarTerms+0x50>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"jd1 -> %f \0A\00"
@.str.1 = [16 x i8] c"stDegree -> %f\0A\00"
@.str.2 = [22 x i8] c"jd0 -> %f, jd1 -> %f\0A\00"
define double @CalculateSolarTerms(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store i32 %0, i32* %3
store i32 %1, i32* %4
%9 = load i32, i32* %3
%10 = load i32, i32* %4
%11 = call double @GetInitialEstimateSolarTerms(i32 %9, i32 %10)
store double %11, double* %6
%12 = load double, double* %6
%13 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), double %12)
br label %14
14: ; preds = %51, %2
%15 = load double, double* %6
store double %15, double* %5
%16 = load double, double* %5
%17 = call double @GetSunEclipticLongitudeEC(double %16)
store double %17, double* %7
%18 = load double, double* %7
%19 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), double %18)
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %14
%23 = load double, double* %7
%24 = fcmp ogt double %23, 3.450000e+02
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load double, double* %7
%27 = fsub double %26, 3.600000e+02
br label %30
28: ; preds = %22, %14
%29 = load double, double* %7
br label %30
30: ; preds = %28, %25
%31 = phi double [ %27, %25 ], [ %29, %28 ]
store double %31, double* %7
%32 = load double, double* %5
%33 = fadd double %32, 5.000000e-06
%34 = call double @GetSunEclipticLongitudeEC(double %33)
%35 = load double, double* %5
%36 = fsub double %35, 5.000000e-06
%37 = call double @GetSunEclipticLongitudeEC(double %36)
%38 = fsub double %34, %37
%39 = fdiv double %38, 1.000000e-05
store double %39, double* %8
%40 = load double, double* %5
%41 = load double, double* %7
%42 = load i32, i32* %4
%43 = sitofp i32 %42 to double
%44 = fsub double %41, %43
%45 = load double, double* %8
%46 = fdiv double %44, %45
%47 = fsub double %40, %46
store double %47, double* %6
%48 = load double, double* %5
%49 = load double, double* %6
%50 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), double %48, double %49)
br label %51
51: ; preds = %30
%52 = load double, double* %6
%53 = load double, double* %5
%54 = fsub double %52, %53
%55 = call double @llvm.fabs.f64(double %54)
%56 = fcmp ogt double %55, 0x3E7AD7F29ABCAF48
br i1 %56, label %14, label %57
57: ; preds = %51
%58 = load double, double* %6
ret double %58
}

LLVM IR (-O2):
@.str = [12 x i8] c"jd1 -> %f \0A\00"
@.str.1 = [16 x i8] c"stDegree -> %f\0A\00"
@.str.2 = [22 x i8] c"jd0 -> %f, jd1 -> %f\0A\00"
define double @CalculateSolarTerms(i32 %0, i32 %1) {
%3 = tail call double @GetInitialEstimateSolarTerms(i32 %0, i32 %1)
%4 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), double %3)
%5 = icmp eq i32 %1, 0
%6 = sitofp i32 %1 to double
br label %7
7: ; preds = %7, %2
%8 = phi double [ %3, %2 ], [ %23, %7 ]
%9 = tail call double @GetSunEclipticLongitudeEC(double %8)
%10 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), double %9)
%11 = fcmp ogt double %9, 3.450000e+02
%12 = and i1 %5, %11
%13 = fadd double %9, -3.600000e+02
%14 = select i1 %12, double %13, double %9
%15 = fadd double %8, 5.000000e-06
%16 = tail call double @GetSunEclipticLongitudeEC(double %15)
%17 = fadd double %8, -5.000000e-06
%18 = tail call double @GetSunEclipticLongitudeEC(double %17)
%19 = fsub double %16, %18
%20 = fdiv double %19, 1.000000e-05
%21 = fsub double %14, %6
%22 = fdiv double %21, %20
%23 = fsub double %8, %22
%24 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), double %8, double %23)
%25 = fsub double %23, %8
%26 = tail call double @llvm.fabs.f64(double %25)
%27 = fcmp ogt double %26, 0x3E7AD7F29ABCAF48
br i1 %27, label %7, label %28
28: ; preds = %7
ret double %23
}