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

/* Variables and functions */
int BN_bn2bin(int /*<<< orphan*/ *, unsigned char *);
int BN_num_bits(int /*<<< orphan*/ *);
int BN_num_bytes(int /*<<< orphan*/ *);
int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype,
           const ASN1_ITEM *it) {
  BIGNUM *bn;
  int pad, len;
  if (*pval == NULL)
    return -1;
  bn = (BIGNUM *)*pval;
  if (BN_num_bits(bn) & 0x7)
    pad = 0;
  else
    pad = 1;
  if (cont) {
    if (pad)
      *cont++ = 0;
    len = BN_bn2bin(bn, cont);
  } else
    len = BN_num_bytes(bn);
  return pad + len;
}


x86 assembly (clang, -O0):
<bn_i2c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1162 <bn_i2c+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e6 <bn_i2c+0xb6>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <BN_num_bits@plt>
and    $0x7,%eax
cmp    $0x0,%eax
je     118e <bn_i2c+0x5e>
movl   $0x0,-0x34(%rbp)
jmp    1195 <bn_i2c+0x65>
movl   $0x1,-0x34(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d1 <bn_i2c+0xa1>
cmpl   $0x0,-0x34(%rbp)
je     11bc <bn_i2c+0x8c>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <BN_bn2bin@plt>
mov    %eax,-0x38(%rbp)
jmp    11dd <bn_i2c+0xad>
mov    -0x30(%rbp),%rdi
call   1040 <BN_num_bytes@plt>
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bn_i2c>:
push   %rbp
push   %r14
push   %rbx
mov    (%rdi),%rbx
test   %rbx,%rbx
je     116d <bn_i2c+0x3d>
mov    %rsi,%r14
mov    %rbx,%rdi
call   1030 <BN_num_bits@plt>
xor    %ebp,%ebp
test   $0x7,%al
sete   %bpl
test   %r14,%r14
je     1174 <bn_i2c+0x44>
test   $0x7,%al
jne    1160 <bn_i2c+0x30>
movb   $0x0,(%r14)
add    $0x1,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <BN_bn2bin@plt>
jmp    117c <bn_i2c+0x4c>
mov    $0xffffffff,%eax
jmp    117e <bn_i2c+0x4e>
mov    %rbx,%rdi
call   1040 <BN_num_bytes@plt>
add    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bn_i2c(i32** %0, i8* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32**
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
store i32** %0, i32*** %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%13 = load i32**, i32*** %6
%14 = load i32*, i32** %13
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 -1, i32* %5
br label %46
17: ; preds = %4
%18 = load i32**, i32*** %6
%19 = load i32*, i32** %18
store i32* %19, i32** %10
%20 = load i32*, i32** %10
%21 = call i32 @BN_num_bits(i32* %20)
%22 = and i32 %21, 7
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %17
store i32 0, i32* %11
br label %26
25: ; preds = %17
store i32 1, i32* %11
br label %26
26: ; preds = %25, %24
%27 = load i8*, i8** %7
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %39
29: ; preds = %26
%30 = load i32, i32* %11
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i8*, i8** %7
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %7
store i8 0, i8* %33
br label %35
35: ; preds = %32, %29
%36 = load i32*, i32** %10
%37 = load i8*, i8** %7
%38 = call i32 @BN_bn2bin(i32* %36, i8* %37)
store i32 %38, i32* %12
br label %42
39: ; preds = %26
%40 = load i32*, i32** %10
%41 = call i32 @BN_num_bytes(i32* %40)
store i32 %41, i32* %12
br label %42
42: ; preds = %39, %35
%43 = load i32, i32* %11
%44 = load i32, i32* %12
%45 = add nsw i32 %43, %44
store i32 %45, i32* %5
br label %46
46: ; preds = %42, %16
%47 = load i32, i32* %5
ret i32 %47
}

LLVM IR (-O2):
define i32 @bn_i2c(i32** nocapture %0, i8* %1, i32* nocapture readnone %2, i32* nocapture readnone %3) {
%5 = load i32*, i32** %0
%6 = icmp eq i32* %5, null
br i1 %6, label %24, label %7
7: ; preds = %4
%8 = tail call i32 @BN_num_bits(i32* %5)
%9 = and i32 %8, 7
%10 = icmp eq i32 %9, 0
%11 = zext i1 %10 to i32
%12 = icmp eq i8* %1, null
br i1 %12, label %19, label %13
13: ; preds = %7
br i1 %10, label %14, label %16
14: ; preds = %13
%15 = getelementptr inbounds i8, i8* %1, i64 1
store i8 0, i8* %1
br label %16
16: ; preds = %14, %13
%17 = phi i8* [ %15, %14 ], [ %1, %13 ]
%18 = tail call i32 @BN_bn2bin(i32* %5, i8* %17)
br label %21
19: ; preds = %7
%20 = tail call i32 @BN_num_bytes(i32* %5)
br label %21
21: ; preds = %19, %16
%22 = phi i32 [ %18, %16 ], [ %20, %19 ]
%23 = add nsw i32 %22, %11
br label %24
24: ; preds = %4, %21
%25 = phi i32 [ %23, %21 ], [ -1, %4 ]
ret i32 %25
}