#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 */
scalar_t__ cos(double);
int /*<<< orphan*/ dtime(double *);
int omp_get_thread_num();
int /*<<< orphan*/ printf(char *, double, ...);
scalar_t__ sin(double);
int main(int argc, char *argv[]) {
  int i, is, ie, id, N, NT;
  double sum;
  double stime, etime;
  dtime(&stime);
  N = 300000000;
  NT = 4;
#pragma omp parallel private(i, id, is, ie, sum)
  {
    id = omp_get_thread_num();
    is = id * N / NT;
    ie = (id + 1) * N / NT;
    printf("%d is=%2d ie=%2d\n", id, is, ie);
    sum = 0.0;
    for (i = is; i < ie; i++) {
      sum += sin((double)i) + cos((double)i);
    }
    printf("%15.12f\n", sum);
  }
  dtime(&etime);
  printf("Elapsed time (s)=%15.12f\n", etime - stime);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x38(%rbp),%rdi
call   1060 <dtime@plt>
movl   $0x11e1a300,-0x24(%rbp)
movl   $0x4,-0x28(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
imul   -0x24(%rbp),%eax
cltd
idivl  -0x28(%rbp)
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
imul   -0x24(%rbp),%eax
cltd
idivl  -0x28(%rbp)
mov    %eax,-0x1c(%rbp)
cvtsi2sdl -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe48(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1218 <main+0xc8>
cvtsi2sdl -0x14(%rbp),%xmm0
call   1050 <sin@plt>
mov    %rax,-0x48(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
call   1070 <cos@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
add    %rcx,%rax
cvtsi2sd %rax,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11cd <main+0x7d>
movsd  -0x30(%rbp),%xmm0
lea    0xdff(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
call   1060 <dtime@plt>
movsd  -0x40(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
lea    0xdcd(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0x20(%rsp),%rdi
call   1060 <dtime@plt>
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
imul   $0x47868c0,%eax,%ebx
imul   $0x11e1a300,%eax,%r14d
lea    0x11e1a300(%r14),%ecx
add    $0x11e1a303,%r14d
test   %ecx,%ecx
cmovns %ecx,%r14d
sar    $0x2,%r14d
cvtsi2sd %eax,%xmm0
lea    0xe65(%rip),%rdi
mov    %ebx,%esi
mov    %r14d,%edx
mov    $0x1,%al
call   1040 <printf@plt>
xorpd  %xmm0,%xmm0
cmp    %ebx,%r14d
jle    1289 <main+0x139>
mov    %ebx,%ebp
or     $0x1,%ebp
test   $0x1,%r14b
jne    11cd <main+0x7d>
xorpd  %xmm0,%xmm0
cmp    %ebp,%r14d
jne    1210 <main+0xc0>
jmp    1289 <main+0x139>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1050 <sin@plt>
mov    %rax,%rbx
movsd  0x8(%rsp),%xmm0
call   1070 <cos@plt>
add    %rbx,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    %ebp,%ebx
cmp    %ebp,%r14d
je     1289 <main+0x139>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  %xmm0,0x10(%rsp)
call   1050 <sin@plt>
mov    %rax,%r15
movsd  0x10(%rsp),%xmm0
call   1070 <cos@plt>
add    %r15,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0x1(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x10(%rsp)
call   1050 <sin@plt>
mov    %rax,%r15
movsd  0x10(%rsp),%xmm0
call   1070 <cos@plt>
add    %r15,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x8(%rsp),%xmm0
add    $0x2,%ebx
cmp    %r14d,%ebx
jne    1210 <main+0xc0>
lea    0xd93(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0x18(%rsp),%rdi
call   1060 <dtime@plt>
movsd  0x18(%rsp),%xmm0
subsd  0x20(%rsp),%xmm0
lea    0xd5e(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"%d is=%2d ie=%2d\0A\00"
@.str.1 = [9 x i8] c"%15.12f\0A\00"
@.str.2 = [26 x i8] c"Elapsed time (s)=%15.12f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca double
%13 = alloca double
%14 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = call i32 @dtime(double* %13)
store i32 300000000, i32* %10
store i32 4, i32* %11
%16 = call i32 (...) @omp_get_thread_num()
store i32 %16, i32* %9
%17 = load i32, i32* %9
%18 = load i32, i32* %10
%19 = mul nsw i32 %17, %18
%20 = load i32, i32* %11
%21 = sdiv i32 %19, %20
store i32 %21, i32* %7
%22 = load i32, i32* %9
%23 = add nsw i32 %22, 1
%24 = load i32, i32* %10
%25 = mul nsw i32 %23, %24
%26 = load i32, i32* %11
%27 = sdiv i32 %25, %26
store i32 %27, i32* %8
%28 = load i32, i32* %9
%29 = sitofp i32 %28 to double
%30 = load i32, i32* %7
%31 = load i32, i32* %8
%32 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double %29, i32 %30, i32 %31)
store double 0.000000e+00, double* %12
%33 = load i32, i32* %7
store i32 %33, i32* %6
br label %34
34: ; preds = %49, %2
%35 = load i32, i32* %6
%36 = load i32, i32* %8
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %52
38: ; preds = %34
%39 = load i32, i32* %6
%40 = sitofp i32 %39 to double
%41 = call i64 @sin(double %40)
%42 = load i32, i32* %6
%43 = sitofp i32 %42 to double
%44 = call i64 @cos(double %43)
%45 = add nsw i64 %41, %44
%46 = sitofp i64 %45 to double
%47 = load double, double* %12
%48 = fadd double %47, %46
store double %48, double* %12
br label %49
49: ; preds = %38
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
store i32 %51, i32* %6
br label %34
52: ; preds = %34
%53 = load double, double* %12
%54 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %53)
%55 = call i32 @dtime(double* %14)
%56 = load double, double* %14
%57 = load double, double* %13
%58 = fsub double %56, %57
%59 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), double %58)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"%d is=%2d ie=%2d\0A\00"
@.str.1 = [9 x i8] c"%15.12f\0A\00"
@.str.2 = [26 x i8] c"Elapsed time (s)=%15.12f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca double
%4 = alloca double
%5 = bitcast double* %3 to i8*
%6 = bitcast double* %4 to i8*
%7 = call i32 @dtime(double* %3)
%8 = call i32 (...) @omp_get_thread_num()
%9 = mul nsw i32 %8, 75000000
%10 = mul i32 %8, 300000000
%11 = add i32 %10, 300000000
%12 = sdiv i32 %11, 4
%13 = sitofp i32 %8 to double
%14 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double %13, i32 %9, i32 %12)
%15 = icmp sgt i32 %12, %9
br i1 %15, label %16, label %50
16: ; preds = %2
%17 = or i32 %9, 1
%18 = and i32 %12, 1
%19 = icmp eq i32 %18, 0
br i1 %19, label %27, label %20
20: ; preds = %16
%21 = sitofp i32 %9 to double
%22 = call i64 @sin(double %21)
%23 = call i64 @cos(double %21)
%24 = add nsw i64 %23, %22
%25 = sitofp i64 %24 to double
%26 = or i32 %9, 1
br label %27
27: ; preds = %20, %16
%28 = phi double [ undef, %16 ], [ %25, %20 ]
%29 = phi double [ 0.000000e+00, %16 ], [ %25, %20 ]
%30 = phi i32 [ %9, %16 ], [ %26, %20 ]
%31 = icmp eq i32 %12, %17
br i1 %31, label %50, label %32
32: ; preds = %27, %32
%33 = phi double [ %47, %32 ], [ %29, %27 ]
%34 = phi i32 [ %48, %32 ], [ %30, %27 ]
%35 = sitofp i32 %34 to double
%36 = call i64 @sin(double %35)
%37 = call i64 @cos(double %35)
%38 = add nsw i64 %37, %36
%39 = sitofp i64 %38 to double
%40 = fadd double %33, %39
%41 = add i32 %34, 1
%42 = sitofp i32 %41 to double
%43 = call i64 @sin(double %42)
%44 = call i64 @cos(double %42)
%45 = add nsw i64 %44, %43
%46 = sitofp i64 %45 to double
%47 = fadd double %40, %46
%48 = add i32 %34, 2
%49 = icmp eq i32 %48, %12
br i1 %49, label %50, label %32
50: ; preds = %27, %32, %2
%51 = phi double [ 0.000000e+00, %2 ], [ %28, %27 ], [ %47, %32 ]
%52 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %51)
%53 = call i32 @dtime(double* %4)
%54 = load double, double* %4
%55 = load double, double* %3
%56 = fsub double %54, %55
%57 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), double %56)
ret i32 0
}