#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 *, ...);
double vecsum(double *, int);
void printvec(double *x, int n) {
  printf("(");
  int i, m = (n <= 6 ? n : 6);
  for (i = 0; i < m; ++i)
    printf("%g, ", x[i]);
  if (n > 6) {
    printf("\n");
    m = (n <= 12 ? 6 : n - 6);
    for (i = m; i < n; ++i)
      printf("%g, ", x[i]);
  }
  printf("), sum is %g\n", vecsum(x, n));
}


x86 assembly (clang, -O0):
<printvec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x6,-0xc(%rbp)
jg     1152 <printvec+0x32>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    115f <printvec+0x3f>
mov    $0x6,%eax
mov    %eax,-0x18(%rbp)
jmp    115f <printvec+0x3f>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a1 <printvec+0x81>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe76(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116c <printvec+0x4c>
cmpl   $0x6,-0xc(%rbp)
jle    121f <printvec+0xff>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0xc,-0xc(%rbp)
jg     11d0 <printvec+0xb0>
mov    $0x6,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d9 <printvec+0xb9>
mov    -0xc(%rbp),%eax
sub    $0x6,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    121a <printvec+0xfa>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xdfd(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11e5 <printvec+0xc5>
jmp    121f <printvec+0xff>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <vecsum@plt>
lea    0xdd5(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printvec>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r12
mov    $0x28,%edi
call   1030 <putchar@plt>
test   %r14d,%r14d
jle    11d9 <printvec+0xa9>
cmp    $0x6,%r14d
mov    $0x6,%r13d
cmovb  %r14d,%r13d
xor    %ebx,%ebx
lea    0xe97(%rip),%r15
nopl   0x0(%rax)
movsd  (%r12,%rbx,8),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1170 <printvec+0x40>
cmp    $0x7,%r14d
jl     11d9 <printvec+0xa9>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    -0x6(%r14),%ecx
cmp    $0xd,%r14d
mov    $0x6,%eax
cmovae %ecx,%eax
cmp    %r14d,%eax
jae    11d9 <printvec+0xa9>
mov    %eax,%ebx
mov    %r14d,%r13d
lea    0xe46(%rip),%r15
nopw   0x0(%rax,%rax,1)
movsd  (%r12,%rbx,8),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %ebx,%r13d
jne    11c0 <printvec+0x90>
mov    %r12,%rdi
mov    %r14d,%esi
call   1050 <vecsum@plt>
lea    0xe1a(%rip),%rdi
mov    $0x1,%al
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <printf@plt>

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

LLVM IR (-O2):
@.str.1 = [5 x i8] c"%g, \00"
@.str.3 = [14 x i8] c"), sum is %g\0A\00"
define void @printvec(double* %0, i32 %1) {
%3 = tail call i32 @putchar(i32 40)
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %34
5: ; preds = %2
%6 = icmp ult i32 %1, 6
%7 = select i1 %6, i32 %1, i32 6
%8 = zext i32 %7 to i64
br label %9
9: ; preds = %5, %9
%10 = phi i64 [ 0, %5 ], [ %14, %9 ]
%11 = getelementptr inbounds double, double* %0, i64 %10
%12 = load double, double* %11
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %12)
%14 = add nuw nsw i64 %10, 1
%15 = icmp eq i64 %14, %8
br i1 %15, label %16, label %9
16: ; preds = %9
%17 = icmp sgt i32 %1, 6
br i1 %17, label %18, label %34
18: ; preds = %16
%19 = tail call i32 @putchar(i32 10)
%20 = icmp ult i32 %1, 13
%21 = add nsw i32 %1, -6
%22 = select i1 %20, i32 6, i32 %21
%23 = icmp ult i32 %22, %1
br i1 %23, label %24, label %34
24: ; preds = %18
%25 = zext i32 %22 to i64
br label %26
26: ; preds = %24, %26
%27 = phi i64 [ %25, %24 ], [ %31, %26 ]
%28 = getelementptr inbounds double, double* %0, i64 %27
%29 = load double, double* %28
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %29)
%31 = add nuw nsw i64 %27, 1
%32 = trunc i64 %31 to i32
%33 = icmp eq i32 %32, %1
br i1 %33, label %34, label %26
34: ; preds = %26, %2, %18, %16
%35 = tail call double @vecsum(double* %0, i32 %1)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), double %35)
ret void
}