#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*/ gmp_randstate_t;

/* Variables and functions */
int CHAR_BIT;
int SHA512_DIGEST_LENGTH;
int /*<<< orphan*/ gmp_randinit_mt(int /*<<< orphan*/);
int /*<<< orphan*/ gmp_randseed(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_add_ui(int /*<<< orphan*/, int /*<<< orphan*/,
                              unsigned char);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init_set_ui(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mul_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_urandomm(int /*<<< orphan*/, int /*<<< orphan*/,
                                int /*<<< orphan*/);
void seedPRNG(unsigned char *hash, gmp_randstate_t prng) {
  gmp_randinit_mt(prng);
  mpz_t seed;
  mpz_init_set_ui(seed, 0);
  for (int i = 0; i < (SHA512_DIGEST_LENGTH); i++) {
    mpz_mul_ui(seed, seed, 1 << CHAR_BIT);
    mpz_add_ui(seed, seed, hash[i]);
  }
  gmp_randseed(prng, seed);
  mpz_t toshuffle;
  mpz_init(toshuffle);
  for (int i = 0; i < (10); i++)
    mpz_urandomm(toshuffle, prng, seed);
  mpz_clear(toshuffle);
  mpz_clear(seed);
}


x86 assembly (clang, -O0):
<seedPRNG>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1080 <gmp_randinit_mt@plt>
mov    -0x10(%rbp),%edi
xor    %esi,%esi
call   1050 <mpz_init_set_ui@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e36(%rip),%rcx
cmp    (%rcx),%eax
jge    11fa <seedPRNG+0x7a>
mov    -0x10(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    0x2e11(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
shl    %cl,%edx
call   1090 <mpz_mul_ui@plt>
mov    -0x10(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
call   1030 <mpz_add_ui@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a8 <seedPRNG+0x28>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1060 <gmp_randseed@plt>
mov    -0x18(%rbp),%edi
call   1040 <mpz_init@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    123a <seedPRNG+0xba>
mov    -0x18(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   10a0 <mpz_urandomm@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1214 <seedPRNG+0x94>
mov    -0x18(%rbp),%edi
call   1070 <mpz_clear@plt>
mov    -0x10(%rbp),%edi
call   1070 <mpz_clear@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seedPRNG>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
mov    %esi,%edi
call   1080 <gmp_randinit_mt@plt>
xor    %esi,%esi
call   1050 <mpz_init_set_ui@plt>
mov    0x2e45(%rip),%r15
cmpl   $0x0,(%r15)
jle    11e6 <seedPRNG+0x66>
xor    %ebp,%ebp
mov    0x2e26(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%r12),%ecx
mov    $0x1,%edx
shl    %cl,%edx
call   1090 <mpz_mul_ui@plt>
movzbl (%rbx,%rbp,1),%edx
call   1030 <mpz_add_ui@plt>
add    $0x1,%rbp
movslq (%r15),%rax
cmp    %rax,%rbp
jl     11c0 <seedPRNG+0x40>
mov    %r14d,%edi
call   1060 <gmp_randseed@plt>
call   1040 <mpz_init@plt>
mov    %r14d,%esi
call   10a0 <mpz_urandomm@plt>
mov    %r14d,%esi
call   10a0 <mpz_urandomm@plt>
mov    %r14d,%esi
call   10a0 <mpz_urandomm@plt>
mov    %r14d,%esi
call   10a0 <mpz_urandomm@plt>
mov    %r14d,%esi
call   10a0 <mpz_urandomm@plt>
mov    %r14d,%esi
call   10a0 <mpz_urandomm@plt>
mov    %r14d,%esi
call   10a0 <mpz_urandomm@plt>
mov    %r14d,%esi
call   10a0 <mpz_urandomm@plt>
mov    %r14d,%esi
call   10a0 <mpz_urandomm@plt>
mov    %r14d,%esi
call   10a0 <mpz_urandomm@plt>
call   1070 <mpz_clear@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <mpz_clear@plt>

LLVM IR (-O0):
@SHA512_DIGEST_LENGTH = global i32 0
@CHAR_BIT = global i32 0
define void @seedPRNG(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i32, i32* %4
%10 = call i32 @gmp_randinit_mt(i32 %9)
%11 = load i32, i32* %5
%12 = call i32 @mpz_init_set_ui(i32 %11, i32 0)
store i32 0, i32* %6
br label %13
13: ; preds = %31, %2
%14 = load i32, i32* %6
%15 = load i32, i32* @SHA512_DIGEST_LENGTH
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %34
17: ; preds = %13
%18 = load i32, i32* %5
%19 = load i32, i32* %5
%20 = load i32, i32* @CHAR_BIT
%21 = shl i32 1, %20
%22 = call i32 @mpz_mul_ui(i32 %18, i32 %19, i32 %21)
%23 = load i32, i32* %5
%24 = load i32, i32* %5
%25 = load i8*, i8** %3
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = call i32 @mpz_add_ui(i32 %23, i32 %24, i8 zeroext %29)
br label %31
31: ; preds = %17
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
br label %13
34: ; preds = %13
%35 = load i32, i32* %4
%36 = load i32, i32* %5
%37 = call i32 @gmp_randseed(i32 %35, i32 %36)
%38 = load i32, i32* %7
%39 = call i32 @mpz_init(i32 %38)
store i32 0, i32* %8
br label %40
40: ; preds = %48, %34
%41 = load i32, i32* %8
%42 = icmp slt i32 %41, 10
br i1 %42, label %43, label %51
43: ; preds = %40
%44 = load i32, i32* %7
%45 = load i32, i32* %4
%46 = load i32, i32* %5
%47 = call i32 @mpz_urandomm(i32 %44, i32 %45, i32 %46)
br label %48
48: ; preds = %43
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
br label %40
51: ; preds = %40
%52 = load i32, i32* %7
%53 = call i32 @mpz_clear(i32 %52)
%54 = load i32, i32* %5
%55 = call i32 @mpz_clear(i32 %54)
ret void
}

LLVM IR (-O2):
@SHA512_DIGEST_LENGTH = global i32 0
@CHAR_BIT = global i32 0
define void @seedPRNG(i8* nocapture %0, i32 %1) {
%3 = tail call i32 @gmp_randinit_mt(i32 %1)
%4 = tail call i32 @mpz_init_set_ui(i32 undef, i32 0)
%5 = load i32, i32* @SHA512_DIGEST_LENGTH
%6 = icmp sgt i32 %5, 0
br i1 %6, label %22, label %7
7: ; preds = %22, %2
%8 = tail call i32 @gmp_randseed(i32 %1, i32 undef)
%9 = tail call i32 @mpz_init(i32 undef)
%10 = tail call i32 @mpz_urandomm(i32 undef, i32 %1, i32 undef)
%11 = tail call i32 @mpz_urandomm(i32 undef, i32 %1, i32 undef)
%12 = tail call i32 @mpz_urandomm(i32 undef, i32 %1, i32 undef)
%13 = tail call i32 @mpz_urandomm(i32 undef, i32 %1, i32 undef)
%14 = tail call i32 @mpz_urandomm(i32 undef, i32 %1, i32 undef)
%15 = tail call i32 @mpz_urandomm(i32 undef, i32 %1, i32 undef)
%16 = tail call i32 @mpz_urandomm(i32 undef, i32 %1, i32 undef)
%17 = tail call i32 @mpz_urandomm(i32 undef, i32 %1, i32 undef)
%18 = tail call i32 @mpz_urandomm(i32 undef, i32 %1, i32 undef)
%19 = tail call i32 @mpz_urandomm(i32 undef, i32 %1, i32 undef)
%20 = tail call i32 @mpz_clear(i32 undef)
%21 = tail call i32 @mpz_clear(i32 undef)
ret void
22: ; preds = %2, %22
%23 = phi i64 [ %30, %22 ], [ 0, %2 ]
%24 = load i32, i32* @CHAR_BIT
%25 = shl nuw i32 1, %24
%26 = tail call i32 @mpz_mul_ui(i32 undef, i32 undef, i32 %25)
%27 = getelementptr inbounds i8, i8* %0, i64 %23
%28 = load i8, i8* %27
%29 = tail call i32 @mpz_add_ui(i32 undef, i32 undef, i8 zeroext %28)
%30 = add nuw nsw i64 %23, 1
%31 = load i32, i32* @SHA512_DIGEST_LENGTH
%32 = sext i32 %31 to i64
%33 = icmp slt i64 %30, %32
br i1 %33, label %22, label %7
}