#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 M_PI;
double cos(double);
int /*<<< orphan*/ file_write(double, char *);
int /*<<< orphan*/ report(double);
double sin(double);
double tan(double);
void test_trig() {
  double x, step;
  step = M_PI / 100.0;
  for (x = -2 * M_PI; x <= 2 * M_PI; x += step) {
    report(x);
    file_write(x, "x");
    file_write(cos(x), "cos_x");
    file_write(sin(x), "sin_x");
    file_write(tan(x), "tan_x");
  }
}


x86 assembly (clang, -O0):
<test_trig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
movsd  (%rax),%xmm0
movsd  0xe9d(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe84(%rip),%xmm0
mov    0x2e65(%rip),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  0xe77(%rip),%xmm0
mov    0x2e48(%rip),%rax
mulsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jb     121f <test_trig+0xcf>
movsd  -0x8(%rbp),%xmm0
call   1070 <report@plt>
movsd  -0x8(%rbp),%xmm0
lea    0xe64(%rip),%rdi
call   1060 <file_write@plt>
movsd  -0x8(%rbp),%xmm0
call   1050 <cos@plt>
lea    0xe3e(%rip),%rdi
call   1060 <file_write@plt>
movsd  -0x8(%rbp),%xmm0
call   1030 <sin@plt>
lea    0xe2e(%rip),%rdi
call   1060 <file_write@plt>
movsd  -0x8(%rbp),%xmm0
call   1040 <tan@plt>
lea    0xe1e(%rip),%rdi
call   1060 <file_write@plt>
movsd  -0x10(%rbp),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    118c <test_trig+0x3c>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_trig>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2e84(%rip),%r13
movsd  0x0(%r13),%xmm0
movsd  0xe96(%rip),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm0,0x8(%rsp)
addsd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jb     122c <test_trig+0xdc>
movsd  0x8(%rsp),%xmm0
divsd  0xe68(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xe7b(%rip),%r14
lea    0xe64(%rip),%r15
lea    0xe63(%rip),%r12
lea    0xe62(%rip),%rbx
nopw   0x0(%rax,%rax,1)
movsd  %xmm1,(%rsp)
movapd %xmm1,%xmm0
call   1070 <report@plt>
movsd  (%rsp),%xmm0
mov    %r14,%rdi
call   1060 <file_write@plt>
movsd  (%rsp),%xmm0
call   1050 <cos@plt>
mov    %r15,%rdi
call   1060 <file_write@plt>
movsd  (%rsp),%xmm0
call   1030 <sin@plt>
mov    %r12,%rdi
call   1060 <file_write@plt>
movsd  (%rsp),%xmm0
call   1040 <tan@plt>
mov    %rbx,%rdi
call   1060 <file_write@plt>
movsd  (%rsp),%xmm1
addsd  0x8(%rsp),%xmm1
movsd  0x0(%r13),%xmm0
addsd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jae    11c0 <test_trig+0x70>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
@.str = [2 x i8] c"x\00"
@.str.1 = [6 x i8] c"cos_x\00"
@.str.2 = [6 x i8] c"sin_x\00"
@.str.3 = [6 x i8] c"tan_x\00"
define void @test_trig() {
%1 = alloca double
%2 = alloca double
%3 = load double, double* @M_PI
%4 = fdiv double %3, 1.000000e+02
store double %4, double* %2
%5 = load double, double* @M_PI
%6 = fmul double -2.000000e+00, %5
store double %6, double* %1
br label %7
7: ; preds = %26, %0
%8 = load double, double* %1
%9 = load double, double* @M_PI
%10 = fmul double 2.000000e+00, %9
%11 = fcmp ole double %8, %10
br i1 %11, label %12, label %30
12: ; preds = %7
%13 = load double, double* %1
%14 = call i32 @report(double %13)
%15 = load double, double* %1
%16 = call i32 @file_write(double %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = load double, double* %1
%18 = call double @cos(double %17)
%19 = call i32 @file_write(double %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%20 = load double, double* %1
%21 = call double @sin(double %20)
%22 = call i32 @file_write(double %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%23 = load double, double* %1
%24 = call double @tan(double %23)
%25 = call i32 @file_write(double %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %12
%27 = load double, double* %2
%28 = load double, double* %1
%29 = fadd double %28, %27
store double %29, double* %1
br label %7
30: ; preds = %7
ret void
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
@.str = [2 x i8] c"x\00"
@.str.1 = [6 x i8] c"cos_x\00"
@.str.2 = [6 x i8] c"sin_x\00"
@.str.3 = [6 x i8] c"tan_x\00"
define void @test_trig() {
%1 = load double, double* @M_PI
%2 = fdiv double %1, 1.000000e+02
%3 = fmul double %1, -2.000000e+00
%4 = fmul double %1, 2.000000e+00
%5 = fcmp ugt double %3, %4
br i1 %5, label %20, label %6
6: ; preds = %0, %6
%7 = phi double [ %16, %6 ], [ %3, %0 ]
%8 = tail call i32 @report(double %7)
%9 = tail call i32 @file_write(double %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = tail call double @cos(double %7)
%11 = tail call i32 @file_write(double %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call double @sin(double %7)
%13 = tail call i32 @file_write(double %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call double @tan(double %7)
%15 = tail call i32 @file_write(double %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%16 = fadd double %2, %7
%17 = load double, double* @M_PI
%18 = fmul double %17, 2.000000e+00
%19 = fcmp ugt double %16, %18
br i1 %19, label %20, label %6
20: ; preds = %6, %0
ret void
}