#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_mac(uint_fast32_t sum, uint_fast32_t a, uint_fast32_t b) {
  uint_fast64_t temp;
  uint_fast32_t temp2;
  assert(sum <= 0x7FFFFFFE);
  assert(a <= 0x7FFFFFFE);
  assert(b <= 0x7FFFFFFE);
  temp = (uint_fast64_t)a * b + sum;
  temp2 = (uint_fast32_t)(temp & 0x7FFFFFFF) + (uint_fast32_t)(temp >> 31);
  return (temp2 >= 0x7FFFFFFF) ? (temp2 - 0x7FFFFFFF) : temp2;
}


x86 assembly (clang, -O0):
<mod_mac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%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>
cmpl   $0x7ffffffe,-0xc(%rbp)
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
and    $0x7fffffff,%eax
mov    -0x10(%rbp),%ecx
sar    $0x1f,%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x7fffffff,-0x14(%rbp)
jl     119a <mod_mac+0x8a>
mov    -0x14(%rbp),%eax
sub    $0x7fffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    11a0 <mod_mac+0x90>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mod_mac>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %esi,%ebp
mov    %edi,%r14d
xor    %edi,%edi
cmp    $0x7fffffff,%r14d
setne  %dil
call   1030 <assert@plt>
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
add    %r14d,%ebx
mov    %ebx,%eax
and    $0x7fffffff,%eax
sar    $0x1f,%ebx
add    %eax,%ebx
xor    %eax,%eax
cmp    $0x7fffffff,%ebx
cmovne %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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