double sum(double d, ...) {
  __builtin_va_list l;
  __builtin_va_start(l, d);
  double t = 0;
  while (d) {
    t += d;
    d = __builtin_va_arg(l, double);
  }
  __builtin_va_end(l);
  return t;
}


x86 assembly (clang, -O0):
<sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
test   %al,%al
je     1135 <sum+0x35>
movaps %xmm1,-0xa0(%rbp)
movaps %xmm2,-0x90(%rbp)
movaps %xmm3,-0x80(%rbp)
movaps %xmm4,-0x70(%rbp)
movaps %xmm5,-0x60(%rbp)
movaps %xmm6,-0x50(%rbp)
movaps %xmm7,-0x40(%rbp)
mov    %r9,-0xb8(%rbp)
mov    %r8,-0xc0(%rbp)
mov    %rcx,-0xc8(%rbp)
mov    %rdx,-0xd0(%rbp)
mov    %rsi,-0xd8(%rbp)
mov    %rdi,-0xe0(%rbp)
movsd  %xmm0,-0x8(%rbp)
lea    -0x20(%rbp),%rax
lea    -0xe0(%rbp),%rcx
mov    %rcx,0x10(%rax)
lea    0x10(%rbp),%rcx
mov    %rcx,0x8(%rax)
movl   $0x40,0x4(%rax)
movl   $0x0,(%rax)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ad <sum+0xad>
jp     11ad <sum+0xad>
jmp    1244 <sum+0x144>
movsd  -0x8(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0xf8(%rbp)
add    $0x4,%rax
mov    %rax,-0xf0(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0xe4(%rbp)
cmp    $0xa0,%eax
ja     1212 <sum+0x112>
mov    -0xf0(%rbp),%rcx
mov    -0xe4(%rbp),%edx
mov    -0xf8(%rbp),%rsi
movslq %edx,%rax
add    0x10(%rsi),%rax
add    $0x10,%edx
mov    %edx,(%rcx)
mov    %rax,-0x100(%rbp)
jmp    122f <sum+0x12f>
mov    -0xf8(%rbp),%rcx
mov    0x8(%rcx),%rdx
mov    %rdx,%rax
add    $0x8,%rdx
mov    %rdx,0x8(%rcx)
mov    %rax,-0x100(%rbp)
mov    -0x100(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1190 <sum+0x90>
movsd  -0x28(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sum>:
sub    $0x58,%rsp
mov    %rdi,-0x60(%rsp)
mov    %rsi,-0x58(%rsp)
mov    %rdx,-0x50(%rsp)
mov    %rcx,-0x48(%rsp)
mov    %r8,-0x40(%rsp)
mov    %r9,-0x38(%rsp)
test   %al,%al
je     114a <sum+0x4a>
movapd %xmm1,-0x20(%rsp)
movapd %xmm2,-0x10(%rsp)
movaps %xmm3,(%rsp)
movaps %xmm4,0x10(%rsp)
movaps %xmm5,0x20(%rsp)
movaps %xmm6,0x30(%rsp)
movaps %xmm7,0x40(%rsp)
lea    -0x60(%rsp),%rax
mov    %rax,-0x70(%rsp)
lea    0x60(%rsp),%rax
mov    %rax,-0x78(%rsp)
movabs $0x4000000000,%rax
mov    %rax,-0x80(%rsp)
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1179 <sum+0x79>
jnp    11c4 <sum+0xc4>
mov    -0x70(%rsp),%rax
xorpd  %xmm2,%xmm2
mov    -0x7c(%rsp),%ecx
xorpd  %xmm1,%xmm1
jmp    11ae <sum+0xae>
nopl   0x0(%rax)
mov    -0x78(%rsp),%rdx
lea    0x8(%rdx),%rsi
mov    %rsi,-0x78(%rsp)
addsd  %xmm0,%xmm1
movsd  (%rdx),%xmm0
ucomisd %xmm2,%xmm0
jne    11ae <sum+0xae>
jnp    11c4 <sum+0xc4>
cmp    $0xa0,%ecx
ja     1190 <sum+0x90>
mov    %ecx,%edx
add    %rax,%rdx
add    $0x10,%ecx
mov    %ecx,-0x7c(%rsp)
jmp    119e <sum+0x9e>
movapd %xmm1,%xmm0
add    $0x58,%rsp
ret

LLVM IR (-O0):
%struct.__va_list_tag = type { i32, i32, i8*, i8* }
define double @sum(double %0, ...) {
%2 = alloca double
%3 = alloca [1 x %struct.__va_list_tag]
%4 = alloca double
store double %0, double* %2
%5 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %3, i64 0, i64 0
%6 = bitcast %struct.__va_list_tag* %5 to i8*
store double 0.000000e+00, double* %4
br label %7
7: ; preds = %29, %1
%8 = load double, double* %2
%9 = fcmp une double %8, 0.000000e+00
br i1 %9, label %10, label %32
10: ; preds = %7
%11 = load double, double* %2
%12 = load double, double* %4
%13 = fadd double %12, %11
store double %13, double* %4
%14 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %3, i64 0, i64 0
%15 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %14, i32 0, i32 1
%16 = load i32, i32* %15
%17 = icmp ule i32 %16, 160
br i1 %17, label %18, label %24
18: ; preds = %10
%19 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %14, i32 0, i32 3
%20 = load i8*, i8** %19
%21 = getelementptr i8, i8* %20, i32 %16
%22 = bitcast i8* %21 to double*
%23 = add i32 %16, 16
store i32 %23, i32* %15
br label %29
24: ; preds = %10
%25 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %14, i32 0, i32 2
%26 = load i8*, i8** %25
%27 = bitcast i8* %26 to double*
%28 = getelementptr i8, i8* %26, i32 8
store i8* %28, i8** %25
br label %29
29: ; preds = %24, %18
%30 = phi double* [ %22, %18 ], [ %27, %24 ]
%31 = load double, double* %30
store double %31, double* %2
br label %7
32: ; preds = %7
%33 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %3, i64 0, i64 0
%34 = bitcast %struct.__va_list_tag* %33 to i8*
%35 = load double, double* %4
ret double %35
}

LLVM IR (-O2):
%struct.__va_list_tag = type { i32, i32, i8*, i8* }
define double @sum(double %0, ...) {
%2 = alloca [1 x %struct.__va_list_tag]
%3 = bitcast [1 x %struct.__va_list_tag]* %2 to i8*
%4 = fcmp une double %0, 0.000000e+00
br i1 %4, label %5, label %30
5: ; preds = %1
%6 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %2, i64 0, i64 0, i32 1
%7 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %2, i64 0, i64 0, i32 2
%8 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %2, i64 0, i64 0, i32 3
%9 = load i8*, i8** %8
%10 = load i32, i32* %6
br label %11
11: ; preds = %5, %24
%12 = phi i32 [ %10, %5 ], [ %25, %24 ]
%13 = phi double [ 0.000000e+00, %5 ], [ %15, %24 ]
%14 = phi double [ %0, %5 ], [ %28, %24 ]
%15 = fadd double %14, %13
%16 = icmp ult i32 %12, 161
br i1 %16, label %17, label %21
17: ; preds = %11
%18 = zext i32 %12 to i64
%19 = getelementptr i8, i8* %9, i64 %18
%20 = add nuw nsw i32 %12, 16
store i32 %20, i32* %6
br label %24
21: ; preds = %11
%22 = load i8*, i8** %7
%23 = getelementptr i8, i8* %22, i64 8
store i8* %23, i8** %7
br label %24
24: ; preds = %21, %17
%25 = phi i32 [ %20, %17 ], [ %12, %21 ]
%26 = phi i8* [ %19, %17 ], [ %22, %21 ]
%27 = bitcast i8* %26 to double*
%28 = load double, double* %27
%29 = fcmp une double %28, 0.000000e+00
br i1 %29, label %11, label %30
30: ; preds = %24, %1
%31 = phi double [ 0.000000e+00, %1 ], [ %15, %24 ]
ret double %31
}