#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);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
double sin(double);
int /*<<< orphan*/ stdin;
double strtod(char *, int /*<<< orphan*/ *);
double tan(double);
int main(int argc, char **argv) {
  char input[25];
  double angle;
  printf("Give me an angle (in radians) ==> ");
  if (!fgets(input, 25, stdin)) {
    perror("an error occured.\n");
  }
  angle = strtod(input, NULL);
  printf("sin(%e) = %e\n", angle, sin(angle));
  printf("cos(%e) = %e\n", angle, cos(angle));
  printf("tan(%e) = %e\n", angle, tan(angle));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
mov    $0x19,%esi
call   1050 <fgets@plt>
cmp    $0x0,%eax
jne    11c0 <main+0x50>
lea    0xe68(%rip),%rdi
call   1090 <perror@plt>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtod@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1060 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
lea    0xe41(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1080 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
lea    0xe25(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1070 <tan@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
lea    0xe09(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x38,%rsp
lea    0xe85(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rdi
mov    $0x19,%esi
call   1050 <fgets@plt>
test   %eax,%eax
je     1217 <main+0xa7>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
movsd  %xmm0,0x8(%rsp)
call   1060 <sin@plt>
movaps %xmm0,%xmm1
lea    0xe77(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x2,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
call   1080 <cos@plt>
movaps %xmm0,%xmm1
lea    0xe63(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x2,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
call   1070 <tan@plt>
movaps %xmm0,%xmm1
lea    0xe4f(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x2,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
ret
lea    0xe05(%rip),%rdi
call   1090 <perror@plt>
jmp    119e <main+0x2e>

LLVM IR (-O0):
@.str = [35 x i8] c"Give me an angle (in radians) ==> \00"
@stdin = global i32 0
@.str.1 = [19 x i8] c"an error occured.\0A\00"
@.str.2 = [14 x i8] c"sin(%e) = %e\0A\00"
@.str.3 = [14 x i8] c"cos(%e) = %e\0A\00"
@.str.4 = [14 x i8] c"tan(%e) = %e\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [25 x i8]
%7 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [25 x i8], [25 x i8]* %6, i64 0, i64 0
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %9, i32 25, i32 %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = getelementptr inbounds [25 x i8], [25 x i8]* %6, i64 0, i64 0
%17 = call double @strtod(i8* %16, i32* null)
store double %17, double* %7
%18 = load double, double* %7
%19 = load double, double* %7
%20 = call double @sin(double %19)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double %18, double %20)
%22 = load double, double* %7
%23 = load double, double* %7
%24 = call double @cos(double %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), double %22, double %24)
%26 = load double, double* %7
%27 = load double, double* %7
%28 = call double @tan(double %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), double %26, double %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [35 x i8] c"Give me an angle (in radians) ==> \00"
@stdin = global i32 0
@.str.1 = [19 x i8] c"an error occured.\0A\00"
@.str.2 = [14 x i8] c"sin(%e) = %e\0A\00"
@.str.3 = [14 x i8] c"cos(%e) = %e\0A\00"
@.str.4 = [14 x i8] c"tan(%e) = %e\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [25 x i8]
%4 = getelementptr inbounds [25 x i8], [25 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %4, i32 25, i32 %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
%12 = call double @strtod(i8* nocapture %4, i32* null)
%13 = call double @sin(double %12)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double %12, double %13)
%15 = call double @cos(double %12)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), double %12, double %15)
%17 = call double @tan(double %12)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), double %12, double %17)
ret i32 0
}