f(int i, ...) {
  __builtin_va_list l;
  __builtin_va_start(l, i);
  int t = i;
  for (;;) {
    i = __builtin_va_arg(l, int);
    if (i == -1)
      break;
    t += i;
  }
  return t;
}


x86 assembly (clang, -O0):
<f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
test   %al,%al
je     113c <f+0x3c>
movaps %xmm0,-0xb0(%rbp)
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    %edi,-0x4(%rbp)
lea    -0x20(%rbp),%rax
lea    -0xe0(%rbp),%rcx
mov    %rcx,0x10(%rax)
lea    0x10(%rbp),%rcx
mov    %rcx,0x8(%rax)
movl   $0x30,0x4(%rax)
movl   $0x8,(%rax)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0xf0(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0xe4(%rbp)
cmp    $0x28,%eax
ja     11ce <f+0xce>
mov    -0xf0(%rbp),%rcx
mov    -0xe4(%rbp),%edx
movslq %edx,%rax
add    0x10(%rcx),%rax
add    $0x8,%edx
mov    %edx,(%rcx)
mov    %rax,-0xf8(%rbp)
jmp    11eb <f+0xeb>
mov    -0xf0(%rbp),%rcx
mov    0x8(%rcx),%rdx
mov    %rdx,%rax
add    $0x8,%rdx
mov    %rdx,0x8(%rcx)
mov    %rax,-0xf8(%rbp)
mov    -0xf8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    1206 <f+0x106>
jmp    1214 <f+0x114>
mov    -0x4(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    118c <f+0x8c>
mov    -0x24(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f>:
sub    $0x58,%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     1148 <f+0x48>
movaps %xmm0,-0x30(%rsp)
movaps %xmm1,-0x20(%rsp)
movaps %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),%rcx
mov    %rcx,-0x70(%rsp)
lea    0x60(%rsp),%rax
mov    %rax,-0x78(%rsp)
movabs $0x3000000008,%rax
mov    %rax,-0x80(%rsp)
mov    $0x8,%edx
jmp    1198 <f+0x98>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    -0x78(%rsp),%rsi
lea    0x8(%rsi),%rdi
mov    %rdi,-0x78(%rsp)
mov    (%rsi),%esi
lea    (%rsi,%rax,1),%edi
cmp    $0xffffffff,%esi
je     11ad <f+0xad>
mov    %edi,%eax
cmp    $0x28,%edx
ja     1180 <f+0x80>
mov    %edx,%esi
add    %rcx,%rsi
add    $0x8,%edx
mov    %edx,-0x80(%rsp)
jmp    118e <f+0x8e>
add    $0x58,%rsp
ret

LLVM IR (-O0):
%struct.__va_list_tag = type { i32, i32, i8*, i8* }
define i32 @f(i32 %0, ...) {
%2 = alloca i32
%3 = alloca [1 x %struct.__va_list_tag]
%4 = alloca i32
store i32 %0, i32* %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*
%7 = load i32, i32* %2
store i32 %7, i32* %4
br label %8
8: ; preds = %30, %1
%9 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %3, i64 0, i64 0
%10 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = icmp ule i32 %11, 40
br i1 %12, label %13, label %19
13: ; preds = %8
%14 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %9, i32 0, i32 3
%15 = load i8*, i8** %14
%16 = getelementptr i8, i8* %15, i32 %11
%17 = bitcast i8* %16 to i32*
%18 = add i32 %11, 8
store i32 %18, i32* %10
br label %24
19: ; preds = %8
%20 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %9, i32 0, i32 2
%21 = load i8*, i8** %20
%22 = bitcast i8* %21 to i32*
%23 = getelementptr i8, i8* %21, i32 8
store i8* %23, i8** %20
br label %24
24: ; preds = %19, %13
%25 = phi i32* [ %17, %13 ], [ %22, %19 ]
%26 = load i32, i32* %25
store i32 %26, i32* %2
%27 = load i32, i32* %2
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %30
29: ; preds = %24
br label %34
30: ; preds = %24
%31 = load i32, i32* %2
%32 = load i32, i32* %4
%33 = add nsw i32 %32, %31
store i32 %33, i32* %4
br label %8
34: ; preds = %29
%35 = load i32, i32* %4
ret i32 %35
}

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