#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);
  if (bin == NULL)
    return;
  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)
cmpq   $0x0,-0x20(%rbp)
jne    119a <hashbn+0x3a>
jmp    11ce <hashbn+0x6e>
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>
test   %rax,%rax
je     11c0 <hashbn+0x60>
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>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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 i8*, i8** %6
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
br label %27
14: ; preds = %2
%15 = load i32*, i32** %3
%16 = load i64, i64* %5
%17 = call i32 @hashlength(i32* %15, i64 %16)
%18 = load i32*, i32** %4
%19 = load i8*, i8** %6
%20 = call i32 @BN_bn2bin(i32* %18, i8* %19)
%21 = load i32*, i32** %3
%22 = load i8*, i8** %6
%23 = load i64, i64* %5
%24 = call i32 @SHA1_Update(i32* %21, i8* %22, i64 %23)
%25 = load i8*, i8** %6
%26 = call i32 @OPENSSL_free(i8* %25)
br label %27
27: ; preds = %14, %13
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 = icmp eq i8* %4, null
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = tail call i32 @hashlength(i32* %0, i64 %3)
%8 = tail call i32 @BN_bn2bin(i32* %1, i8* %4)
%9 = tail call i32 @SHA1_Update(i32* %0, i8* %4, i64 %3)
%10 = tail call i32 @OPENSSL_free(i8* %4)
br label %11
11: ; preds = %2, %6
ret void
}