#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 *, ...);
int main(int argc, char **argv) {
  const long N = 1e10;
  const long M = 13;
  double sum = 0.0;
  double sums[4] = {0.0};
  if (argc == 1) {
    printf("this is how I roll...\n");
    for (long i = 0; i < N; i++) {
      sum += M;
    }
  } else {
    printf("this is how I unroll...\n");
    for (long i = 0; i < N; i += 4) {
      sums[0] += M;
      sums[1] += M;
      sums[2] += M;
      sums[3] += M;
    }
    for (int i = 0; i < 4; i++) {
      sum += sums[i];
    }
  }
  printf("sum = %e\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movabs $0x2540be400,%rax
mov    %rax,-0x18(%rbp)
movq   $0xd,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
cmpl   $0x1,-0x8(%rbp)
jne    11c0 <main+0xa0>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x58(%rbp)
movabs $0x2540be400,%rax
cmp    %rax,-0x58(%rbp)
jge    11bb <main+0x9b>
movsd  0xe60(%rip),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    1184 <main+0x64>
jmp    127b <main+0x15b>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x60(%rbp)
movabs $0x2540be400,%rax
cmp    %rax,-0x60(%rbp)
jge    1243 <main+0x123>
movsd  0xe0e(%rip),%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xdfc(%rip),%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xdea(%rip),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xdd8(%rip),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x60(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x60(%rbp)
jmp    11d6 <main+0xb6>
movl   $0x0,-0x64(%rbp)
cmpl   $0x4,-0x64(%rbp)
jge    1276 <main+0x156>
movslq -0x64(%rbp),%rax
movsd  -0x50(%rbp,%rax,8),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    124a <main+0x12a>
jmp    127b <main+0x15b>
movsd  -0x28(%rbp),%xmm0
lea    0xdb1(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
movabs $0x2540be3d8,%rbx
cmp    $0x1,%edi
jne    117b <main+0x5b>
lea    0xf03(%rip),%rdi
call   1030 <puts@plt>
add    $0x28,%rbx
xorpd  %xmm0,%xmm0
movsd  0xec4(%rip),%xmm1
nopl   0x0(%rax)
addsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
add    $0xfffffffffffffff8,%rbx
jne    1150 <main+0x30>
jmp    1215 <main+0xf5>
lea    0xea0(%rip),%rdi
call   1030 <puts@plt>
xorpd  %xmm1,%xmm1
mov    $0xffffffffffffffd8,%rax
movapd 0xe66(%rip),%xmm2
xorpd  %xmm0,%xmm0
xchg   %ax,%ax
addpd  %xmm2,%xmm0
addpd  %xmm2,%xmm1
addpd  %xmm2,%xmm1
addpd  %xmm2,%xmm0
addpd  %xmm2,%xmm0
addpd  %xmm2,%xmm1
addpd  %xmm2,%xmm1
addpd  %xmm2,%xmm0
addpd  %xmm2,%xmm0
addpd  %xmm2,%xmm1
addpd  %xmm2,%xmm1
addpd  %xmm2,%xmm0
addpd  %xmm2,%xmm0
addpd  %xmm2,%xmm1
addpd  %xmm2,%xmm1
addpd  %xmm2,%xmm0
addpd  %xmm2,%xmm0
addpd  %xmm2,%xmm1
addpd  %xmm2,%xmm1
addpd  %xmm2,%xmm0
add    $0x28,%rax
cmp    %rbx,%rax
jb     11a0 <main+0x80>
xorpd  %xmm2,%xmm2
addsd  %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
lea    0xdfc(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"this is how I roll...\0A\00"
@.str.1 = [25 x i8] c"this is how I unroll...\0A\00"
@.str.2 = [10 x i8] c"sum = %e\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca double
%9 = alloca [4 x double]
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 10000000000, i64* %6
store i64 13, i64* %7
store double 0.000000e+00, double* %8
%13 = bitcast [4 x double]* %9 to i8*
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %28
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* %10
br label %18
18: ; preds = %24, %16
%19 = load i64, i64* %10
%20 = icmp slt i64 %19, 10000000000
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load double, double* %8
%23 = fadd double %22, 1.300000e+01
store double %23, double* %8
br label %24
24: ; preds = %21
%25 = load i64, i64* %10
%26 = add nsw i64 %25, 1
store i64 %26, i64* %10
br label %18
27: ; preds = %18
br label %64
28: ; preds = %2
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i64 0, i64* %11
br label %30
30: ; preds = %46, %28
%31 = load i64, i64* %11
%32 = icmp slt i64 %31, 10000000000
br i1 %32, label %33, label %49
33: ; preds = %30
%34 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
%35 = load double, double* %34
%36 = fadd double %35, 1.300000e+01
store double %36, double* %34
%37 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 1
%38 = load double, double* %37
%39 = fadd double %38, 1.300000e+01
store double %39, double* %37
%40 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 2
%41 = load double, double* %40
%42 = fadd double %41, 1.300000e+01
store double %42, double* %40
%43 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 3
%44 = load double, double* %43
%45 = fadd double %44, 1.300000e+01
store double %45, double* %43
br label %46
46: ; preds = %33
%47 = load i64, i64* %11
%48 = add nsw i64 %47, 4
store i64 %48, i64* %11
br label %30
49: ; preds = %30
store i32 0, i32* %12
br label %50
50: ; preds = %60, %49
%51 = load i32, i32* %12
%52 = icmp slt i32 %51, 4
br i1 %52, label %53, label %63
53: ; preds = %50
%54 = load i32, i32* %12
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 %55
%57 = load double, double* %56
%58 = load double, double* %8
%59 = fadd double %58, %57
store double %59, double* %8
br label %60
60: ; preds = %53
%61 = load i32, i32* %12
%62 = add nsw i32 %61, 1
store i32 %62, i32* %12
br label %50
63: ; preds = %50
br label %64
64: ; preds = %63, %27
%65 = load double, double* %8
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double %65)
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [10 x i8] c"sum = %e\0A\00"
@str = [24 x i8] c"this is how I unroll...\00"
@str.3 = [22 x i8] c"this is how I roll...\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %4, label %19
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.3, i64 0, i64 0))
br label %6
6: ; preds = %6, %4
%7 = phi double [ 0.000000e+00, %4 ], [ %16, %6 ]
%8 = phi i64 [ 0, %4 ], [ %17, %6 ]
%9 = fadd double %7, 1.300000e+01
%10 = fadd double %9, 1.300000e+01
%11 = fadd double %10, 1.300000e+01
%12 = fadd double %11, 1.300000e+01
%13 = fadd double %12, 1.300000e+01
%14 = fadd double %13, 1.300000e+01
%15 = fadd double %14, 1.300000e+01
%16 = fadd double %15, 1.300000e+01
%17 = add nuw nsw i64 %8, 8
%18 = icmp eq i64 %17, 10000000000
br i1 %18, label %45, label %6
19: ; preds = %2
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %30
21: ; preds = %30
%22 = extractelement <4 x double> %42, i64 0
%23 = fadd double %22, 0.000000e+00
%24 = extractelement <4 x double> %42, i64 1
%25 = fadd double %23, %24
%26 = extractelement <4 x double> %42, i64 2
%27 = fadd double %25, %26
%28 = extractelement <4 x double> %42, i64 3
%29 = fadd double %27, %28
br label %45
30: ; preds = %30, %19
%31 = phi i64 [ 0, %19 ], [ %43, %30 ]
%32 = phi <4 x double> [ zeroinitializer, %19 ], [ %42, %30 ]
%33 = fadd <4 x double> %32, <double 1.300000e+01, double 1.300000e+01, double 1.300000e+01, double 1.300000e+01>
%34 = fadd <4 x double> %33, <double 1.300000e+01, double 1.300000e+01, double 1.300000e+01, double 1.300000e+01>
%35 = fadd <4 x double> %34, <double 1.300000e+01, double 1.300000e+01, double 1.300000e+01, double 1.300000e+01>
%36 = fadd <4 x double> %35, <double 1.300000e+01, double 1.300000e+01, double 1.300000e+01, double 1.300000e+01>
%37 = fadd <4 x double> %36, <double 1.300000e+01, double 1.300000e+01, double 1.300000e+01, double 1.300000e+01>
%38 = fadd <4 x double> %37, <double 1.300000e+01, double 1.300000e+01, double 1.300000e+01, double 1.300000e+01>
%39 = fadd <4 x double> %38, <double 1.300000e+01, double 1.300000e+01, double 1.300000e+01, double 1.300000e+01>
%40 = fadd <4 x double> %39, <double 1.300000e+01, double 1.300000e+01, double 1.300000e+01, double 1.300000e+01>
%41 = fadd <4 x double> %40, <double 1.300000e+01, double 1.300000e+01, double 1.300000e+01, double 1.300000e+01>
%42 = fadd <4 x double> %41, <double 1.300000e+01, double 1.300000e+01, double 1.300000e+01, double 1.300000e+01>
%43 = add nuw nsw i64 %31, 40
%44 = icmp ult i64 %31, 9999999960
br i1 %44, label %30, label %21
45: ; preds = %6, %21
%46 = phi double [ %29, %21 ], [ %16, %6 ]
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double %46)
ret i32 0
}