#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 *, ...);
int /*<<< orphan*/ scanf(char *, double *);
int main() {
  double radian = 0;
  double libResult = 0;
  double myResult = 0.0;
  printf("\n\nPlease insert a number in radians\n");
  scanf("%lf", &radian);
  if (radian > 3.14159) {
    radian = radian - 2 * 3.14159;
  } else if (radian > 3.14159 / 2) {
    radian = 3.14159 - radian;
  }
  libResult = cos(radian);
  myResult = my_cos(radian);
  printf("cos calculated by fucntion: %f\n", myResult);
  printf("cos calculated by library: %f\n", libResult);
  printf(" \nEnd of Main\n");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec1(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
movsd  -0x10(%rbp),%xmm0
movsd  0xe6e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11b7 <main+0x77>
movsd  -0x10(%rbp),%xmm0
movsd  0xe67(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11e5 <main+0xa5>
movsd  -0x10(%rbp),%xmm0
movsd  0xe44(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11e0 <main+0xa0>
movsd  0xe2a(%rip),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11e5 <main+0xa5>
movsd  -0x10(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <my_cos@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xe32(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm0
lea    0xe3f(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
lea    0xef7(%rip),%rdi
call   1030 <puts@plt>
lea    0xea8(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
movsd  0x8(%rsp),%xmm0
ucomisd 0xe78(%rip),%xmm0
jbe    119a <main+0x4a>
addsd  0xe7e(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
jmp    11ba <main+0x6a>
ucomisd 0xe66(%rip),%xmm0
jbe    11ba <main+0x6a>
movsd  0xe54(%rip),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movapd %xmm1,%xmm0
call   1060 <cos@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1070 <my_cos@plt>
lea    0xe45(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe57(%rip),%rdi
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"\0A\0APlease insert a number in radians\0A\00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [32 x i8] c"cos calculated by fucntion: %f\0A\00"
@.str.3 = [31 x i8] c"cos calculated by library: %f\0A\00"
@.str.4 = [15 x i8] c" \0AEnd of Main\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
store i32 0, i32* %1
store double 0.000000e+00, double* %2
store double 0.000000e+00, double* %3
store double 0.000000e+00, double* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %2)
%7 = load double, double* %2
%8 = fcmp ogt double %7, 3.141590e+00
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = load double, double* %2
%11 = fsub double %10, 6.283180e+00
store double %11, double* %2
br label %19
12: ; preds = %0
%13 = load double, double* %2
%14 = fcmp ogt double %13, 0x3FF921F9F01B866E
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load double, double* %2
%17 = fsub double 3.141590e+00, %16
store double %17, double* %2
br label %18
18: ; preds = %15, %12
br label %19
19: ; preds = %18, %9
%20 = load double, double* %2
%21 = call double @cos(double %20)
store double %21, double* %3
%22 = load double, double* %2
%23 = call double @my_cos(double %22)
store double %23, double* %4
%24 = load double, double* %4
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), double %24)
%26 = load double, double* %3
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), double %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
ret i32 1
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [32 x i8] c"cos calculated by fucntion: %f\0A\00"
@.str.3 = [31 x i8] c"cos calculated by library: %f\0A\00"
@str = [36 x i8] c"\0A\0APlease insert a number in radians\00"
@str.5 = [14 x i8] c" \0AEnd of Main\00"
define i32 @main() {
%1 = alloca double
%2 = bitcast double* %1 to i8*
store double 0.000000e+00, double* %1
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %1)
%5 = load double, double* %1
%6 = fcmp ogt double %5, 3.141590e+00
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = fadd double %5, -6.283180e+00
store double %8, double* %1
br label %13
9: ; preds = %0
%10 = fcmp ogt double %5, 0x3FF921F9F01B866E
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = fsub double 3.141590e+00, %5
store double %12, double* %1
br label %13
13: ; preds = %9, %11, %7
%14 = phi double [ %5, %9 ], [ %12, %11 ], [ %8, %7 ]
%15 = call double @cos(double %14)
%16 = load double, double* %1
%17 = call double @my_cos(double %16)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), double %17)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), double %15)
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0))
ret i32 1
}