#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 M_PI;
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/ *);
scalar_t__ sin(int);
void *thread(void *arg) {
  int i;
  double *res = (double *)arg;
  for (i = 0; i < 20000000; i++) {
    *res += sin(M_PI * (1 + 4 * i) / 2);
  }
  pthread_exit(NULL);
}


x86 assembly (clang, -O0):
<thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x1312d00,-0x14(%rbp)
jge    118b <thread+0x6b>
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    -0x14(%rbp),%ecx
shl    $0x2,%ecx
add    $0x1,%ecx
imul   %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1030 <sin@plt>
cvtsi2sd %rax,%xmm0
mov    -0x20(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113b <thread+0x1b>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0x1,%ebp
mov    0x2eb5(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r14),%eax
imul   %ebp,%eax
mov    %eax,%edi
shr    $0x1f,%edi
add    %eax,%edi
sar    %edi
call   1030 <sin@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  (%rbx),%xmm0
movsd  %xmm0,(%rbx)
add    $0x4,%ebp
cmp    $0x4c4b401,%ebp
jne    1140 <thread+0x20>
xor    %edi,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <pthread_exit@plt>

LLVM IR (-O0):
@M_PI = global i32 0
define i8* @thread(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca double*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = bitcast i8* %6 to double*
store double* %7, double** %5
store i32 0, i32* %4
br label %8
8: ; preds = %23, %1
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 20000000
br i1 %10, label %11, label %26
11: ; preds = %8
%12 = load i32, i32* @M_PI
%13 = load i32, i32* %4
%14 = mul nsw i32 4, %13
%15 = add nsw i32 1, %14
%16 = mul nsw i32 %12, %15
%17 = sdiv i32 %16, 2
%18 = call i64 @sin(i32 %17)
%19 = sitofp i64 %18 to double
%20 = load double*, double** %5
%21 = load double, double* %20
%22 = fadd double %21, %19
store double %22, double* %20
br label %23
23: ; preds = %11
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %8
26: ; preds = %8
%27 = call i32 @pthread_exit(i32* null)
%28 = load i8*, i8** %2
ret i8* %28
}

LLVM IR (-O2):
@M_PI = global i32 0
define noalias i8* @thread(i8* nocapture %0) {
%2 = bitcast i8* %0 to double*
br label %3
3: ; preds = %1, %3
%4 = phi i32 [ 0, %1 ], [ %14, %3 ]
%5 = load i32, i32* @M_PI
%6 = shl nuw nsw i32 %4, 2
%7 = or i32 %6, 1
%8 = mul nsw i32 %5, %7
%9 = sdiv i32 %8, 2
%10 = tail call i64 @sin(i32 %9)
%11 = sitofp i64 %10 to double
%12 = load double, double* %2
%13 = fadd double %12, %11
store double %13, double* %2
%14 = add nuw nsw i32 %4, 1
%15 = icmp eq i32 %14, 20000000
br i1 %15, label %16, label %3
16: ; preds = %3
%17 = tail call i32 @pthread_exit(i32* null)
ret i8* undef
}