#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*/ assert(int);
int mulh(int, int);
int mulhsu(int, int);
int mulhu(int, int);
int main() {
  assert(mulh(2147483647, 2147483647) == 1073741823);
  assert(mulh(-2147483647, 2147483647) == -1073741824);
  assert(mulhsu(2147483647, 4294967295) == 2147483646);
  assert(mulhsu(-2147483647, 4294967295) == -2147483647);
  assert(mulhu(4294967295, 613566756) == 613566755);
  assert(mulhu(4294967295, 4294967295) == 4294967294);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x7fffffff,%esi
mov    %esi,%edi
call   1050 <mulh@plt>
cmp    $0x3fffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x80000001,%edi
mov    $0x7fffffff,%esi
call   1050 <mulh@plt>
cmp    $0xc0000000,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x7fffffff,%edi
mov    $0xffffffff,%esi
call   1030 <mulhsu@plt>
cmp    $0x7ffffffe,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x80000001,%edi
mov    $0xffffffff,%esi
call   1030 <mulhsu@plt>
cmp    $0x80000001,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0xffffffff,%edi
mov    $0x24924924,%esi
call   1060 <mulhu@plt>
cmp    $0x24924923,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0xffffffff,%esi
mov    %esi,%edi
call   1060 <mulhu@plt>
cltq
mov    $0xfffffffe,%ecx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0x7fffffff,%edi
mov    $0x7fffffff,%esi
call   1050 <mulh@plt>
xor    %edi,%edi
cmp    $0x3fffffff,%eax
sete   %dil
call   1040 <assert@plt>
mov    $0x80000001,%edi
mov    $0x7fffffff,%esi
call   1050 <mulh@plt>
xor    %edi,%edi
cmp    $0xc0000000,%eax
sete   %dil
call   1040 <assert@plt>
mov    $0x7fffffff,%edi
mov    $0xffffffff,%esi
call   1030 <mulhsu@plt>
xor    %edi,%edi
cmp    $0x7ffffffe,%eax
sete   %dil
call   1040 <assert@plt>
mov    $0x80000001,%edi
mov    $0xffffffff,%esi
call   1030 <mulhsu@plt>
xor    %edi,%edi
cmp    $0x80000001,%eax
sete   %dil
call   1040 <assert@plt>
mov    $0xffffffff,%edi
mov    $0x24924924,%esi
call   1060 <mulhu@plt>
xor    %edi,%edi
cmp    $0x24924923,%eax
sete   %dil
call   1040 <assert@plt>
mov    $0xffffffff,%edi
mov    $0xffffffff,%esi
call   1060 <mulhu@plt>
xor    %edi,%edi
call   1040 <assert@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 @mulh(i32 2147483647, i32 2147483647)
%3 = icmp eq i32 %2, 1073741823
%4 = zext i1 %3 to i32
%5 = call i32 @assert(i32 %4)
%6 = call i32 @mulh(i32 -2147483647, i32 2147483647)
%7 = icmp eq i32 %6, -1073741824
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = call i32 @mulhsu(i32 2147483647, i32 -1)
%11 = icmp eq i32 %10, 2147483646
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = call i32 @mulhsu(i32 -2147483647, i32 -1)
%15 = icmp eq i32 %14, -2147483647
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = call i32 @mulhu(i32 -1, i32 613566756)
%19 = icmp eq i32 %18, 613566755
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = call i32 @mulhu(i32 -1, i32 -1)
%23 = sext i32 %22 to i64
%24 = icmp eq i64 %23, 4294967294
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i32 @mulh(i32 2147483647, i32 2147483647)
%2 = icmp eq i32 %1, 1073741823
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i32 @mulh(i32 -2147483647, i32 2147483647)
%6 = icmp eq i32 %5, -1073741824
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i32 @mulhsu(i32 2147483647, i32 -1)
%10 = icmp eq i32 %9, 2147483646
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = tail call i32 @mulhsu(i32 -2147483647, i32 -1)
%14 = icmp eq i32 %13, -2147483647
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = tail call i32 @mulhu(i32 -1, i32 613566756)
%18 = icmp eq i32 %17, 613566755
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = tail call i32 @mulhu(i32 -1, i32 -1)
%22 = tail call i32 @assert(i32 0)
ret i32 0
}