f(int a, ...) {
  __builtin_va_list l;
  int ret = a;
  __builtin_va_start(l, a);
  for (;;) {
    int i = __builtin_va_arg(l, int);
    if (i == 0)
      break;
    ret += i;
  }
  __builtin_va_end(l);
  return ret;
}


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)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%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)
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,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    1206 <f+0x106>
jmp    1214 <f+0x114>
mov    -0x28(%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    %eax,%r10d
mov    %edi,%eax
mov    %rsi,-0x58(%rsp)
mov    %rdx,-0x50(%rsp)
mov    %rcx,-0x48(%rsp)
mov    %r8,-0x40(%rsp)
mov    %r9,-0x38(%rsp)
test   %r10b,%r10b
je     114e <f+0x4e>
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),%rdx
mov    %rdx,-0x78(%rsp)
movabs $0x3000000008,%rdx
mov    %rdx,-0x80(%rsp)
mov    $0x8,%edx
jmp    1196 <f+0x96>
nopl   0x0(%rax,%rax,1)
mov    -0x78(%rsp),%rsi
lea    0x8(%rsi),%rdi
mov    %rdi,-0x78(%rsp)
mov    (%rsi),%esi
add    %esi,%eax
test   %esi,%esi
je     11a9 <f+0xa9>
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
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
store i32 %6, i32* %4
%7 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %3, i64 0, i64 0
%8 = bitcast %struct.__va_list_tag* %7 to i8*
br label %9
9: ; preds = %31, %1
%10 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %3, i64 0, i64 0
%11 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = icmp ule i32 %12, 40
br i1 %13, label %14, label %20
14: ; preds = %9
%15 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %10, i32 0, i32 3
%16 = load i8*, i8** %15
%17 = getelementptr i8, i8* %16, i32 %12
%18 = bitcast i8* %17 to i32*
%19 = add i32 %12, 8
store i32 %19, i32* %11
br label %25
20: ; preds = %9
%21 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %10, i32 0, i32 2
%22 = load i8*, i8** %21
%23 = bitcast i8* %22 to i32*
%24 = getelementptr i8, i8* %22, i32 8
store i8* %24, i8** %21
br label %25
25: ; preds = %20, %14
%26 = phi i32* [ %18, %14 ], [ %23, %20 ]
%27 = load i32, i32* %26
store i32 %27, i32* %5
%28 = load i32, i32* %5
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %25
br label %35
31: ; preds = %25
%32 = load i32, i32* %5
%33 = load i32, i32* %4
%34 = add nsw i32 %33, %32
store i32 %34, i32* %4
br label %9
35: ; preds = %30
%36 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %3, i64 0, i64 0
%37 = bitcast %struct.__va_list_tag* %36 to i8*
%38 = load i32, i32* %4
ret i32 %38
}

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, 0
%26 = add nsw i32 %24, %11
br i1 %25, label %27, label %9
27: ; preds = %20
ret i32 %26
}