#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 */
scalar_t__ cos(double);
int /*<<< orphan*/ my_abs(scalar_t__);
scalar_t__ my_cos(double);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ scanf(char *, double *);
int main(void) {
  double x;
  printf("Enter value for cos:\n");
  while (scanf("%lf", &x)) {
    printf("my_cos(%lf) = %1.9lf\n", x, my_cos(x));
    printf("cos(%lf) = %1.9lf\n", x, cos(x));
    printf("diff = %1.9lf\n\n", my_abs(my_cos(x) - cos(x)));
    printf("Enter another value for cos:\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea2(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
cmp    $0x0,%rax
je     1222 <main+0xd2>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1070 <my_cos@plt>
movsd  -0x28(%rbp),%xmm0
mov    %rax,%rsi
lea    0xe70(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <cos@plt>
movsd  -0x20(%rbp),%xmm0
mov    %rax,%rsi
lea    0xe49(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x10(%rbp),%xmm0
call   1070 <my_cos@plt>
mov    %rax,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <cos@plt>
mov    -0x18(%rbp),%rdi
sub    %rax,%rdi
call   1030 <my_abs@plt>
mov    %eax,%esi
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    116d <main+0x1d>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeb5(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7f(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <scanf@plt>
test   %rax,%rax
je     1258 <main+0xf8>
lea    0xe6c(%rip),%r15
lea    0xe78(%rip),%r12
lea    0xe96(%rip),%r13
lea    0xe50(%rip),%rbx
lea    0x8(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nop
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
call   1080 <my_cos@plt>
lea    0xe2c(%rip),%rdi
movsd  0x10(%rsp),%xmm0
mov    %rax,%rsi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
call   1070 <cos@plt>
mov    %r15,%rdi
movsd  0x10(%rsp),%xmm0
mov    %rax,%rsi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x8(%rsp),%xmm0
call   1080 <my_cos@plt>
mov    %rax,%r14
movsd  0x8(%rsp),%xmm0
call   1070 <cos@plt>
sub    %rax,%r14
mov    %r14,%rdi
call   1040 <my_abs@plt>
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <scanf@plt>
test   %rax,%rax
jne    11c0 <main+0x60>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Enter value for cos:\0A\00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [22 x i8] c"my_cos(%lf) = %1.9lf\0A\00"
@.str.3 = [19 x i8] c"cos(%lf) = %1.9lf\0A\00"
@.str.4 = [16 x i8] c"diff = %1.9lf\0A\0A\00"
@.str.5 = [30 x i8] c"Enter another value for cos:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
store i32 0, i32* %1
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %7, %0
%5 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %2)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %24
7: ; preds = %4
%8 = load double, double* %2
%9 = load double, double* %2
%10 = call i64 @my_cos(double %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), double %8, i64 %10)
%12 = load double, double* %2
%13 = load double, double* %2
%14 = call i64 @cos(double %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), double %12, i64 %14)
%16 = load double, double* %2
%17 = call i64 @my_cos(double %16)
%18 = load double, double* %2
%19 = call i64 @cos(double %18)
%20 = sub nsw i64 %17, %19
%21 = call i32 @my_abs(i64 %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %4
24: ; preds = %4
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [22 x i8] c"my_cos(%lf) = %1.9lf\0A\00"
@.str.3 = [19 x i8] c"cos(%lf) = %1.9lf\0A\00"
@.str.4 = [16 x i8] c"diff = %1.9lf\0A\0A\00"
@str = [21 x i8] c"Enter value for cos:\00"
@str.6 = [29 x i8] c"Enter another value for cos:\00"
define i32 @main() {
%1 = alloca double
%2 = bitcast double* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%4 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %23, label %6
6: ; preds = %0, %6
%7 = load double, double* %1
%8 = call i64 @my_cos(double %7)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), double %7, i64 %8)
%10 = load double, double* %1
%11 = call i64 @cos(double %10)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), double %10, i64 %11)
%13 = load double, double* %1
%14 = call i64 @my_cos(double %13)
%15 = load double, double* %1
%16 = call i64 @cos(double %15)
%17 = sub nsw i64 %14, %16
%18 = call i32 @my_abs(i64 %17)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %18)
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.6, i64 0, i64 0))
%21 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %1)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %6
23: ; preds = %6, %0
ret i32 0
}