#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*/ SHA_CTX;
typedef int /*<<< orphan*/ BIGNUM;

/* Variables and functions */
int /*<<< orphan*/ BN_bn2bin(int /*<<< orphan*/ const *, unsigned char *);
size_t BN_num_bytes(int /*<<< orphan*/ const *);
int /*<<< orphan*/ OPENSSL_free(unsigned char *);
unsigned char *OPENSSL_malloc(size_t);
int /*<<< orphan*/ SHA1_Update(int /*<<< orphan*/ *, unsigned char *, size_t);
int /*<<< orphan*/ hashlength(int /*<<< orphan*/ *, size_t);
void hashbn(SHA_CTX *sha, const BIGNUM *bn) {
  size_t l = BN_num_bytes(bn);
  unsigned char *bin = OPENSSL_malloc(l);
  hashlength(sha, l);
  BN_bn2bin(bn, bin);
  SHA1_Update(sha, bin, l);
  OPENSSL_free(bin);
}


x86 assembly (clang, -O0):
<hashbn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <BN_num_bytes@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <OPENSSL_malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <hashlength@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <BN_bn2bin@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <SHA1_Update@plt>
mov    -0x20(%rbp),%rdi
call   1080 <OPENSSL_free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hashbn>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <BN_num_bytes@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1040 <OPENSSL_malloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r12,%rsi
call   1070 <hashlength@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <BN_bn2bin@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1030 <SHA1_Update@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1080 <OPENSSL_free@plt>

LLVM IR (-O0):
define void @hashbn(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i8*
store i32* %0, i32** %3
store i32* %1, i32** %4
%7 = load i32*, i32** %4
%8 = call i64 @BN_num_bytes(i32* %7)
store i64 %8, i64* %5
%9 = load i64, i64* %5
%10 = call i8* @OPENSSL_malloc(i64 %9)
store i8* %10, i8** %6
%11 = load i32*, i32** %3
%12 = load i64, i64* %5
%13 = call i32 @hashlength(i32* %11, i64 %12)
%14 = load i32*, i32** %4
%15 = load i8*, i8** %6
%16 = call i32 @BN_bn2bin(i32* %14, i8* %15)
%17 = load i32*, i32** %3
%18 = load i8*, i8** %6
%19 = load i64, i64* %5
%20 = call i32 @SHA1_Update(i32* %17, i8* %18, i64 %19)
%21 = load i8*, i8** %6
%22 = call i32 @OPENSSL_free(i8* %21)
ret void
}

LLVM IR (-O2):
define void @hashbn(i32* %0, i32* %1) {
%3 = tail call i64 @BN_num_bytes(i32* %1)
%4 = tail call i8* @OPENSSL_malloc(i64 %3)
%5 = tail call i32 @hashlength(i32* %0, i64 %3)
%6 = tail call i32 @BN_bn2bin(i32* %1, i8* %4)
%7 = tail call i32 @SHA1_Update(i32* %0, i8* %4, i64 %3)
%8 = tail call i32 @OPENSSL_free(i8* %4)
ret void
}