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


x86 assembly (clang, -O0):
<task>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0xf4240,-0x10(%rbp)
jge    11af <task+0x7f>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <sin@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%edi
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),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115b <task+0x2b>
mov    -0xc(%rbp),%esi
movsd  -0x18(%rbp),%xmm0
lea    0xe53(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<task>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
lea    0xec1(%rip),%rdi
xor    %ebp,%ebp
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xorpd  %xmm0,%xmm0
xchg   %ax,%ax
movsd  %xmm0,0x8(%rsp)
mov    %ebp,%edi
call   1040 <sin@plt>
movsd  %xmm0,0x10(%rsp)
mov    %ebp,%edi
call   1050 <tan@plt>
mulsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x1,%ebp
cmp    $0xf4240,%ebp
jne    1150 <task+0x20>
lea    0xe79(%rip),%rdi
mov    %ebx,%esi
mov    $0x1,%al
add    $0x18,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <printf@plt>

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

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