__float128 logadd_s(const __float128 a, const int sign_a, const __float128 b,
                    const int sign_b, int *sign) {
  if (isinfq(a) && a < 0) {
    *sign = sign_b;
    return b;
  } else if (isinfq(b) && b < 0) {
    *sign = sign_a;
    return a;
  }
  if (a > b) {
    *sign = sign_a;
    return a + log1pq(sign_a * sign_b * expq(b - a));
  } else {
    *sign = sign_b;
    return b + log1pq(sign_a * sign_b * expq(a - b));
  }
}


x86 assembly (clang, -O0):
<logadd_s>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movaps %xmm0,-0x20(%rbp)
mov    %edi,-0x24(%rbp)
movaps %xmm1,-0x40(%rbp)
mov    %esi,-0x44(%rbp)
mov    %rdx,-0x50(%rbp)
movaps -0x20(%rbp),%xmm0
mov    $0x1,%al
call   1040 <isinfq@plt>
cmp    $0x0,%eax
je     1190 <logadd_s+0x60>
movaps -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
call   3db0 <__letf2>
test   %eax,%eax
jns    1190 <logadd_s+0x60>
jmp    117a <logadd_s+0x4a>
mov    -0x44(%rbp),%ecx
mov    -0x50(%rbp),%rax
mov    %ecx,(%rax)
movaps -0x40(%rbp),%xmm0
movaps %xmm0,-0x10(%rbp)
jmp    129f <logadd_s+0x16f>
movaps -0x40(%rbp),%xmm0
mov    $0x1,%al
call   1040 <isinfq@plt>
cmp    $0x0,%eax
je     11d3 <logadd_s+0xa3>
movaps -0x40(%rbp),%xmm0
xorps  %xmm1,%xmm1
call   3db0 <__letf2>
test   %eax,%eax
jns    11d3 <logadd_s+0xa3>
jmp    11bd <logadd_s+0x8d>
mov    -0x24(%rbp),%ecx
mov    -0x50(%rbp),%rax
mov    %ecx,(%rax)
movaps -0x20(%rbp),%xmm0
movaps %xmm0,-0x10(%rbp)
jmp    129f <logadd_s+0x16f>
jmp    11d8 <logadd_s+0xa8>
movaps -0x20(%rbp),%xmm0
movaps -0x40(%rbp),%xmm1
call   3a70 <__getf2>
test   %eax,%eax
jle    1248 <logadd_s+0x118>
jmp    11f2 <logadd_s+0xc2>
mov    -0x24(%rbp),%ecx
mov    -0x50(%rbp),%rax
mov    %ecx,(%rax)
movaps -0x20(%rbp),%xmm1
movaps %xmm1,-0x60(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x44(%rbp),%ecx
imul   %ecx,%eax
mov    %eax,-0x64(%rbp)
movaps -0x40(%rbp),%xmm0
call   2690 <__subtf3>
mov    $0x1,%al
call   1050 <expq@plt>
mov    -0x64(%rbp),%edi
imul   %eax,%edi
xor    %eax,%eax
call   1030 <log1pq@plt>
mov    %eax,%edi
call   39d0 <__floatsitf>
movaps %xmm0,%xmm1
movaps -0x60(%rbp),%xmm0
call   12b0 <__addtf3>
movaps %xmm0,-0x10(%rbp)
jmp    129f <logadd_s+0x16f>
mov    -0x44(%rbp),%ecx
mov    -0x50(%rbp),%rax
mov    %ecx,(%rax)
movaps -0x40(%rbp),%xmm1
movaps %xmm1,-0x80(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x44(%rbp),%ecx
imul   %ecx,%eax
mov    %eax,-0x84(%rbp)
movaps -0x20(%rbp),%xmm0
call   2690 <__subtf3>
mov    $0x1,%al
call   1050 <expq@plt>
mov    -0x84(%rbp),%edi
imul   %eax,%edi
xor    %eax,%eax
call   1030 <log1pq@plt>
mov    %eax,%edi
call   39d0 <__floatsitf>
movaps %xmm0,%xmm1
movaps -0x80(%rbp),%xmm0
call   12b0 <__addtf3>
movaps %xmm0,-0x10(%rbp)
movaps -0x10(%rbp),%xmm0
add    $0x90,%rsp
pop    %rbp
ret
nopl   0x0(%rax)

x86 assembly (clang, -O2):
<logadd_s>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%rbp
mov    %esi,%r15d
movaps %xmm1,(%rsp)
mov    %edi,%r14d
movaps %xmm0,0x10(%rsp)
mov    $0x1,%al
call   1040 <isinfq@plt>
mov    %eax,%ebx
xorps  %xmm1,%xmm1
movaps 0x10(%rsp),%xmm0
call   3d40 <__letf2>
test   %eax,%eax
jns    1177 <logadd_s+0x47>
test   %ebx,%ebx
je     1177 <logadd_s+0x47>
mov    %r15d,0x0(%rbp)
movaps (%rsp),%xmm0
jmp    122c <logadd_s+0xfc>
movaps (%rsp),%xmm0
mov    $0x1,%al
call   1040 <isinfq@plt>
mov    %eax,%ebx
xorps  %xmm1,%xmm1
movaps (%rsp),%xmm0
call   3d40 <__letf2>
test   %eax,%eax
jns    11a6 <logadd_s+0x76>
test   %ebx,%ebx
je     11a6 <logadd_s+0x76>
mov    %r14d,0x0(%rbp)
movaps 0x10(%rsp),%xmm0
jmp    122c <logadd_s+0xfc>
movaps 0x10(%rsp),%xmm0
movaps (%rsp),%xmm1
call   3a00 <__getf2>
test   %eax,%eax
jle    11f1 <logadd_s+0xc1>
mov    %r14d,0x0(%rbp)
imul   %r14d,%r15d
movaps (%rsp),%xmm0
movaps 0x10(%rsp),%xmm1
call   2620 <__subtf3>
mov    $0x1,%al
call   1050 <expq@plt>
imul   %eax,%r15d
mov    %r15d,%edi
xor    %eax,%eax
call   1030 <log1pq@plt>
mov    %eax,%edi
call   3960 <__floatsitf>
movaps 0x10(%rsp),%xmm1
jmp    1227 <logadd_s+0xf7>
mov    %r15d,0x0(%rbp)
imul   %r15d,%r14d
movaps 0x10(%rsp),%xmm0
movaps (%rsp),%xmm1
call   2620 <__subtf3>
mov    $0x1,%al
call   1050 <expq@plt>
imul   %eax,%r14d
mov    %r14d,%edi
xor    %eax,%eax
call   1030 <log1pq@plt>
mov    %eax,%edi
call   3960 <__floatsitf>
movaps (%rsp),%xmm1
call   1240 <__addtf3>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
nopw   0x0(%rax,%rax,1)

LLVM IR (-O0):
define fp128 @logadd_s(fp128 %0, i32 %1, fp128 %2, i32 %3, i32* %4) {
%6 = alloca fp128
%7 = alloca fp128
%8 = alloca i32
%9 = alloca fp128
%10 = alloca i32
%11 = alloca i32*
store fp128 %0, fp128* %7
store i32 %1, i32* %8
store fp128 %2, fp128* %9
store i32 %3, i32* %10
store i32* %4, i32** %11
%12 = load fp128, fp128* %7
%13 = call i32 (fp128, ...) bitcast (i32 (...)* @isinfq to i32 (fp128, ...)*)(fp128 %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %5
%16 = load fp128, fp128* %7
%17 = fcmp olt fp128 %16, 0xL00000000000000000000000000000000
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i32, i32* %10
%20 = load i32*, i32** %11
store i32 %19, i32* %20
%21 = load fp128, fp128* %9
store fp128 %21, fp128* %6
br label %68
22: ; preds = %15, %5
%23 = load fp128, fp128* %9
%24 = call i32 (fp128, ...) bitcast (i32 (...)* @isinfq to i32 (fp128, ...)*)(fp128 %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %22
%27 = load fp128, fp128* %9
%28 = fcmp olt fp128 %27, 0xL00000000000000000000000000000000
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = load i32, i32* %8
%31 = load i32*, i32** %11
store i32 %30, i32* %31
%32 = load fp128, fp128* %7
store fp128 %32, fp128* %6
br label %68
33: ; preds = %26, %22
br label %34
34: ; preds = %33
%35 = load fp128, fp128* %7
%36 = load fp128, fp128* %9
%37 = fcmp ogt fp128 %35, %36
br i1 %37, label %38, label %53
38: ; preds = %34
%39 = load i32, i32* %8
%40 = load i32*, i32** %11
store i32 %39, i32* %40
%41 = load fp128, fp128* %7
%42 = load i32, i32* %8
%43 = load i32, i32* %10
%44 = mul nsw i32 %42, %43
%45 = load fp128, fp128* %9
%46 = load fp128, fp128* %7
%47 = fsub fp128 %45, %46
%48 = call i32 (fp128, ...) bitcast (i32 (...)* @expq to i32 (fp128, ...)*)(fp128 %47)
%49 = mul nsw i32 %44, %48
%50 = call i32 (i32, ...) bitcast (i32 (...)* @log1pq to i32 (i32, ...)*)(i32 %49)
%51 = sitofp i32 %50 to fp128
%52 = fadd fp128 %41, %51
store fp128 %52, fp128* %6
br label %68
53: ; preds = %34
%54 = load i32, i32* %10
%55 = load i32*, i32** %11
store i32 %54, i32* %55
%56 = load fp128, fp128* %9
%57 = load i32, i32* %8
%58 = load i32, i32* %10
%59 = mul nsw i32 %57, %58
%60 = load fp128, fp128* %7
%61 = load fp128, fp128* %9
%62 = fsub fp128 %60, %61
%63 = call i32 (fp128, ...) bitcast (i32 (...)* @expq to i32 (fp128, ...)*)(fp128 %62)
%64 = mul nsw i32 %59, %63
%65 = call i32 (i32, ...) bitcast (i32 (...)* @log1pq to i32 (i32, ...)*)(i32 %64)
%66 = sitofp i32 %65 to fp128
%67 = fadd fp128 %56, %66
store fp128 %67, fp128* %6
br label %68
68: ; preds = %53, %38, %29, %18
%69 = load fp128, fp128* %6
ret fp128 %69
}

LLVM IR (-O2):
define fp128 @logadd_s(fp128 %0, i32 %1, fp128 %2, i32 %3, i32* nocapture writeonly %4) {
%6 = tail call i32 (fp128, ...) bitcast (i32 (...)* @isinfq to i32 (fp128, ...)*)(fp128 %0)
%7 = icmp ne i32 %6, 0
%8 = fcmp olt fp128 %0, 0xL00000000000000000000000000000000
%9 = and i1 %8, %7
br i1 %9, label %10, label %11
10: ; preds = %5
store i32 %3, i32* %4
br label %35
11: ; preds = %5
%12 = tail call i32 (fp128, ...) bitcast (i32 (...)* @isinfq to i32 (fp128, ...)*)(fp128 %2)
%13 = icmp ne i32 %12, 0
%14 = fcmp olt fp128 %2, 0xL00000000000000000000000000000000
%15 = and i1 %14, %13
br i1 %15, label %16, label %17
16: ; preds = %11
store i32 %1, i32* %4
br label %35
17: ; preds = %11
%18 = fcmp ogt fp128 %0, %2
br i1 %18, label %19, label %27
19: ; preds = %17
store i32 %1, i32* %4
%20 = mul nsw i32 %3, %1
%21 = fsub fp128 %2, %0
%22 = tail call i32 (fp128, ...) bitcast (i32 (...)* @expq to i32 (fp128, ...)*)(fp128 %21)
%23 = mul nsw i32 %20, %22
%24 = tail call i32 (i32, ...) bitcast (i32 (...)* @log1pq to i32 (i32, ...)*)(i32 %23)
%25 = sitofp i32 %24 to fp128
%26 = fadd fp128 %25, %0
br label %35
27: ; preds = %17
store i32 %3, i32* %4
%28 = mul nsw i32 %3, %1
%29 = fsub fp128 %0, %2
%30 = tail call i32 (fp128, ...) bitcast (i32 (...)* @expq to i32 (fp128, ...)*)(fp128 %29)
%31 = mul nsw i32 %28, %30
%32 = tail call i32 (i32, ...) bitcast (i32 (...)* @log1pq to i32 (i32, ...)*)(i32 %31)
%33 = sitofp i32 %32 to fp128
%34 = fadd fp128 %33, %2
br label %35
35: ; preds = %27, %19, %16, %10
%36 = phi fp128 [ %2, %10 ], [ %0, %16 ], [ %26, %19 ], [ %34, %27 ]
ret fp128 %36
}