#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 uint_fast64_t;
typedef int uint_fast32_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
uint_fast32_t mod_mul(uint_fast32_t a, uint_fast32_t b) {
  uint_fast64_t temp;
  uint_fast32_t temp2;
  assert(a <= 0x7FFFFFFE);
  assert(b <= 0x7FFFFFFE);
  temp = (uint_fast64_t)a * b;
  temp2 = (uint_fast32_t)(temp & 0x7FFFFFFF) + (uint_fast32_t)(temp >> 31);
  return (temp2 >= 0x7FFFFFFF) ? (temp2 - 0x7FFFFFFF) : temp2;
}


x86 assembly (clang, -O0):
<mod_mul>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x7ffffffe,-0x4(%rbp)
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x7ffffffe,-0x8(%rbp)
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x4(%rbp),%eax
imul   -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x7fffffff,%eax
mov    -0xc(%rbp),%ecx
sar    $0x1f,%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x7fffffff,-0x10(%rbp)
jl     1180 <mod_mul+0x70>
mov    -0x10(%rbp),%eax
sub    $0x7fffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1186 <mod_mul+0x76>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mod_mul>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
xor    %edi,%edi
cmp    $0x7fffffff,%ebp
setne  %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmp    $0x7fffffff,%ebx
setne  %dil
call   1030 <assert@plt>
imul   %ebp,%ebx
mov    %ebx,%eax
and    $0x7fffffff,%eax
sar    $0x1f,%ebx
add    %eax,%ebx
xor    %eax,%eax
cmp    $0x7fffffff,%ebx
cmovne %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mod_mul(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = icmp sle i32 %7, 2147483646
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i32, i32* %4
%12 = icmp sle i32 %11, 2147483646
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = mul nsw i32 %15, %16
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = and i32 %18, 2147483647
%20 = load i32, i32* %5
%21 = ashr i32 %20, 31
%22 = add nsw i32 %19, %21
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp sge i32 %23, 2147483647
br i1 %24, label %25, label %28
25: ; preds = %2
%26 = load i32, i32* %6
%27 = sub nsw i32 %26, 2147483647
br label %30
28: ; preds = %2
%29 = load i32, i32* %6
br label %30
30: ; preds = %28, %25
%31 = phi i32 [ %27, %25 ], [ %29, %28 ]
ret i32 %31
}

LLVM IR (-O2):
define i32 @mod_mul(i32 %0, i32 %1) {
%3 = icmp ne i32 %0, 2147483647
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = icmp ne i32 %1, 2147483647
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = mul nsw i32 %1, %0
%10 = and i32 %9, 2147483647
%11 = ashr i32 %9, 31
%12 = add nsw i32 %10, %11
%13 = icmp eq i32 %12, 2147483647
%14 = select i1 %13, i32 0, i32 %12
ret i32 %14
}