#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 */
scalar_t__ time(int /*<<< orphan*/);
scalar_t__ unlikely(int);
unsigned long _stp_random_u(unsigned long n) {
  static unsigned long seed;
  static int initialized_p = 0;
  if (unlikely(!initialized_p)) {
    seed = (unsigned long)time(0);
    initialized_p = 1;
  }
  seed = seed * 1103515245 + 12345;
  return (n == 0 ? 0 : seed % n);
}


x86 assembly (clang, -O0):
<_stp_random_u>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpl   $0x0,0x2f0d(%rip)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <unlikely@plt>
cmp    $0x0,%rax
je     1164 <_stp_random_u+0x44>
xor    %edi,%edi
call   1030 <time@plt>
mov    %rax,0x2ede(%rip)
movl   $0x1,0x2edc(%rip)
imul   $0x41c64e6d,0x2ec9(%rip),%rax
6d 4e c6 41
add    $0x3039,%rax
mov    %rax,0x2ebc(%rip)
cmpq   $0x0,-0x8(%rbp)
jne    1194 <_stp_random_u+0x74>
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,-0x10(%rbp)
jmp    11a7 <_stp_random_u+0x87>
mov    0x2e9d(%rip),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_stp_random_u>:
push   %rbx
mov    %rdi,%rbx
movzbl 0x2f15(%rip),%edi
xor    $0x1,%edi
call   1040 <unlikely@plt>
test   %rax,%rax
je     1148 <_stp_random_u+0x28>
xor    %edi,%edi
call   1030 <time@plt>
movb   $0x1,0x2efa(%rip)
jmp    114f <_stp_random_u+0x2f>
mov    0x2ee9(%rip),%rax
imul   $0x41c64e6d,%rax,%rax
add    $0x3039,%rax
mov    %rax,0x2ed5(%rip)
test   %rbx,%rbx
je     117e <_stp_random_u+0x5e>
mov    %rax,%rcx
or     %rbx,%rcx
shr    $0x20,%rcx
je     1182 <_stp_random_u+0x62>
xor    %edx,%edx
div    %rbx
mov    %rdx,%rax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
xor    %edx,%edx
div    %ebx
mov    %edx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@_stp_random_u.seed = internal global i64 0
@_stp_random_u.initialized_p = internal global i32 0
define i64 @_stp_random_u(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = load i32, i32* @_stp_random_u.initialized_p
%4 = icmp ne i32 %3, 0
%5 = xor i1 %4, true
%6 = zext i1 %5 to i32
%7 = call i64 @unlikely(i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i64 @time(i32 0)
store i64 %10, i64* @_stp_random_u.seed
store i32 1, i32* @_stp_random_u.initialized_p
br label %11
11: ; preds = %9, %1
%12 = load i64, i64* @_stp_random_u.seed
%13 = mul i64 %12, 1103515245
%14 = add i64 %13, 12345
store i64 %14, i64* @_stp_random_u.seed
%15 = load i64, i64* %2
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %11
br label %22
18: ; preds = %11
%19 = load i64, i64* @_stp_random_u.seed
%20 = load i64, i64* %2
%21 = urem i64 %19, %20
br label %22
22: ; preds = %18, %17
%23 = phi i64 [ 0, %17 ], [ %21, %18 ]
ret i64 %23
}

LLVM IR (-O2):
@_stp_random_u.seed = internal unnamed_addr global i64 0
@_stp_random_u.initialized_p = internal unnamed_addr global i1 false
define i64 @_stp_random_u(i64 %0) {
%2 = load i1, i1* @_stp_random_u.initialized_p
%3 = xor i1 %2, true
%4 = zext i1 %3 to i32
%5 = tail call i64 @unlikely(i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load i64, i64* @_stp_random_u.seed
br label %11
9: ; preds = %1
%10 = tail call i64 @time(i32 0)
store i1 true, i1* @_stp_random_u.initialized_p
br label %11
11: ; preds = %7, %9
%12 = phi i64 [ %8, %7 ], [ %10, %9 ]
%13 = mul i64 %12, 1103515245
%14 = add i64 %13, 12345
store i64 %14, i64* @_stp_random_u.seed
%15 = icmp eq i64 %0, 0
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = urem i64 %14, %0
br label %18
18: ; preds = %11, %16
%19 = phi i64 [ %17, %16 ], [ 0, %11 ]
ret i64 %19
}