#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 abs(int);
int rand_num(unsigned int *seed) {
  unsigned int v = ((unsigned long long)(*seed) * 279470273UL) % 4294967291UL;
  if (v == 0) {
    v = *seed;
    while (((unsigned long long)v * 279470273UL) % 4294967291UL == 0)
      v++;
  }
  *seed = v;
  return abs((int)v);
}


x86 assembly (clang, -O0):
<rand_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
imul   $0x10a860c1,%rax,%rax
mov    $0xfffffffb,%ecx
xor    %edx,%edx
div    %rcx
mov    %edx,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    117c <rand_num+0x6c>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
imul   $0x10a860c1,%rax,%rax
mov    $0xfffffffb,%ecx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
jne    1177 <rand_num+0x67>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114b <rand_num+0x3b>
jmp    117c <rand_num+0x6c>
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%edi
call   1030 <abs@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_num>:
mov    (%rdi),%esi
imul   $0x10a860c1,%rsi,%rcx
movabs $0x800000028000000d,%rdx
mov    %rcx,%rax
mul    %rdx
shr    $0x1f,%rdx
lea    (%rdx,%rdx,4),%eax
add    %eax,%ecx
jne    1153 <rand_num+0x53>
movabs $0x1e0dbeb09644b973,%rax
be 0d 1e
movabs $0x100000006,%rcx
nopl   0x0(%rax,%rax,1)
mov    %esi,%edx
imul   %rax,%rdx
add    $0x1,%esi
cmp    %rcx,%rdx
jb     1140 <rand_num+0x40>
add    $0xffffffff,%esi
mov    %esi,%ecx
mov    %ecx,(%rdi)
mov    %ecx,%eax
neg    %eax
cmovs  %ecx,%eax
ret

LLVM IR (-O0):
define i32 @rand_num(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
store i32* %0, i32** %2
%4 = load i32*, i32** %2
%5 = load i32, i32* %4
%6 = zext i32 %5 to i64
%7 = mul i64 %6, 279470273
%8 = urem i64 %7, 4294967291
%9 = trunc i64 %8 to i32
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %25
12: ; preds = %1
%13 = load i32*, i32** %2
%14 = load i32, i32* %13
store i32 %14, i32* %3
br label %15
15: ; preds = %21, %12
%16 = load i32, i32* %3
%17 = zext i32 %16 to i64
%18 = mul i64 %17, 279470273
%19 = urem i64 %18, 4294967291
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = load i32, i32* %3
%23 = add i32 %22, 1
store i32 %23, i32* %3
br label %15
24: ; preds = %15
br label %25
25: ; preds = %24, %1
%26 = load i32, i32* %3
%27 = load i32*, i32** %2
store i32 %26, i32* %27
%28 = load i32, i32* %3
%29 = call i32 @abs(i32 %28)
ret i32 %29
}

LLVM IR (-O2):
define i32 @rand_num(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = zext i32 %2 to i64
%4 = mul nuw nsw i64 %3, 279470273
%5 = urem i64 %4, 4294967291
%6 = trunc i64 %5 to i32
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %1, %8
%9 = phi i32 [ %14, %8 ], [ %2, %1 ]
%10 = zext i32 %9 to i64
%11 = mul nuw nsw i64 %10, 279470273
%12 = urem i64 %11, 4294967291
%13 = icmp eq i64 %12, 0
%14 = add i32 %9, 1
br i1 %13, label %8, label %15
15: ; preds = %8, %1
%16 = phi i32 [ %6, %1 ], [ %9, %8 ]
store i32 %16, i32* %0
%17 = tail call i32 @llvm.abs.i32(i32 %16, i1 true)
ret i32 %17
}