unsigned long long carried_add_7(unsigned long long carry,
                                 unsigned long long *res,
                                 unsigned long long *a1,
                                 unsigned long long *a2) {
  asm("mov  %%rax,   %%r8;"
      "xor  %%rax,   %%rax;"
      "adc  (%%rcx), %%r8;"
      "setc %%al;"
      "mov  %%rax,    %%r9;"
      "adc  (%%rdx), %%r8;"
      "mov  %%r8,    (%%rbx);"
      "setc %%al;"
      "or   %%r9,    %%rax;"
      "sub  $0x0008,  %%rbx;"
      "sub  $0x0008,  %%rcx;"
      "sub  $0x0008,  %%rdx;"
      "mov  %%rax,   %%r8;"
      "xor  %%rax,   %%rax;"
      "adc  (%%rcx), %%r8;"
      "setc %%al;"
      "mov  %%rax,    %%r9;"
      "adc  (%%rdx), %%r8;"
      "mov  %%r8,    (%%rbx);"
      "setc %%al;"
      "or   %%r9,    %%rax;"
      : "=a"(carry)
      : "a"(carry), "b"(res), "c"(a1), "d"(a2));
  return carry;
}


x86 assembly (clang, -O0):
<carried_add_7>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rbx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%rdx
mov    %rax,%r8
xor    %rax,%rax
adc    (%rcx),%r8
setb   %al
mov    %rax,%r9
adc    (%rdx),%r8
mov    %r8,(%rbx)
setb   %al
or     %r9,%rax
sub    $0x8,%rbx
sub    $0x8,%rcx
sub    $0x8,%rdx
mov    %rax,%r8
xor    %rax,%rax
adc    (%rcx),%r8
setb   %al
mov    %rax,%r9
adc    (%rdx),%r8
mov    %r8,(%rbx)
setb   %al
or     %r9,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<carried_add_7>:
push   %rbx
mov    %rcx,%r8
mov    %rdx,%rcx
mov    %rsi,%rbx
mov    %rdi,%rax
mov    %r8,%rdx
mov    %rax,%r8
xor    %rax,%rax
adc    (%rcx),%r8
setb   %al
mov    %rax,%r9
adc    (%rdx),%r8
mov    %r8,(%rbx)
setb   %al
or     %r9,%rax
sub    $0x8,%rbx
sub    $0x8,%rcx
sub    $0x8,%rdx
mov    %rax,%r8
xor    %rax,%rax
adc    (%rcx),%r8
setb   %al
mov    %rax,%r9
adc    (%rdx),%r8
mov    %r8,(%rbx)
setb   %al
or     %r9,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i64 @carried_add_7(i64 %0, i64* %1, i64* %2, i64* %3) {
%5 = alloca i64
%6 = alloca i64*
%7 = alloca i64*
%8 = alloca i64*
store i64 %0, i64* %5
store i64* %1, i64** %6
store i64* %2, i64** %7
store i64* %3, i64** %8
%9 = load i64, i64* %5
%10 = load i64*, i64** %6
%11 = load i64*, i64** %7
%12 = load i64*, i64** %8
%13 = call i64 asm "mov %rax, %r8;xor %rax, %rax;adc (%rcx), %r8;setc %al;mov %rax, %r9;adc (%rdx), %r8;mov %r8, (%rbx);setc %al;or %r9, %rax;sub $$0x0008, %rbx;sub $$0x0008, %rcx;sub $$0x0008, %rdx;mov %rax, %r8;xor %rax, %rax;adc (%rcx), %r8;setc %al;mov %rax, %r9;adc (%rdx), %r8;mov %r8, (%rbx);setc %al;or %r9, %rax;", "={ax},{ax},{bx},{cx},{dx},~{dirflag},~{fpsr},~{flags}"(i64 %9, i64* %10, i64* %11, i64* %12)
store i64 %13, i64* %5
%14 = load i64, i64* %5
ret i64 %14
}

LLVM IR (-O2):
define i64 @carried_add_7(i64 %0, i64* readnone %1, i64* readnone %2, i64* readnone %3) {
%5 = tail call i64 asm "mov %rax, %r8;xor %rax, %rax;adc (%rcx), %r8;setc %al;mov %rax, %r9;adc (%rdx), %r8;mov %r8, (%rbx);setc %al;or %r9, %rax;sub $$0x0008, %rbx;sub $$0x0008, %rcx;sub $$0x0008, %rdx;mov %rax, %r8;xor %rax, %rax;adc (%rcx), %r8;setc %al;mov %rax, %r9;adc (%rdx), %r8;mov %r8, (%rbx);setc %al;or %r9, %rax;", "={ax},{ax},{bx},{cx},{dx},~{dirflag},~{fpsr},~{flags}"(i64 %0, i64* %1, i64* %2, i64* %3)
ret i64 %5
}