#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(long);
int /*<<< orphan*/ printf(char *, ...);
double sin(long);
double tan(long);
void task() {
  printf("Task started\n");
  long i;
  double result = 0.0;
  for (i = 0; i < 10000000; i++) {
    result = result + sin(i) * cos(i) * tan(i);
  }
  printf("Task completed with result %e\n", result);
}


x86 assembly (clang, -O0):
<task>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movq   $0x0,-0x8(%rbp)
cmpq   $0x989680,-0x8(%rbp)
jge    11da <task+0x9a>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <sin@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <tan@plt>
movsd  -0x20(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x18(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1166 <task+0x26>
movsd  -0x10(%rbp),%xmm0
lea    0xe28(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<task>:
push   %rbx
sub    $0x10,%rsp
lea    0xec3(%rip),%rdi
call   1030 <puts@plt>
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1050 <sin@plt>
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1070 <cos@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1060 <tan@plt>
mulsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x1,%rbx
cmp    $0x989680,%rbx
jne    1170 <task+0x20>
lea    0xe34(%rip),%rdi
mov    $0x1,%al
add    $0x10,%rsp
pop    %rbx
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"Task started\0A\00"
@.str.1 = [31 x i8] c"Task completed with result %e\0A\00"
define void @task() {
%1 = alloca i64
%2 = alloca double
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store double 0.000000e+00, double* %2
store i64 0, i64* %1
br label %4
4: ; preds = %17, %0
%5 = load i64, i64* %1
%6 = icmp slt i64 %5, 10000000
br i1 %6, label %7, label %20
7: ; preds = %4
%8 = load double, double* %2
%9 = load i64, i64* %1
%10 = call double @sin(i64 %9)
%11 = load i64, i64* %1
%12 = call double @cos(i64 %11)
%13 = fmul double %10, %12
%14 = load i64, i64* %1
%15 = call double @tan(i64 %14)
%16 = call double @llvm.fmuladd.f64(double %13, double %15, double %8)
store double %16, double* %2
br label %17
17: ; preds = %7
%18 = load i64, i64* %1
%19 = add nsw i64 %18, 1
store i64 %19, i64* %1
br label %4
20: ; preds = %4
%21 = load double, double* %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), double %21)
ret void
}

LLVM IR (-O2):
@.str.1 = [31 x i8] c"Task completed with result %e\0A\00"
@str = [13 x i8] c"Task started\00"
define void @task() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %2
2: ; preds = %0, %2
%3 = phi double [ 0.000000e+00, %0 ], [ %9, %2 ]
%4 = phi i64 [ 0, %0 ], [ %10, %2 ]
%5 = tail call double @sin(i64 %4)
%6 = tail call double @cos(i64 %4)
%7 = fmul double %5, %6
%8 = tail call double @tan(i64 %4)
%9 = tail call double @llvm.fmuladd.f64(double %7, double %8, double %3)
%10 = add nuw nsw i64 %4, 1
%11 = icmp eq i64 %10, 10000000
br i1 %11, label %12, label %2
12: ; preds = %2
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), double %9)
ret void
}