#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 atoi(char const *);
int /*<<< orphan*/ printf(char *, double);
double *rand_double_arr(int);
double res;
int main(int argc, const char **argv) {
  int size = 512;
  if (argc > 1) {
    size = atoi(argv[1]);
  }
  double *arr = rand_double_arr(size);
  double res = (res, arr, 5.0, size);
  for (int i = 0; i < size; ++i) {
    printf("%lf ", arr[i]);
  }
  printf("reduce: %lf", res);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x200,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1167 <main+0x37>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <rand_double_arr@plt>
mov    %rax,-0x20(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b7 <main+0x87>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1184 <main+0x54>
movsd  -0x28(%rbp),%xmm0
lea    0xe42(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x1,%edi
jle    1157 <main+0x27>
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
mov    %eax,%r14d
mov    %eax,%edi
call   1040 <rand_double_arr@plt>
test   %r14d,%r14d
jg     1167 <main+0x37>
jmp    1197 <main+0x67>
mov    $0x200,%r14d
mov    $0x200,%edi
call   1040 <rand_double_arr@plt>
mov    %rax,%r12
mov    %r14d,%ebp
xor    %ebx,%ebx
lea    0xe8a(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
movsd  (%r12,%rbx,8),%xmm0
mov    %r15,%rdi
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <main+0x50>
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
lea    0xe5f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%lf \00"
@.str.1 = [12 x i8] c"reduce: %lf\00"
@res = global double 0.000000e+00
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca double*
%8 = alloca double
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 512, i32* %6
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %6
br label %17
17: ; preds = %12, %2
%18 = load i32, i32* %6
%19 = call double* @rand_double_arr(i32 %18)
store double* %19, double** %7
%20 = load double, double* %8
%21 = load double*, double** %7
%22 = load i32, i32* %6
%23 = sitofp i32 %22 to double
store double %23, double* %8
store i32 0, i32* %9
br label %24
24: ; preds = %35, %17
%25 = load i32, i32* %9
%26 = load i32, i32* %6
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %38
28: ; preds = %24
%29 = load double*, double** %7
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %29, i64 %31
%33 = load double, double* %32
%34 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %33)
br label %35
35: ; preds = %28
%36 = load i32, i32* %9
%37 = add nsw i32 %36, 1
store i32 %37, i32* %9
br label %24
38: ; preds = %24
%39 = load double, double* %8
%40 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %39)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%lf \00"
@.str.1 = [12 x i8] c"reduce: %lf\00"
@res = global double 0.000000e+00
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call double* @rand_double_arr(i32 512)
br label %12
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = tail call double* @rand_double_arr(i32 %9)
%11 = icmp sgt i32 %9, 0
br i1 %11, label %12, label %16
12: ; preds = %4, %6
%13 = phi double* [ %5, %4 ], [ %10, %6 ]
%14 = phi i32 [ 512, %4 ], [ %9, %6 ]
%15 = zext i32 %14 to i64
br label %20
16: ; preds = %20, %6
%17 = phi i32 [ %9, %6 ], [ %14, %20 ]
%18 = sitofp i32 %17 to double
%19 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %18)
ret i32 0
20: ; preds = %12, %20
%21 = phi i64 [ 0, %12 ], [ %25, %20 ]
%22 = getelementptr inbounds double, double* %13, i64 %21
%23 = load double, double* %22
%24 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %23)
%25 = add nuw nsw i64 %21, 1
%26 = icmp eq i64 %25, %15
br i1 %26, label %16, label %20
}