#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, ...);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/);
double sin(long);
double tan(long);
void *task(void *t) {
  long id = (long)t;
  printf("Thread %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("Thread %ld completed with result %e\n", id, result);
  pthread_exit(0);
}


x86 assembly (clang, -O0):
<task>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x989680,-0x20(%rbp)
jge    11fa <task+0xaa>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <sin@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <tan@plt>
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1186 <task+0x36>
mov    -0x18(%rbp),%rsi
movsd  -0x28(%rbp),%xmm0
lea    0xe0a(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<task>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
lea    0xe9f(%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   1070 <cos@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1060 <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    1180 <task+0x30>
lea    0xe34(%rip),%rdi
mov    %r14,%rsi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %edi,%edi
add    $0x18,%rsp
pop    %rbx
pop    %r14
jmp    1050 <pthread_exit@plt>

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

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