#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 */
long long RAND_MAX;
long long rand();
long long randomValue(long long random, long long maxval) {
  if (maxval > RAND_MAX) {
    random += (long long)rand() + (long long)rand() + (long long)rand();
    random %= maxval;
    random += (long long)rand() + (long long)rand() + (long long)rand();
    random %= maxval;
    random += (long long)rand() + (long long)rand() + (long long)rand();
    random %= maxval;
    random += (long long)rand() + (long long)rand() + (long long)rand();
    random %= maxval;
    random += (long long)rand() + (long long)rand() + (long long)rand();
    random %= maxval;
    random += (long long)rand() + (long long)rand() + (long long)rand();
    random %= maxval;
    random += (long long)rand() + (long long)rand() + (long long)rand();
    random %= maxval;
  } else {
    random = rand() % maxval;
  }
  return random;
}


x86 assembly (clang, -O0):
<randomValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2eba(%rip),%rcx
cmp    (%rcx),%rax
jle    1342 <randomValue+0x232>
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,-0x80(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,%rcx
mov    -0x80(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x78(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,%rcx
mov    -0x78(%rbp),%rax
add    %rcx,%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
cqto
idiv   %rcx
mov    %rdx,-0x8(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,-0x70(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,%rcx
mov    -0x70(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x68(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
add    %rcx,%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
cqto
idiv   %rcx
mov    %rdx,-0x8(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,-0x60(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,%rcx
mov    -0x60(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
add    %rcx,%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
cqto
idiv   %rcx
mov    %rdx,-0x8(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,-0x50(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
add    %rcx,%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
cqto
idiv   %rcx
mov    %rdx,-0x8(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
add    %rcx,%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
cqto
idiv   %rcx
mov    %rdx,-0x8(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
add    %rcx,%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
cqto
idiv   %rcx
mov    %rdx,-0x8(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
add    %rcx,%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
cqto
idiv   %rcx
mov    %rdx,-0x8(%rbp)
jmp    1353 <randomValue+0x243>
mov    $0x0,%al
call   1030 <rand@plt>
cqto
idivq  -0x10(%rbp)
mov    %rdx,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomValue>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2ec3(%rip),%rax
mov    (%rax),%r12
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%rbx
cmp    %r14,%r12
jge    12ff <randomValue+0x1ef>
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1030 <rand@plt>
add    %r15,%rbx
add    %r12,%rbx
add    %rax,%rbx
mov    %rbx,%rax
or     %r14,%rax
shr    $0x20,%rax
je     116e <randomValue+0x5e>
mov    %rbx,%rax
cqto
idiv   %r14
mov    %rdx,%r15
jmp    1178 <randomValue+0x68>
mov    %ebx,%eax
xor    %edx,%edx
div    %r14d
mov    %edx,%r15d
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1030 <rand@plt>
add    %r15,%rbx
add    %r12,%rbx
add    %rax,%rbx
mov    %rbx,%rax
or     %r14,%rax
shr    $0x20,%rax
je     11b5 <randomValue+0xa5>
mov    %rbx,%rax
cqto
idiv   %r14
mov    %rdx,%r15
jmp    11bf <randomValue+0xaf>
mov    %ebx,%eax
xor    %edx,%edx
div    %r14d
mov    %edx,%r15d
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1030 <rand@plt>
add    %r15,%rbx
add    %r12,%rbx
add    %rax,%rbx
mov    %rbx,%rax
or     %r14,%rax
shr    $0x20,%rax
je     11fc <randomValue+0xec>
mov    %rbx,%rax
cqto
idiv   %r14
mov    %rdx,%r15
jmp    1206 <randomValue+0xf6>
mov    %ebx,%eax
xor    %edx,%edx
div    %r14d
mov    %edx,%r15d
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1030 <rand@plt>
add    %r15,%rbx
add    %r12,%rbx
add    %rax,%rbx
mov    %rbx,%rax
or     %r14,%rax
shr    $0x20,%rax
je     1243 <randomValue+0x133>
mov    %rbx,%rax
cqto
idiv   %r14
mov    %rdx,%r15
jmp    124d <randomValue+0x13d>
mov    %ebx,%eax
xor    %edx,%edx
div    %r14d
mov    %edx,%r15d
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1030 <rand@plt>
add    %r15,%rbx
add    %r12,%rbx
add    %rax,%rbx
mov    %rbx,%rax
or     %r14,%rax
shr    $0x20,%rax
je     128a <randomValue+0x17a>
mov    %rbx,%rax
cqto
idiv   %r14
mov    %rdx,%r15
jmp    1294 <randomValue+0x184>
mov    %ebx,%eax
xor    %edx,%edx
div    %r14d
mov    %edx,%r15d
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1030 <rand@plt>
add    %r15,%rbx
add    %r12,%rbx
add    %rax,%rbx
mov    %rbx,%rax
or     %r14,%rax
shr    $0x20,%rax
je     12d1 <randomValue+0x1c1>
mov    %rbx,%rax
cqto
idiv   %r14
mov    %rdx,%r15
jmp    12db <randomValue+0x1cb>
mov    %ebx,%eax
xor    %edx,%edx
div    %r14d
mov    %edx,%r15d
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1030 <rand@plt>
add    %r15,%rbx
add    %r12,%rbx
add    %rax,%rbx
mov    %rbx,%rax
or     %r14,%rax
shr    $0x20,%rax
je     1318 <randomValue+0x208>
mov    %rbx,%rax
cqto
idiv   %r14
mov    %rdx,%rax
jmp    1321 <randomValue+0x211>
mov    %ebx,%eax
xor    %edx,%edx
div    %r14d
mov    %edx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
define i64 @randomValue(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
%5 = load i64, i64* %4
%6 = load i64, i64* @RAND_MAX
%7 = icmp sgt i64 %5, %6
br i1 %7, label %8, label %79
8: ; preds = %2
%9 = call i64 (...) @rand()
%10 = call i64 (...) @rand()
%11 = add nsw i64 %9, %10
%12 = call i64 (...) @rand()
%13 = add nsw i64 %11, %12
%14 = load i64, i64* %3
%15 = add nsw i64 %14, %13
store i64 %15, i64* %3
%16 = load i64, i64* %4
%17 = load i64, i64* %3
%18 = srem i64 %17, %16
store i64 %18, i64* %3
%19 = call i64 (...) @rand()
%20 = call i64 (...) @rand()
%21 = add nsw i64 %19, %20
%22 = call i64 (...) @rand()
%23 = add nsw i64 %21, %22
%24 = load i64, i64* %3
%25 = add nsw i64 %24, %23
store i64 %25, i64* %3
%26 = load i64, i64* %4
%27 = load i64, i64* %3
%28 = srem i64 %27, %26
store i64 %28, i64* %3
%29 = call i64 (...) @rand()
%30 = call i64 (...) @rand()
%31 = add nsw i64 %29, %30
%32 = call i64 (...) @rand()
%33 = add nsw i64 %31, %32
%34 = load i64, i64* %3
%35 = add nsw i64 %34, %33
store i64 %35, i64* %3
%36 = load i64, i64* %4
%37 = load i64, i64* %3
%38 = srem i64 %37, %36
store i64 %38, i64* %3
%39 = call i64 (...) @rand()
%40 = call i64 (...) @rand()
%41 = add nsw i64 %39, %40
%42 = call i64 (...) @rand()
%43 = add nsw i64 %41, %42
%44 = load i64, i64* %3
%45 = add nsw i64 %44, %43
store i64 %45, i64* %3
%46 = load i64, i64* %4
%47 = load i64, i64* %3
%48 = srem i64 %47, %46
store i64 %48, i64* %3
%49 = call i64 (...) @rand()
%50 = call i64 (...) @rand()
%51 = add nsw i64 %49, %50
%52 = call i64 (...) @rand()
%53 = add nsw i64 %51, %52
%54 = load i64, i64* %3
%55 = add nsw i64 %54, %53
store i64 %55, i64* %3
%56 = load i64, i64* %4
%57 = load i64, i64* %3
%58 = srem i64 %57, %56
store i64 %58, i64* %3
%59 = call i64 (...) @rand()
%60 = call i64 (...) @rand()
%61 = add nsw i64 %59, %60
%62 = call i64 (...) @rand()
%63 = add nsw i64 %61, %62
%64 = load i64, i64* %3
%65 = add nsw i64 %64, %63
store i64 %65, i64* %3
%66 = load i64, i64* %4
%67 = load i64, i64* %3
%68 = srem i64 %67, %66
store i64 %68, i64* %3
%69 = call i64 (...) @rand()
%70 = call i64 (...) @rand()
%71 = add nsw i64 %69, %70
%72 = call i64 (...) @rand()
%73 = add nsw i64 %71, %72
%74 = load i64, i64* %3
%75 = add nsw i64 %74, %73
store i64 %75, i64* %3
%76 = load i64, i64* %4
%77 = load i64, i64* %3
%78 = srem i64 %77, %76
store i64 %78, i64* %3
br label %83
79: ; preds = %2
%80 = call i64 (...) @rand()
%81 = load i64, i64* %4
%82 = srem i64 %80, %81
store i64 %82, i64* %3
br label %83
83: ; preds = %79, %8
%84 = load i64, i64* %3
ret i64 %84
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
define i64 @randomValue(i64 %0, i64 %1) {
%3 = load i64, i64* @RAND_MAX
%4 = icmp slt i64 %3, %1
%5 = tail call i64 (...) @rand()
br i1 %4, label %6, label %54
6: ; preds = %2
%7 = tail call i64 (...) @rand()
%8 = tail call i64 (...) @rand()
%9 = add i64 %5, %0
%10 = add i64 %9, %7
%11 = add i64 %10, %8
%12 = srem i64 %11, %1
%13 = tail call i64 (...) @rand()
%14 = tail call i64 (...) @rand()
%15 = tail call i64 (...) @rand()
%16 = add i64 %13, %12
%17 = add i64 %16, %14
%18 = add i64 %17, %15
%19 = srem i64 %18, %1
%20 = tail call i64 (...) @rand()
%21 = tail call i64 (...) @rand()
%22 = tail call i64 (...) @rand()
%23 = add i64 %20, %19
%24 = add i64 %23, %21
%25 = add i64 %24, %22
%26 = srem i64 %25, %1
%27 = tail call i64 (...) @rand()
%28 = tail call i64 (...) @rand()
%29 = tail call i64 (...) @rand()
%30 = add i64 %27, %26
%31 = add i64 %30, %28
%32 = add i64 %31, %29
%33 = srem i64 %32, %1
%34 = tail call i64 (...) @rand()
%35 = tail call i64 (...) @rand()
%36 = tail call i64 (...) @rand()
%37 = add i64 %34, %33
%38 = add i64 %37, %35
%39 = add i64 %38, %36
%40 = srem i64 %39, %1
%41 = tail call i64 (...) @rand()
%42 = tail call i64 (...) @rand()
%43 = tail call i64 (...) @rand()
%44 = add i64 %41, %40
%45 = add i64 %44, %42
%46 = add i64 %45, %43
%47 = srem i64 %46, %1
%48 = tail call i64 (...) @rand()
%49 = tail call i64 (...) @rand()
%50 = tail call i64 (...) @rand()
%51 = add i64 %48, %47
%52 = add i64 %51, %49
%53 = add i64 %52, %50
br label %54
54: ; preds = %2, %6
%55 = phi i64 [ %53, %6 ], [ %5, %2 ]
%56 = srem i64 %55, %1
ret i64 %56
}