#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 */
typedef int int64_t;

/* Variables and functions */
int mt_genrand_int32();
int64_t mtrandom_int64(int64_t range) {
  int64_t r = 0;
  if (range == 0)
    return range;
  r |= mt_genrand_int32();
  r <<= 31;
  r |= mt_genrand_int32();
  if (range > 0)
    return r % range;
  else
    return -(r % -range);
}


x86 assembly (clang, -O0):
<mtrandom_int64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1137 <mtrandom_int64+0x27>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1185 <mtrandom_int64+0x75>
mov    $0x0,%al
call   1030 <mt_genrand_int32@plt>
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x1f,%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1030 <mt_genrand_int32@plt>
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    1173 <mtrandom_int64+0x63>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %edx,-0x4(%rbp)
jmp    1185 <mtrandom_int64+0x75>
mov    -0xc(%rbp),%eax
xor    %ecx,%ecx
sub    -0x8(%rbp),%ecx
cltd
idiv   %ecx
xor    %eax,%eax
sub    %edx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mtrandom_int64>:
push   %rbp
push   %rbx
push   %rax
test   %edi,%edi
je     1139 <mtrandom_int64+0x29>
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <mt_genrand_int32@plt>
mov    %eax,%ebp
shl    $0x1f,%ebp
xor    %eax,%eax
call   1030 <mt_genrand_int32@plt>
or     %ebp,%eax
test   %ebx,%ebx
jle    113d <mtrandom_int64+0x2d>
cltd
idiv   %ebx
mov    %edx,%eax
jmp    1146 <mtrandom_int64+0x36>
xor    %eax,%eax
jmp    1146 <mtrandom_int64+0x36>
neg    %ebx
cltd
idiv   %ebx
mov    %edx,%eax
neg    %eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mtrandom_int64(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %4
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load i32, i32* %3
store i32 %8, i32* %2
br label %30
9: ; preds = %1
%10 = call i32 (...) @mt_genrand_int32()
%11 = load i32, i32* %4
%12 = or i32 %11, %10
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = shl i32 %13, 31
store i32 %14, i32* %4
%15 = call i32 (...) @mt_genrand_int32()
%16 = load i32, i32* %4
%17 = or i32 %16, %15
store i32 %17, i32* %4
%18 = load i32, i32* %3
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %9
%21 = load i32, i32* %4
%22 = load i32, i32* %3
%23 = srem i32 %21, %22
store i32 %23, i32* %2
br label %30
24: ; preds = %9
%25 = load i32, i32* %4
%26 = load i32, i32* %3
%27 = sub nsw i32 0, %26
%28 = srem i32 %25, %27
%29 = sub nsw i32 0, %28
store i32 %29, i32* %2
br label %30
30: ; preds = %24, %20, %7
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
define i32 @mtrandom_int64(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %15, label %3
3: ; preds = %1
%4 = tail call i32 (...) @mt_genrand_int32()
%5 = shl i32 %4, 31
%6 = tail call i32 (...) @mt_genrand_int32()
%7 = or i32 %5, %6
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = srem i32 %7, %0
br label %15
11: ; preds = %3
%12 = sub nsw i32 0, %0
%13 = srem i32 %7, %12
%14 = sub nsw i32 0, %13
br label %15
15: ; preds = %1, %11, %9
%16 = phi i32 [ %10, %9 ], [ %14, %11 ], [ 0, %1 ]
ret i32 %16
}