#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 *, long, ...);
int /*<<< orphan*/ pthread_exit(void *);
double sin(int);
double tan(int);
void *fBusyWork(void *tharg) {
  int i;
  long thd;
  double result = 0.0;
  thd = (long)tharg;
  printf("Thread %ld start...\n", thd);
  for (i = 0; i < 1000000; i++) {
    result = result + sin(i) * tan(i);
  }
  printf("Thread %ld done. Result = %e\n", thd, result);
  pthread_exit((void *)(long)result);
}


x86 assembly (clang, -O0):
<fBusyWork>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xf4240,-0x14(%rbp)
jge    11c9 <fBusyWork+0x89>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <sin@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x14(%rbp),%edi
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    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1175 <fBusyWork+0x35>
mov    -0x20(%rbp),%rsi
movsd  -0x28(%rbp),%xmm0
lea    0xe3c(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
cvttsd2si -0x28(%rbp),%rdi
call   1050 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fBusyWork>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0xeb0(%rip),%rdi
xor    %ebp,%ebp
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %ebp,%edi
call   1040 <sin@plt>
movsd  %xmm0,0x10(%rsp)
mov    %ebp,%edi
call   1060 <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    1160 <fBusyWork+0x20>
lea    0xe6d(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%al
call   1030 <printf@plt>
cvttsd2si 0x8(%rsp),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <pthread_exit@plt>

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

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