#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 */
typedef int uint64_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int hi_dword(int);
int lo_dword(int);
uint64_t mul128(uint64_t multiplier, uint64_t multiplicand,
                uint64_t *product_hi) {
  uint64_t a = hi_dword(multiplier);
  uint64_t b = lo_dword(multiplier);
  uint64_t c = hi_dword(multiplicand);
  uint64_t d = lo_dword(multiplicand);
  uint64_t ac = a * c;
  uint64_t ad = a * d;
  uint64_t bc = b * c;
  uint64_t bd = b * d;
  uint64_t adbc = ad + bc;
  uint64_t adbc_carry = adbc < ad ? 1 : 0;
  uint64_t product_lo = bd + (adbc << 32);
  uint64_t product_lo_carry = product_lo < bd ? 1 : 0;
  *product_hi = ac + (adbc >> 32) + (adbc_carry << 32) + product_lo_carry;
  assert(ac <= *product_hi);
  return product_lo;
}


x86 assembly (clang, -O0):
<mul128>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <hi_dword@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <lo_dword@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <hi_dword@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <lo_dword@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
imul   -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%eax
imul   -0x20(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edx
mov    -0x28(%rbp),%esi
xor    %eax,%eax
mov    $0x1,%ecx
cmp    %esi,%edx
cmovl  %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%eax
mov    -0x34(%rbp),%edx
mov    $0x20,%ecx
shl    %cl,%edx
mov    %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%edx
mov    -0x30(%rbp),%esi
xor    %eax,%eax
mov    $0x1,%ecx
cmp    %esi,%edx
cmovl  %ecx,%eax
mov    %eax,-0x40(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x34(%rbp),%edx
mov    $0x20,%ecx
sar    %cl,%edx
mov    %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%eax
mov    $0x20,%ecx
shl    %cl,%eax
mov    -0x44(%rbp),%ecx
add    %eax,%ecx
add    -0x40(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x3c(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mul128>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
call   1050 <hi_dword@plt>
mov    %ebp,%edi
call   1030 <lo_dword@plt>
mov    %ebx,%edi
call   1050 <hi_dword@plt>
mov    %ebx,%edi
call   1030 <lo_dword@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <assert@plt>

LLVM IR (-O0):
define i32 @mul128(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%19 = load i32, i32* %4
%20 = call i32 @hi_dword(i32 %19)
store i32 %20, i32* %7
%21 = load i32, i32* %4
%22 = call i32 @lo_dword(i32 %21)
store i32 %22, i32* %8
%23 = load i32, i32* %5
%24 = call i32 @hi_dword(i32 %23)
store i32 %24, i32* %9
%25 = load i32, i32* %5
%26 = call i32 @lo_dword(i32 %25)
store i32 %26, i32* %10
%27 = load i32, i32* %7
%28 = load i32, i32* %9
%29 = mul nsw i32 %27, %28
store i32 %29, i32* %11
%30 = load i32, i32* %7
%31 = load i32, i32* %10
%32 = mul nsw i32 %30, %31
store i32 %32, i32* %12
%33 = load i32, i32* %8
%34 = load i32, i32* %9
%35 = mul nsw i32 %33, %34
store i32 %35, i32* %13
%36 = load i32, i32* %8
%37 = load i32, i32* %10
%38 = mul nsw i32 %36, %37
store i32 %38, i32* %14
%39 = load i32, i32* %12
%40 = load i32, i32* %13
%41 = add nsw i32 %39, %40
store i32 %41, i32* %15
%42 = load i32, i32* %15
%43 = load i32, i32* %12
%44 = icmp slt i32 %42, %43
%45 = zext i1 %44 to i64
%46 = select i1 %44, i32 1, i32 0
store i32 %46, i32* %16
%47 = load i32, i32* %14
%48 = load i32, i32* %15
%49 = shl i32 %48, 32
%50 = add nsw i32 %47, %49
store i32 %50, i32* %17
%51 = load i32, i32* %17
%52 = load i32, i32* %14
%53 = icmp slt i32 %51, %52
%54 = zext i1 %53 to i64
%55 = select i1 %53, i32 1, i32 0
store i32 %55, i32* %18
%56 = load i32, i32* %11
%57 = load i32, i32* %15
%58 = ashr i32 %57, 32
%59 = add nsw i32 %56, %58
%60 = load i32, i32* %16
%61 = shl i32 %60, 32
%62 = add nsw i32 %59, %61
%63 = load i32, i32* %18
%64 = add nsw i32 %62, %63
%65 = load i32*, i32** %6
store i32 %64, i32* %65
%66 = load i32, i32* %11
%67 = load i32*, i32** %6
%68 = load i32, i32* %67
%69 = icmp sle i32 %66, %68
%70 = zext i1 %69 to i32
%71 = call i32 @assert(i32 %70)
%72 = load i32, i32* %17
ret i32 %72
}

LLVM IR (-O2):
define i32 @mul128(i32 %0, i32 %1, i32* nocapture readnone %2) {
%4 = tail call i32 @hi_dword(i32 %0)
%5 = tail call i32 @lo_dword(i32 %0)
%6 = tail call i32 @hi_dword(i32 %1)
%7 = tail call i32 @lo_dword(i32 %1)
%8 = tail call i32 @assert(i32 poison)
ret i32 poison
}