#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 */
struct script_stack_element {
  int dummy;
};
typedef int /*<<< orphan*/ mpz_t;

/* Variables and functions */
scalar_t__ alloca(int);
struct script_stack_element *make_stack_element(unsigned char *, size_t);
int /*<<< orphan*/ mpz_export(unsigned char *, size_t, int, int, int,
                              int /*<<< orphan*/, int /*<<< orphan*/);
int mpz_sizeinbase(int /*<<< orphan*/, int);
struct script_stack_element *make_num(mpz_t n) {
  size_t count = (mpz_sizeinbase(n, 2) + 7) / 8;
  unsigned char *out = (unsigned char *)alloca(sizeof(unsigned char) * count);
  mpz_export(out, count, -1, 1, 1, 0, n);
  return make_stack_element(out, count);
}


x86 assembly (clang, -O0):
<make_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x2,%esi
call   1040 <mpz_sizeinbase@plt>
add    $0x7,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1030 <alloca@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x4(%rbp),%eax
mov    $0xffffffff,%edx
mov    $0x1,%r8d
xor    %r9d,%r9d
mov    %r8d,%ecx
mov    %eax,(%rsp)
call   1050 <mpz_export@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <make_stack_element@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_num>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
mov    $0x2,%esi
call   1040 <mpz_sizeinbase@plt>
lea    0x7(%rax),%ecx
add    $0xe,%eax
test   %ecx,%ecx
cmovns %ecx,%eax
sar    $0x3,%eax
movslq %eax,%rbx
mov    %ebx,%edi
call   1030 <alloca@plt>
mov    %rax,%rbp
mov    %r14d,(%rsp)
mov    %rax,%rdi
mov    %rbx,%rsi
mov    $0xffffffff,%edx
mov    $0x1,%ecx
mov    $0x1,%r8d
xor    %r9d,%r9d
call   1050 <mpz_export@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <make_stack_element@plt>

LLVM IR (-O0):
%struct.script_stack_element = type { i32 }
define %struct.script_stack_element* @make_num(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i8*
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i32 @mpz_sizeinbase(i32 %5, i32 2)
%7 = add nsw i32 %6, 7
%8 = sdiv i32 %7, 8
%9 = sext i32 %8 to i64
store i64 %9, i64* %3
%10 = load i64, i64* %3
%11 = mul i64 1, %10
%12 = trunc i64 %11 to i32
%13 = call i64 @alloca(i32 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = load i64, i64* %3
%17 = load i32, i32* %2
%18 = call i32 @mpz_export(i8* %15, i64 %16, i32 -1, i32 1, i32 1, i32 0, i32 %17)
%19 = load i8*, i8** %4
%20 = load i64, i64* %3
%21 = call %struct.script_stack_element* @make_stack_element(i8* %19, i64 %20)
ret %struct.script_stack_element* %21
}

LLVM IR (-O2):
%struct.script_stack_element = type { i32 }
define %struct.script_stack_element* @make_num(i32 %0) {
%2 = tail call i32 @mpz_sizeinbase(i32 %0, i32 2)
%3 = add nsw i32 %2, 7
%4 = sdiv i32 %3, 8
%5 = sext i32 %4 to i64
%6 = tail call i64 @alloca(i32 %4)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 @mpz_export(i8* %7, i64 %5, i32 -1, i32 1, i32 1, i32 0, i32 %0)
%9 = tail call %struct.script_stack_element* @make_stack_element(i8* %7, i64 %5)
ret %struct.script_stack_element* %9
}