#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(int);
int /*<<< orphan*/ foo();
int /*<<< orphan*/ printf(char *, int);
scalar_t__ sin(int);
main() {
  double res = 0.;
  int i, j;
  for (j = 0; j < 10; j++) {
    for (i = 0; i < 150000; i++) {
      if (i % 2 == 0) {
        res += cos(1. / (double)(i + 1));
      } else {
        res += sin(1. / (double)(i + 1));
      }
    }
    foo();
  }
  printf("all done: %d iters\n", i);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0xa,-0x18(%rbp)
jge    1219 <main+0xd9>
movl   $0x0,-0x14(%rbp)
cmpl   $0x249f0,-0x14(%rbp)
jge    1204 <main+0xc4>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11c3 <main+0x83>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe5e(%rip),%xmm0
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1060 <cos@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11f1 <main+0xb1>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe2b(%rip),%xmm0
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sin@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11f6 <main+0xb6>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116f <main+0x2f>
mov    $0x0,%al
call   1050 <foo@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115e <main+0x1e>
mov    -0x14(%rbp),%esi
lea    0xde5(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
jmp    115f <main+0x1f>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <foo@plt>
add    $0x1,%ebp
cmp    $0xa,%ebp
je     11a5 <main+0x65>
mov    $0x1,%ebx
jmp    1180 <main+0x40>
cs nopw 0x0(%rax,%rax,1)
call   1040 <sin@plt>
add    $0x1,%ebx
cmp    $0x249f1,%ebx
je     1150 <main+0x10>
lea    0x1(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  0xe6e(%rip),%xmm1
divsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
test   $0x1,%al
jne    1170 <main+0x30>
call   1060 <cos@plt>
jmp    1175 <main+0x35>
lea    0xe5c(%rip),%rdi
mov    $0x249f0,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"all done: %d iters\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store double 0.000000e+00, double* %2
store i32 0, i32* %4
br label %5
5: ; preds = %42, %0
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 10
br i1 %7, label %8, label %45
8: ; preds = %5
store i32 0, i32* %3
br label %9
9: ; preds = %37, %8
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 150000
br i1 %11, label %12, label %40
12: ; preds = %9
%13 = load i32, i32* %3
%14 = srem i32 %13, 2
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %12
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
%19 = sitofp i32 %18 to double
%20 = fdiv double 1.000000e+00, %19
%21 = fptosi double %20 to i32
%22 = call i64 @cos(i32 %21)
%23 = sitofp i64 %22 to double
%24 = load double, double* %2
%25 = fadd double %24, %23
store double %25, double* %2
br label %36
26: ; preds = %12
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
%29 = sitofp i32 %28 to double
%30 = fdiv double 1.000000e+00, %29
%31 = fptosi double %30 to i32
%32 = call i64 @sin(i32 %31)
%33 = sitofp i64 %32 to double
%34 = load double, double* %2
%35 = fadd double %34, %33
store double %35, double* %2
br label %36
36: ; preds = %26, %16
br label %37
37: ; preds = %36
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
store i32 %39, i32* %3
br label %9
40: ; preds = %9
%41 = call i32 (...) @foo()
br label %42
42: ; preds = %40
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 1
store i32 %44, i32* %4
br label %5
45: ; preds = %5
%46 = load i32, i32* %3
%47 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@.str = [20 x i8] c"all done: %d iters\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %17
%2 = phi i32 [ 0, %0 ], [ %19, %17 ]
br label %3
3: ; preds = %1, %15
%4 = phi i32 [ 0, %1 ], [ %7, %15 ]
%5 = and i32 %4, 1
%6 = icmp eq i32 %5, 0
%7 = add nuw nsw i32 %4, 1
%8 = sitofp i32 %7 to double
%9 = fdiv double 1.000000e+00, %8
%10 = fptosi double %9 to i32
br i1 %6, label %11, label %13
11: ; preds = %3
%12 = tail call i64 @cos(i32 %10)
br label %15
13: ; preds = %3
%14 = tail call i64 @sin(i32 %10)
br label %15
15: ; preds = %11, %13
%16 = icmp eq i32 %7, 150000
br i1 %16, label %17, label %3
17: ; preds = %15
%18 = tail call i32 (...) @foo()
%19 = add nuw nsw i32 %2, 1
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %1
21: ; preds = %17
%22 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 150000)
ret i32 0
}