#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_sqr_ul_2ul(unsigned long *r1, unsigned long *r2,
                        const unsigned long a) {
  const int half = 64 / 2;
  const unsigned long mask = (1UL << half) - 1UL;
  unsigned long t1, t2, p1, p2;
  t1 = (a & mask) * (a & mask);
  t2 = 0UL;
  p1 = (a >> half) * (a & mask);
  p2 = p1 >> half;
  p1 = (p1 & mask) << half;
  ularith_add_2ul_2ul(&t1, &t2, p1, p2);
  ularith_add_2ul_2ul(&t1, &t2, p1, p2);
  t2 += (a >> half) * (a >> half);
  *r1 = t1;
  *r2 = t2;
}


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

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

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

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