void test(__int128 n) {
  __int128 mult = mpm(n);
  if (mult > 0) {
    print128(n);
    printf(" * ");
    print128(mult);
    printf(" = ");
    print128(n * mult);
    printf("\n");
  } else {
    print128(n);
    printf("(no solution)\n");
  }
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
xor    %eax,%eax
call   1050 <mpm@plt>
movslq %eax,%rcx
mov    %rcx,%rax
sar    $0x3f,%rax
mov    %rcx,-0x30(%rbp)
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
sub    $0x1,%rcx
sbb    $0x0,%rax
jl     126d <test+0x13d>
jmp    119f <test+0x6f>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
xor    %eax,%eax
mov    %al,-0x89(%rbp)
call   1030 <print128@plt>
mov    -0x89(%rbp),%al
lea    0xe2f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x89(%rbp),%al
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rdx
mov    %rdx,-0x58(%rbp)
mov    %rcx,-0x60(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
call   1030 <print128@plt>
mov    -0x89(%rbp),%al
lea    0xdfe(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,-0x88(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rcx
mov    %rax,%rdi
imul   %rcx,%rdi
mul    %rsi
mov    %rax,%rcx
mov    %rdx,%rax
mov    -0x88(%rbp),%rdx
add    %rdi,%rax
imul   %rsi,%rdx
add    %rdx,%rax
mov    %rcx,-0x70(%rbp)
mov    %rax,-0x68(%rbp)
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    $0x0,%al
call   1030 <print128@plt>
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    129a <test+0x16a>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,-0x78(%rbp)
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rdi
mov    -0x78(%rbp),%rsi
mov    $0x0,%al
call   1030 <print128@plt>
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1070 <mpm@plt>
test   %eax,%eax
jle    11c6 <test+0x76>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <print128@plt>
lea    0xe85(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%ebp
mov    %rbp,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <print128@plt>
lea    0xe6d(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
imul   %rbp,%rbx
mov    %r14,%rax
mul    %rbp
add    %rdx,%rbx
mov    %rax,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <print128@plt>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <print128@plt>
lea    0xe2e(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <puts@plt>

LLVM IR (-O0):
@.str = [4 x i8] c" * \00"
@.str.1 = [4 x i8] c" = \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [15 x i8] c"(no solution)\0A\00"
define void @test(i64 %0, i64 %1) {
%3 = alloca i128
%4 = alloca i128
%5 = alloca i128
%6 = alloca i128
%7 = alloca i128
%8 = alloca i128
%9 = alloca i128
%10 = alloca i128
%11 = bitcast i128* %3 to { i64, i64 }*
%12 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %11, i32 0, i32 0
store i64 %0, i64* %12
%13 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %11, i32 0, i32 1
store i64 %1, i64* %13
%14 = load i128, i128* %3
store i128 %14, i128* %4
%15 = load i128, i128* %4
store i128 %15, i128* %6
%16 = bitcast i128* %6 to { i64, i64 }*
%17 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %16, i32 0, i32 0
%18 = load i64, i64* %17
%19 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %16, i32 0, i32 1
%20 = load i64, i64* %19
%21 = call i32 (i64, i64, ...) bitcast (i32 (...)* @mpm to i32 (i64, i64, ...)*)(i64 %18, i64 %20)
%22 = sext i32 %21 to i128
store i128 %22, i128* %5
%23 = load i128, i128* %5
%24 = icmp sgt i128 %23, 0
br i1 %24, label %25, label %52
25: ; preds = %2
%26 = load i128, i128* %4
store i128 %26, i128* %7
%27 = bitcast i128* %7 to { i64, i64 }*
%28 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %27, i32 0, i32 0
%29 = load i64, i64* %28
%30 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %27, i32 0, i32 1
%31 = load i64, i64* %30
%32 = call i32 (i64, i64, ...) bitcast (i32 (...)* @print128 to i32 (i64, i64, ...)*)(i64 %29, i64 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%34 = load i128, i128* %5
store i128 %34, i128* %8
%35 = bitcast i128* %8 to { i64, i64 }*
%36 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %35, i32 0, i32 0
%37 = load i64, i64* %36
%38 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %35, i32 0, i32 1
%39 = load i64, i64* %38
%40 = call i32 (i64, i64, ...) bitcast (i32 (...)* @print128 to i32 (i64, i64, ...)*)(i64 %37, i64 %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%42 = load i128, i128* %4
%43 = load i128, i128* %5
%44 = mul nsw i128 %42, %43
store i128 %44, i128* %9
%45 = bitcast i128* %9 to { i64, i64 }*
%46 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %45, i32 0, i32 0
%47 = load i64, i64* %46
%48 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %45, i32 0, i32 1
%49 = load i64, i64* %48
%50 = call i32 (i64, i64, ...) bitcast (i32 (...)* @print128 to i32 (i64, i64, ...)*)(i64 %47, i64 %49)
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %61
52: ; preds = %2
%53 = load i128, i128* %4
store i128 %53, i128* %10
%54 = bitcast i128* %10 to { i64, i64 }*
%55 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %54, i32 0, i32 0
%56 = load i64, i64* %55
%57 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %54, i32 0, i32 1
%58 = load i64, i64* %57
%59 = call i32 (i64, i64, ...) bitcast (i32 (...)* @print128 to i32 (i64, i64, ...)*)(i64 %56, i64 %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %61
61: ; preds = %52, %25
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c" * \00"
@.str.1 = [4 x i8] c" = \00"
@str = [14 x i8] c"(no solution)\00"
define void @test(i64 %0, i64 %1) {
%3 = tail call i32 (i64, i64, ...) bitcast (i32 (...)* @mpm to i32 (i64, i64, ...)*)(i64 %0, i64 %1)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %22
5: ; preds = %2
%6 = zext i32 %3 to i128
%7 = zext i64 %1 to i128
%8 = shl nuw i128 %7, 64
%9 = zext i64 %0 to i128
%10 = or i128 %8, %9
%11 = tail call i32 (i64, i64, ...) bitcast (i32 (...)* @print128 to i32 (i64, i64, ...)*)(i64 %0, i64 %1)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%13 = zext i32 %3 to i64
%14 = tail call i32 (i64, i64, ...) bitcast (i32 (...)* @print128 to i32 (i64, i64, ...)*)(i64 %13, i64 0)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%16 = mul nsw i128 %10, %6
%17 = trunc i128 %16 to i64
%18 = lshr i128 %16, 64
%19 = trunc i128 %18 to i64
%20 = tail call i32 (i64, i64, ...) bitcast (i32 (...)* @print128 to i32 (i64, i64, ...)*)(i64 %17, i64 %19)
%21 = tail call i32 @putchar(i32 10)
br label %25
22: ; preds = %2
%23 = tail call i32 (i64, i64, ...) bitcast (i32 (...)* @print128 to i32 (i64, i64, ...)*)(i64 %0, i64 %1)
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %25
25: ; preds = %22, %5
ret void
}