#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ ularith_add_2ul_2ul(unsigned long *, unsigned long *,
                                       unsigned long, unsigned long);
void ularith_mul_ul_ul_2ul(unsigned long *r1, unsigned long *r2,
                           const unsigned long a, const unsigned long b) {
  const int half = 64 / 2;
  const unsigned long mask = (1UL << half) - 1UL;
  unsigned long t1, t2, p1, p2;
  t1 = (a & mask) * (b & mask);
  t2 = 0UL;
  p1 = (a >> half) * (b & mask);
  p2 = p1 >> half;
  p1 = (p1 & mask) << half;
  ularith_add_2ul_2ul(&t1, &t2, p1, p2);
  p1 = (a & mask) * (b >> half);
  p2 = p1 >> half;
  p1 = (p1 & mask) << half;
  ularith_add_2ul_2ul(&t1, &t2, p1, p2);
  t2 += (a >> half) * (b >> half);
  *r1 = t1;
  *r2 = t2;
}


x86 assembly (clang, -O0):
<ularith_mul_ul_ul_2ul>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x20,-0x24(%rbp)
mov    $0xffffffff,%eax
mov    %rax,-0x30(%rbp)
movabs $0xffffffff,%rax
and    -0x18(%rbp),%rax
movabs $0xffffffff,%rcx
and    -0x20(%rbp),%rcx
imul   %rcx,%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x18(%rbp),%rax
shr    $0x20,%rax
movabs $0xffffffff,%rcx
and    -0x20(%rbp),%rcx
imul   %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
shr    $0x20,%rax
mov    %rax,-0x50(%rbp)
movabs $0xffffffff,%rax
and    -0x48(%rbp),%rax
shl    $0x20,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdx
mov    -0x50(%rbp),%rcx
lea    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1030 <ularith_add_2ul_2ul@plt>
movabs $0xffffffff,%rax
and    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
shr    $0x20,%rcx
imul   %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
shr    $0x20,%rax
mov    %rax,-0x50(%rbp)
movabs $0xffffffff,%rax
and    -0x48(%rbp),%rax
shl    $0x20,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdx
mov    -0x50(%rbp),%rcx
lea    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1030 <ularith_add_2ul_2ul@plt>
mov    -0x18(%rbp),%rax
shr    $0x20,%rax
mov    -0x20(%rbp),%rcx
shr    $0x20,%rcx
imul   %rcx,%rax
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ularith_mul_ul_ul_2ul>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %rdx,%r12
mov    %rsi,0x10(%rsp)
mov    %rdi,%r15
mov    %r12d,%r13d
mov    %ebx,%edx
mov    %rdx,%rax
imul   %r13,%rax
mov    %rax,0x8(%rsp)
movq   $0x0,(%rsp)
shr    $0x20,%r12
imul   %r12,%rdx
mov    %rdx,%rcx
shr    $0x20,%rcx
shl    $0x20,%rdx
lea    0x8(%rsp),%rbp
mov    %rsp,%r14
mov    %rbp,%rdi
mov    %r14,%rsi
call   1030 <ularith_add_2ul_2ul@plt>
shr    $0x20,%rbx
imul   %rbx,%r13
mov    %r13,%rcx
shr    $0x20,%rcx
shl    $0x20,%r13
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   1030 <ularith_add_2ul_2ul@plt>
imul   %r12,%rbx
add    (%rsp),%rbx
mov    0x8(%rsp),%rax
mov    %rax,(%r15)
mov    0x10(%rsp),%rax
mov    %rbx,(%rax)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @ularith_mul_ul_ul_2ul(i64* %0, i64* %1, i64 %2, i64 %3) {
%5 = alloca i64*
%6 = alloca i64*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
store i64* %0, i64** %5
store i64* %1, i64** %6
store i64 %2, i64* %7
store i64 %3, i64* %8
store i32 32, i32* %9
store i64 4294967295, i64* %10
%15 = load i64, i64* %7
%16 = and i64 %15, 4294967295
%17 = load i64, i64* %8
%18 = and i64 %17, 4294967295
%19 = mul i64 %16, %18
store i64 %19, i64* %11
store i64 0, i64* %12
%20 = load i64, i64* %7
%21 = lshr i64 %20, 32
%22 = load i64, i64* %8
%23 = and i64 %22, 4294967295
%24 = mul i64 %21, %23
store i64 %24, i64* %13
%25 = load i64, i64* %13
%26 = lshr i64 %25, 32
store i64 %26, i64* %14
%27 = load i64, i64* %13
%28 = and i64 %27, 4294967295
%29 = shl i64 %28, 32
store i64 %29, i64* %13
%30 = load i64, i64* %13
%31 = load i64, i64* %14
%32 = call i32 @ularith_add_2ul_2ul(i64* %11, i64* %12, i64 %30, i64 %31)
%33 = load i64, i64* %7
%34 = and i64 %33, 4294967295
%35 = load i64, i64* %8
%36 = lshr i64 %35, 32
%37 = mul i64 %34, %36
store i64 %37, i64* %13
%38 = load i64, i64* %13
%39 = lshr i64 %38, 32
store i64 %39, i64* %14
%40 = load i64, i64* %13
%41 = and i64 %40, 4294967295
%42 = shl i64 %41, 32
store i64 %42, i64* %13
%43 = load i64, i64* %13
%44 = load i64, i64* %14
%45 = call i32 @ularith_add_2ul_2ul(i64* %11, i64* %12, i64 %43, i64 %44)
%46 = load i64, i64* %7
%47 = lshr i64 %46, 32
%48 = load i64, i64* %8
%49 = lshr i64 %48, 32
%50 = mul i64 %47, %49
%51 = load i64, i64* %12
%52 = add i64 %51, %50
store i64 %52, i64* %12
%53 = load i64, i64* %11
%54 = load i64*, i64** %5
store i64 %53, i64* %54
%55 = load i64, i64* %12
%56 = load i64*, i64** %6
store i64 %55, i64* %56
ret void
}

LLVM IR (-O2):
define void @ularith_mul_ul_ul_2ul(i64* nocapture writeonly %0, i64* nocapture writeonly %1, i64 %2, i64 %3) {
%5 = alloca i64
%6 = alloca i64
%7 = bitcast i64* %5 to i8*
%8 = bitcast i64* %6 to i8*
%9 = and i64 %2, 4294967295
%10 = and i64 %3, 4294967295
%11 = mul nuw i64 %10, %9
store i64 %11, i64* %5
store i64 0, i64* %6
%12 = lshr i64 %2, 32
%13 = mul nuw i64 %10, %12
%14 = lshr i64 %13, 32
%15 = shl i64 %13, 32
%16 = call i32 @ularith_add_2ul_2ul(i64* %5, i64* %6, i64 %15, i64 %14)
%17 = lshr i64 %3, 32
%18 = mul nuw i64 %17, %9
%19 = lshr i64 %18, 32
%20 = shl i64 %18, 32
%21 = call i32 @ularith_add_2ul_2ul(i64* %5, i64* %6, i64 %20, i64 %19)
%22 = mul nuw i64 %17, %12
%23 = load i64, i64* %6
%24 = add i64 %23, %22
%25 = load i64, i64* %5
store i64 %25, i64* %0
store i64 %24, i64* %1
ret void
}