#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
long lrand48();
int /*<<< orphan*/ stderr;
long random_long(long a_max) {
  long the_value;
  the_value = lrand48() % (a_max + 1);
  if (the_value >= 0 && the_value <= a_max)
    return the_value;
  else {
    fprintf(stderr, "Error in random long int !\n");
    exit(0);
  }
}


x86 assembly (clang, -O0):
<random_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <lrand48@plt>
mov    -0x8(%rbp),%rcx
add    $0x1,%rcx
cqto
idiv   %rcx
mov    %rdx,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jl     1177 <random_long+0x47>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jg     1177 <random_long+0x47>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xe79(%rip),%rsi
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<random_long>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <lrand48@plt>
lea    0x1(%rbx),%rcx
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
je     1157 <random_long+0x27>
cqto
idiv   %rcx
test   %rdx,%rdx
jns    1160 <random_long+0x30>
jmp    116a <random_long+0x3a>
xor    %edx,%edx
div    %ecx
test   %rdx,%rdx
js     116a <random_long+0x3a>
cmp    %rbx,%rdx
jg     116a <random_long+0x3a>
mov    %rdx,%rax
pop    %rbx
ret
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    0xe86(%rip),%rsi
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"Error in random long int !\0A\00"
define i64 @random_long(i64 %0) {
%2 = alloca i64
%3 = alloca i64
store i64 %0, i64* %2
%4 = call i64 (...) @lrand48()
%5 = load i64, i64* %2
%6 = add nsw i64 %5, 1
%7 = srem i64 %4, %6
store i64 %7, i64* %3
%8 = load i64, i64* %3
%9 = icmp sge i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %1
%11 = load i64, i64* %3
%12 = load i64, i64* %2
%13 = icmp sle i64 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = load i64, i64* %3
ret i64 %15
16: ; preds = %10, %1
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"Error in random long int !\0A\00"
define i64 @random_long(i64 %0) {
%2 = tail call i64 (...) @lrand48()
%3 = add nsw i64 %0, 1
%4 = srem i64 %2, %3
%5 = icmp slt i64 %4, 0
%6 = icmp sgt i64 %4, %0
%7 = or i1 %5, %6
br i1 %7, label %9, label %8
8: ; preds = %1
ret i64 %4
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 0)
unreachable
}