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


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

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

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

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