#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 /*<<< orphan*/ mpz_t;
typedef int /*<<< orphan*/ data;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(unsigned long long *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ mpz_import(int /*<<< orphan*/, int, int, int,
                              int /*<<< orphan*/, int /*<<< orphan*/,
                              unsigned long long *);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void get_random(mpz_t results, int num_bytes) {
  unsigned long long *data =
      (unsigned long long *)malloc((num_bytes / 8) * sizeof(long long));
  int ret_val;
  FILE *fp;
  fp = fopen("/dev/urandom", "r");
  if (fp == NULL) {
    fprintf(stderr, "cannot open random number device!");
    return;
  }
  ret_val = fread(data, 8, num_bytes / 8, fp);
  fclose(fp);
  mpz_init(results);
  mpz_import(results, (num_bytes / 8), 1, sizeof(data[0]), 0, 0, data);
  mpz_t zero_value;
  mpz_init(zero_value);
}


x86 assembly (clang, -O0):
<get_random>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe5f(%rip),%rdi
lea    0xe65(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d6 <get_random+0x66>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
call   1060 <fprintf@plt>
jmp    123e <get_random+0xce>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
mov    -0x20(%rbp),%rcx
mov    $0x8,%esi
call   1030 <fread@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x10(%rbp),%rax
mov    $0x1,%edx
mov    $0x8,%ecx
xor    %r9d,%r9d
mov    %r9d,%r8d
mov    %rax,(%rsp)
call   1090 <mpz_import@plt>
mov    -0x24(%rbp),%edi
call   1050 <mpz_init@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_random>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
lea    0x7(%rsi),%ebp
test   %esi,%esi
cmovns %esi,%ebp
mov    %ebp,%edi
and    $0xfffffff8,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
lea    0xe6a(%rip),%rdi
lea    0xe70(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11fc <get_random+0x8c>
mov    %rax,%rbx
sar    $0x3,%ebp
mov    %r15,%rdi
mov    $0x8,%esi
mov    %ebp,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14d,%edi
call   1050 <mpz_init@plt>
mov    %r15,(%rsp)
mov    %r14d,%edi
mov    %ebp,%esi
mov    $0x1,%edx
mov    $0x8,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1090 <mpz_import@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <mpz_init@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fprintf@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [34 x i8] c"cannot open random number device!\00"
define void @get_random(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%9 = load i32, i32* %4
%10 = sdiv i32 %9, 8
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 8
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i64*
store i64* %15, i64** %5
%16 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %7
%17 = load i32*, i32** %7
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %39
22: ; preds = %2
%23 = load i64*, i64** %5
%24 = load i32, i32* %4
%25 = sdiv i32 %24, 8
%26 = load i32*, i32** %7
%27 = call i32 @fread(i64* %23, i32 8, i32 %25, i32* %26)
store i32 %27, i32* %6
%28 = load i32*, i32** %7
%29 = call i32 @fclose(i32* %28)
%30 = load i32, i32* %3
%31 = call i32 @mpz_init(i32 %30)
%32 = load i32, i32* %3
%33 = load i32, i32* %4
%34 = sdiv i32 %33, 8
%35 = load i64*, i64** %5
%36 = call i32 @mpz_import(i32 %32, i32 %34, i32 1, i32 8, i32 0, i32 0, i64* %35)
%37 = load i32, i32* %8
%38 = call i32 @mpz_init(i32 %37)
br label %39
39: ; preds = %22, %19
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [34 x i8] c"cannot open random number device!\00"
define void @get_random(i32 %0, i32 %1) {
%3 = sdiv i32 %1, 8
%4 = shl nsw i32 %3, 3
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i64*
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %18
12: ; preds = %2
%13 = tail call i32 @fread(i64* %6, i32 8, i32 %3, i32* %7)
%14 = tail call i32 @fclose(i32* %7)
%15 = tail call i32 @mpz_init(i32 %0)
%16 = tail call i32 @mpz_import(i32 %0, i32 %3, i32 1, i32 8, i32 0, i32 0, i64* %6)
%17 = tail call i32 @mpz_init(i32 undef)
br label %18
18: ; preds = %12, %9
ret void
}