#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 /*<<< orphan*/ mpz_add(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init_set_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_pow_ui(int /*<<< orphan*/, int /*<<< orphan*/,
                              unsigned int);
int /*<<< orphan*/ mpz_sub(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_urandomm(int /*<<< orphan*/, int /*<<< orphan*/,
                                int /*<<< orphan*/);
void generateOTP(gmp_randstate_t prng, mpz_t otp, unsigned int numBits) {
  mpz_t range;
  mpz_init_set_ui(range, 2);
  mpz_pow_ui(range, range, numBits + 1);
  mpz_t min;
  mpz_init_set_ui(min, 2);
  mpz_pow_ui(min, min, numBits);
  mpz_sub(range, range, min);
  mpz_init(otp);
  mpz_urandomm(otp, prng, range);
  mpz_add(otp, min, otp);
  mpz_clear(range);
  mpz_clear(min);
}


x86 assembly (clang, -O0):
<generateOTP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x10(%rbp),%edi
mov    $0x2,%esi
call   1060 <mpz_init_set_ui@plt>
mov    -0x10(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
add    $0x1,%edx
call   1070 <mpz_pow_ui@plt>
mov    -0x14(%rbp),%edi
mov    $0x2,%esi
call   1060 <mpz_init_set_ui@plt>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1070 <mpz_pow_ui@plt>
mov    -0x10(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <mpz_sub@plt>
mov    -0x8(%rbp),%edi
call   1040 <mpz_init@plt>
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1090 <mpz_urandomm@plt>
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1050 <mpz_add@plt>
mov    -0x10(%rbp),%edi
call   1080 <mpz_clear@plt>
mov    -0x14(%rbp),%edi
call   1080 <mpz_clear@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generateOTP>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebx
mov    %edi,%ebp
mov    $0x2,%esi
call   1060 <mpz_init_set_ui@plt>
lea    0x1(%r14),%edx
call   1070 <mpz_pow_ui@plt>
mov    $0x2,%esi
call   1060 <mpz_init_set_ui@plt>
mov    %r14d,%edx
call   1070 <mpz_pow_ui@plt>
call   1030 <mpz_sub@plt>
mov    %ebx,%edi
call   1040 <mpz_init@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1090 <mpz_urandomm@plt>
mov    %ebx,%edi
mov    %ebx,%edx
call   1050 <mpz_add@plt>
call   1080 <mpz_clear@plt>
pop    %rbx
pop    %r14
pop    %rbp
jmp    1080 <mpz_clear@plt>

LLVM IR (-O0):
define void @generateOTP(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %7
%10 = call i32 @mpz_init_set_ui(i32 %9, i32 2)
%11 = load i32, i32* %7
%12 = load i32, i32* %7
%13 = load i32, i32* %6
%14 = add i32 %13, 1
%15 = call i32 @mpz_pow_ui(i32 %11, i32 %12, i32 %14)
%16 = load i32, i32* %8
%17 = call i32 @mpz_init_set_ui(i32 %16, i32 2)
%18 = load i32, i32* %8
%19 = load i32, i32* %8
%20 = load i32, i32* %6
%21 = call i32 @mpz_pow_ui(i32 %18, i32 %19, i32 %20)
%22 = load i32, i32* %7
%23 = load i32, i32* %7
%24 = load i32, i32* %8
%25 = call i32 @mpz_sub(i32 %22, i32 %23, i32 %24)
%26 = load i32, i32* %5
%27 = call i32 @mpz_init(i32 %26)
%28 = load i32, i32* %5
%29 = load i32, i32* %4
%30 = load i32, i32* %7
%31 = call i32 @mpz_urandomm(i32 %28, i32 %29, i32 %30)
%32 = load i32, i32* %5
%33 = load i32, i32* %8
%34 = load i32, i32* %5
%35 = call i32 @mpz_add(i32 %32, i32 %33, i32 %34)
%36 = load i32, i32* %7
%37 = call i32 @mpz_clear(i32 %36)
%38 = load i32, i32* %8
%39 = call i32 @mpz_clear(i32 %38)
ret void
}

LLVM IR (-O2):
define void @generateOTP(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @mpz_init_set_ui(i32 undef, i32 2)
%5 = add i32 %2, 1
%6 = tail call i32 @mpz_pow_ui(i32 undef, i32 undef, i32 %5)
%7 = tail call i32 @mpz_init_set_ui(i32 undef, i32 2)
%8 = tail call i32 @mpz_pow_ui(i32 undef, i32 undef, i32 %2)
%9 = tail call i32 @mpz_sub(i32 undef, i32 undef, i32 undef)
%10 = tail call i32 @mpz_init(i32 %1)
%11 = tail call i32 @mpz_urandomm(i32 %1, i32 %0, i32 undef)
%12 = tail call i32 @mpz_add(i32 %1, i32 undef, i32 %1)
%13 = tail call i32 @mpz_clear(i32 undef)
%14 = tail call i32 @mpz_clear(i32 undef)
ret void
}