#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 cos(double);
double my_cos(double);
int /*<<< orphan*/ printf(char *, double, double, ...);
int /*<<< orphan*/ scanf(char *, double *);
int main(int argc, char *argv[]) {
  double mathCOS = 0, compCOS = 0, x = 4, diff, per_diff;
  scanf("%lf", &x);
  mathCOS = cos(x);
  compCOS = my_cos(x);
  diff = compCOS - mathCOS;
  per_diff = (diff / mathCOS) * 100;
  printf("math.h cos(%g) = %g\nmy_cos(%g) = %g\n\n", x, mathCOS, x, compCOS);
  printf("difference = %g\nRelative Percent Difference = %g%%\n\n", diff,
         per_diff);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe9a(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
lea    0xe96(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <scanf@plt>
movsd  -0x28(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1060 <my_cos@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  0xe3e(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm3
lea    0xe2e(%rip),%rdi
mov    $0x4,%al
call   1030 <printf@plt>
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
lea    0xe3c(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
movabs $0x4010000000000000,%rax
mov    %rax,0x8(%rsp)
lea    0xeae(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
movsd  0x8(%rsp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1060 <my_cos@plt>
movapd %xmm0,%xmm3
movsd  0x10(%rsp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,0x20(%rsp)
divsd  %xmm1,%xmm0
mulsd  0xe60(%rip),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
lea    0xe59(%rip),%rdi
movaps %xmm0,%xmm2
mov    $0x4,%al
call   1030 <printf@plt>
lea    0xe6e(%rip),%rdi
movsd  0x20(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
mov    $0x2,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%lf\00"
@.str.1 = [38 x i8] c"math.h cos(%g) = %g\0Amy_cos(%g) = %g\0A\0A\00"
@.str.2 = [53 x i8] c"difference = %g\0ARelative Percent Difference = %g%%\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %6
store double 0.000000e+00, double* %7
store double 4.000000e+00, double* %8
%11 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %8)
%12 = load double, double* %8
%13 = call double @cos(double %12)
store double %13, double* %6
%14 = load double, double* %8
%15 = call double @my_cos(double %14)
store double %15, double* %7
%16 = load double, double* %7
%17 = load double, double* %6
%18 = fsub double %16, %17
store double %18, double* %9
%19 = load double, double* %9
%20 = load double, double* %6
%21 = fdiv double %19, %20
%22 = fmul double %21, 1.000000e+02
store double %22, double* %10
%23 = load double, double* %8
%24 = load double, double* %6
%25 = load double, double* %8
%26 = load double, double* %7
%27 = call i32 (i8*, double, double, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), double %23, double %24, double %25, double %26)
%28 = load double, double* %9
%29 = load double, double* %10
%30 = call i32 (i8*, double, double, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), double %28, double %29)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%lf\00"
@.str.1 = [38 x i8] c"math.h cos(%g) = %g\0Amy_cos(%g) = %g\0A\0A\00"
@.str.2 = [53 x i8] c"difference = %g\0ARelative Percent Difference = %g%%\0A\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca double
%4 = bitcast double* %3 to i8*
store double 4.000000e+00, double* %3
%5 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %3)
%6 = load double, double* %3
%7 = call double @cos(double %6)
%8 = load double, double* %3
%9 = call double @my_cos(double %8)
%10 = fsub double %9, %7
%11 = fdiv double %10, %7
%12 = fmul double %11, 1.000000e+02
%13 = load double, double* %3
%14 = call i32 (i8*, double, double, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), double %13, double %7, double %13, double %9)
%15 = call i32 (i8*, double, double, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), double %10, double %12)
ret i32 0
}