#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int type;
  int length;
  scalar_t__ *data;
};
typedef int /*<<< orphan*/ BIO;
typedef TYPE_1__ ASN1_INTEGER;

/* Variables and functions */
int BIO_write(int /*<<< orphan*/ *, char *, int);
int V_ASN1_NEG;
int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a) {
  int i, n = 0;
  static const char *h = "0123456789ABCDEF";
  char buf[2];
  if (a == NULL)
    return (0);
  if (a->type & V_ASN1_NEG) {
    if (BIO_write(bp, "-", 1) != 1)
      goto err;
    n = 1;
  }
  if (a->length == 0) {
    if (BIO_write(bp, "00", 2) != 2)
      goto err;
    n += 2;
  } else {
    for (i = 0; i < a->length; i++) {
      if ((i != 0) && (i % 35 == 0)) {
        if (BIO_write(bp, "\\\n", 2) != 2)
          goto err;
        n += 2;
      }
      buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f];
      buf[1] = h[((unsigned char)a->data[i]) & 0x0f];
      if (BIO_write(bp, buf, 2) != 2)
        goto err;
      n += 2;
    }
  }
  return (n);
err:
  return (-1);
}


x86 assembly (clang, -O0):
<i2a_ASN1_INTEGER>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    113e <i2a_ASN1_INTEGER+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    12bd <i2a_ASN1_INTEGER+0x1ad>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    0x2e9d(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1180 <i2a_ASN1_INTEGER+0x70>
mov    -0x10(%rbp),%rdi
lea    0xeb0(%rip),%rsi
mov    $0x1,%edx
call   1030 <BIO_write@plt>
cmp    $0x1,%eax
je     1179 <i2a_ASN1_INTEGER+0x69>
jmp    12b6 <i2a_ASN1_INTEGER+0x1a6>
movl   $0x1,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmpl   $0x0,0x4(%rax)
jne    11bf <i2a_ASN1_INTEGER+0xaf>
mov    -0x10(%rbp),%rdi
lea    0xe7a(%rip),%rsi
mov    $0x2,%edx
call   1030 <BIO_write@plt>
cmp    $0x2,%eax
je     11b1 <i2a_ASN1_INTEGER+0xa1>
jmp    12b6 <i2a_ASN1_INTEGER+0x1a6>
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
jmp    12ab <i2a_ASN1_INTEGER+0x19b>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    0x4(%rcx),%eax
jge    12a6 <i2a_ASN1_INTEGER+0x196>
cmpl   $0x0,-0x1c(%rbp)
je     1220 <i2a_ASN1_INTEGER+0x110>
mov    -0x1c(%rbp),%eax
mov    $0x23,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1220 <i2a_ASN1_INTEGER+0x110>
mov    -0x10(%rbp),%rdi
lea    0xe17(%rip),%rsi
mov    $0x2,%edx
call   1030 <BIO_write@plt>
cmp    $0x2,%eax
je     1217 <i2a_ASN1_INTEGER+0x107>
jmp    12b6 <i2a_ASN1_INTEGER+0x1a6>
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
mov    0x2e01(%rip),%rax
mov    -0x18(%rbp),%rcx
mov    0x8(%rcx),%rcx
movslq -0x1c(%rbp),%rdx
mov    (%rcx,%rdx,8),%rcx
movzbl %cl,%ecx
sar    $0x4,%ecx
and    $0xf,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x22(%rbp)
mov    0x2dd8(%rip),%rax
mov    -0x18(%rbp),%rcx
mov    0x8(%rcx),%rcx
movslq -0x1c(%rbp),%rdx
mov    (%rcx,%rdx,8),%rcx
movzbl %cl,%ecx
and    $0xf,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x22(%rbp),%rsi
mov    $0x2,%edx
call   1030 <BIO_write@plt>
cmp    $0x2,%eax
je     128f <i2a_ASN1_INTEGER+0x17f>
jmp    12b6 <i2a_ASN1_INTEGER+0x1a6>
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c6 <i2a_ASN1_INTEGER+0xb6>
jmp    12ab <i2a_ASN1_INTEGER+0x19b>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12bd <i2a_ASN1_INTEGER+0x1ad>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2a_ASN1_INTEGER>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     1224 <i2a_ASN1_INTEGER+0x114>
mov    %rsi,%r13
mov    %rdi,%r14
mov    0x2eb7(%rip),%rax
mov    (%rax),%eax
test   %eax,(%rsi)
je     1228 <i2a_ASN1_INTEGER+0x118>
lea    0xecf(%rip),%rsi
mov    $0x1,%r12d
mov    %r14,%rdi
mov    $0x1,%edx
call   1030 <BIO_write@plt>
mov    $0xffffffff,%ebp
cmp    $0x1,%eax
jne    1266 <i2a_ASN1_INTEGER+0x156>
cmpl   $0x0,0x4(%r13)
je     1236 <i2a_ASN1_INTEGER+0x126>
jle    125c <i2a_ASN1_INTEGER+0x14c>
xor    %ebx,%ebx
lea    0xe99(%rip),%rax
lea    0xe7c(%rip),%r15
mov    %r12d,%ebp
mov    %rax,%r12
nopw   0x0(%rax,%rax,1)
test   %rbx,%rbx
je     11d2 <i2a_ASN1_INTEGER+0xc2>
mov    %ebx,%eax
mov    $0xd41d41d5,%ecx
imul   %rcx,%rax
shr    $0x20,%rax
mov    %ebx,%ecx
sub    %eax,%ecx
shr    %ecx
add    %eax,%ecx
shr    $0x5,%ecx
imul   $0xffffffdd,%ecx,%eax
add    %ebx,%eax
jne    11d2 <i2a_ASN1_INTEGER+0xc2>
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x2,%edx
call   1030 <BIO_write@plt>
cmp    $0x2,%eax
jne    1261 <i2a_ASN1_INTEGER+0x151>
add    $0x2,%ebp
mov    0x8(%r13),%rax
mov    (%rax,%rbx,8),%rax
mov    %eax,%ecx
shr    $0x4,%ecx
and    $0xf,%ecx
movzbl (%rcx,%r15,1),%ecx
mov    %cl,0x6(%rsp)
and    $0xf,%eax
movzbl (%rax,%r15,1),%eax
mov    %al,0x7(%rsp)
mov    %r14,%rdi
lea    0x6(%rsp),%rsi
mov    $0x2,%edx
call   1030 <BIO_write@plt>
cmp    $0x2,%eax
jne    1261 <i2a_ASN1_INTEGER+0x151>
add    $0x2,%ebp
add    $0x1,%rbx
movslq 0x4(%r13),%rax
cmp    %rax,%rbx
jl     1190 <i2a_ASN1_INTEGER+0x80>
jmp    1266 <i2a_ASN1_INTEGER+0x156>
xor    %ebp,%ebp
jmp    1266 <i2a_ASN1_INTEGER+0x156>
xor    %r12d,%r12d
cmpl   $0x0,0x4(%r13)
jne    116e <i2a_ASN1_INTEGER+0x5e>
lea    0xdd6(%rip),%rsi
mov    %r14,%rdi
mov    $0x2,%edx
call   1030 <BIO_write@plt>
or     $0x2,%r12d
cmp    $0x2,%eax
mov    $0xffffffff,%ebp
cmove  %r12d,%ebp
jmp    1266 <i2a_ASN1_INTEGER+0x156>
mov    %r12d,%ebp
jmp    1266 <i2a_ASN1_INTEGER+0x156>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32, i64* }
@i2a_ASN1_INTEGER.h = internal global i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i32 0, i32 0)
@.str = [17 x i8] c"0123456789ABCDEF\00"
@V_ASN1_NEG = global i32 0
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [3 x i8] c"00\00"
@.str.3 = [3 x i8] c"\\\0A\00"
define i32 @i2a_ASN1_INTEGER(i32* %0, %struct.TYPE_3__* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca %struct.TYPE_3__*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [2 x i8]
store i32* %0, i32** %4
store %struct.TYPE_3__* %1, %struct.TYPE_3__** %5
store i32 0, i32* %7
%9 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%10 = icmp eq %struct.TYPE_3__* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %107
12: ; preds = %2
%13 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%14 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = load i32, i32* @V_ASN1_NEG
%17 = and i32 %15, %16
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %12
%20 = load i32*, i32** %4
%21 = call i32 @BIO_write(i32* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%22 = icmp ne i32 %21, 1
br i1 %22, label %23, label %24
23: ; preds = %19
br label %106
24: ; preds = %19
store i32 1, i32* %7
br label %25
25: ; preds = %24, %12
%26 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%27 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %26, i32 0, i32 1
%28 = load i32, i32* %27
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %25
%31 = load i32*, i32** %4
%32 = call i32 @BIO_write(i32* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%33 = icmp ne i32 %32, 2
br i1 %33, label %34, label %35
34: ; preds = %30
br label %106
35: ; preds = %30
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 2
store i32 %37, i32* %7
br label %104
38: ; preds = %25
store i32 0, i32* %6
br label %39
39: ; preds = %100, %38
%40 = load i32, i32* %6
%41 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%42 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %41, i32 0, i32 1
%43 = load i32, i32* %42
%44 = icmp slt i32 %40, %43
br i1 %44, label %45, label %103
45: ; preds = %39
%46 = load i32, i32* %6
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %60
48: ; preds = %45
%49 = load i32, i32* %6
%50 = srem i32 %49, 35
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %60
52: ; preds = %48
%53 = load i32*, i32** %4
%54 = call i32 @BIO_write(i32* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%55 = icmp ne i32 %54, 2
br i1 %55, label %56, label %57
56: ; preds = %52
br label %106
57: ; preds = %52
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 2
store i32 %59, i32* %7
br label %60
60: ; preds = %57, %48, %45
%61 = load i8*, i8** @i2a_ASN1_INTEGER.h
%62 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%63 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %62, i32 0, i32 2
%64 = load i64*, i64** %63
%65 = load i32, i32* %6
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i64, i64* %64, i64 %66
%68 = load i64, i64* %67
%69 = trunc i64 %68 to i8
%70 = zext i8 %69 to i32
%71 = ashr i32 %70, 4
%72 = and i32 %71, 15
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %61, i64 %73
%75 = load i8, i8* %74
%76 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
store i8 %75, i8* %76
%77 = load i8*, i8** @i2a_ASN1_INTEGER.h
%78 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%79 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %78, i32 0, i32 2
%80 = load i64*, i64** %79
%81 = load i32, i32* %6
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i64, i64* %80, i64 %82
%84 = load i64, i64* %83
%85 = trunc i64 %84 to i8
%86 = zext i8 %85 to i32
%87 = and i32 %86, 15
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i8, i8* %77, i64 %88
%90 = load i8, i8* %89
%91 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 1
store i8 %90, i8* %91
%92 = load i32*, i32** %4
%93 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%94 = call i32 @BIO_write(i32* %92, i8* %93, i32 2)
%95 = icmp ne i32 %94, 2
br i1 %95, label %96, label %97
96: ; preds = %60
br label %106
97: ; preds = %60
%98 = load i32, i32* %7
%99 = add nsw i32 %98, 2
store i32 %99, i32* %7
br label %100
100: ; preds = %97
%101 = load i32, i32* %6
%102 = add nsw i32 %101, 1
store i32 %102, i32* %6
br label %39
103: ; preds = %39
br label %104
104: ; preds = %103, %35
%105 = load i32, i32* %7
store i32 %105, i32* %3
br label %107
106: ; preds = %96, %56, %34, %23
store i32 -1, i32* %3
br label %107
107: ; preds = %106, %104, %11
%108 = load i32, i32* %3
ret i32 %108
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32, i64* }
@.str = [17 x i8] c"0123456789ABCDEF\00"
@V_ASN1_NEG = global i32 0
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [3 x i8] c"00\00"
@.str.3 = [3 x i8] c"\\\0A\00"
define i32 @i2a_ASN1_INTEGER(i32* %0, %struct.TYPE_3__* %1) {
%3 = alloca [2 x i8]
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%5 = icmp eq %struct.TYPE_3__* %1, null
br i1 %5, label %63, label %6
6: ; preds = %2
%7 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
%8 = load i32, i32* %7
%9 = load i32, i32* @V_ASN1_NEG
%10 = and i32 %9, %8
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %6
%13 = tail call i32 @BIO_write(i32* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %63
15: ; preds = %12, %6
%16 = phi i32 [ 0, %6 ], [ 1, %12 ]
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 1
%18 = load i32, i32* %17
%19 = icmp eq i32 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %15
%21 = icmp sgt i32 %18, 0
br i1 %21, label %22, label %63
22: ; preds = %20
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 2
%24 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
br label %30
25: ; preds = %15
%26 = tail call i32 @BIO_write(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%27 = icmp eq i32 %26, 2
%28 = or i32 %16, 2
%29 = select i1 %27, i32 %28, i32 -1
br label %63
30: ; preds = %22, %57
%31 = phi i64 [ 0, %22 ], [ %59, %57 ]
%32 = phi i32 [ %16, %22 ], [ %58, %57 ]
%33 = icmp ne i64 %31, 0
%34 = trunc i64 %31 to i32
%35 = urem i32 %34, 35
%36 = icmp eq i32 %35, 0
%37 = and i1 %33, %36
br i1 %37, label %38, label %43
38: ; preds = %30
%39 = call i32 @BIO_write(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%40 = icmp eq i32 %39, 2
br i1 %40, label %41, label %63
41: ; preds = %38
%42 = add nsw i32 %32, 2
br label %43
43: ; preds = %41, %30
%44 = phi i32 [ %42, %41 ], [ %32, %30 ]
%45 = load i64*, i64** %23
%46 = getelementptr inbounds i64, i64* %45, i64 %31
%47 = load i64, i64* %46
%48 = lshr i64 %47, 4
%49 = and i64 %48, 15
%50 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %49
%51 = load i8, i8* %50
store i8 %51, i8* %4
%52 = and i64 %47, 15
%53 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %52
%54 = load i8, i8* %53
store i8 %54, i8* %24
%55 = call i32 @BIO_write(i32* %0, i8* %4, i32 2)
%56 = icmp eq i32 %55, 2
br i1 %56, label %57, label %63
57: ; preds = %43
%58 = add nsw i32 %44, 2
%59 = add nuw nsw i64 %31, 1
%60 = load i32, i32* %17
%61 = sext i32 %60 to i64
%62 = icmp slt i64 %59, %61
br i1 %62, label %30, label %63
63: ; preds = %57, %43, %38, %20, %25, %12, %2
%64 = phi i32 [ 0, %2 ], [ -1, %12 ], [ %29, %25 ], [ %16, %20 ], [ %58, %57 ], [ -1, %43 ], [ -1, %38 ]
ret i32 %64
}