#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);
long genr_rand_port(long init_rand) {
  long k, residue;
  k = init_rand / 51924L;
  residue = 41358L * (init_rand - 51924L * k) - 10855L * k;
  if (residue < 0) {
    residue += 2147483647L;
  }
  assert(residue >= 1 && residue <= (2147483647L - 1));
  return residue;
}


x86 assembly (clang, -O0):
<genr_rand_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    $0xcad4,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
imul   $0xcad4,-0x10(%rbp),%rcx
sub    %rcx,%rax
imul   $0xa18e,%rax,%rax
imul   $0x2a67,-0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    116c <genr_rand_port+0x5c>
mov    -0x18(%rbp),%rax
add    $0x7fffffff,%rax
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x1,-0x18(%rbp)
mov    %al,-0x19(%rbp)
jl     118a <genr_rand_port+0x7a>
cmpq   $0x7ffffffe,-0x18(%rbp)
7f
setle  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genr_rand_port>:
push   %rbx
movabs $0x50c71ac2f68db74f,%rcx
1a c7 50
mov    %rdi,%rax
imul   %rcx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0xe,%rdx
add    %rax,%rdx
imul   $0xffffffffffff352c,%rdx,%rax
add    %rdi,%rax
imul   $0xa18e,%rax,%rax
imul   $0xffffffffffffd599,%rdx,%rcx
lea    (%rax,%rcx,1),%rbx
add    $0x7fffffff,%rbx
add    %rcx,%rax
cmovns %rax,%rbx
lea    -0x1(%rbx),%rax
xor    %edi,%edi
cmp    $0x7ffffffe,%rax
setb   %dil
call   1030 <assert@plt>
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i64 @genr_rand_port(i64 %0) {
%2 = sdiv i64 %0, 51924
%3 = mul nsw i64 %2, -51924
%4 = add i64 %3, %0
%5 = mul nsw i64 %4, 41358
%6 = mul nsw i64 %2, -10855
%7 = add i64 %5, %6
%8 = icmp slt i64 %7, 0
%9 = add nsw i64 %7, 2147483647
%10 = select i1 %8, i64 %9, i64 %7
%11 = add nsw i64 %10, -1
%12 = icmp ult i64 %11, 2147483646
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
ret i64 %10
}