#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 length;
  scalar_t__ *data;
};
typedef int /*<<< orphan*/ BIO;
typedef TYPE_1__ ASN1_ENUMERATED;

/* Variables and functions */
int BIO_write(int /*<<< orphan*/ *, char *, int);
int i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a) {
  int i, n = 0;
  static const char h[] = "0123456789ABCDEF";
  char buf[2];
  if (a == NULL)
    return (0);
  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_ENUMERATED>:
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_ENUMERATED+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    1277 <i2a_ASN1_ENUMERATED+0x167>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jne    117a <i2a_ASN1_ENUMERATED+0x6a>
mov    -0x10(%rbp),%rdi
lea    0xebb(%rip),%rsi
mov    $0x2,%edx
call   1030 <BIO_write@plt>
cmp    $0x2,%eax
je     116e <i2a_ASN1_ENUMERATED+0x5e>
jmp    1270 <i2a_ASN1_ENUMERATED+0x160>
movl   $0x2,-0x20(%rbp)
jmp    1265 <i2a_ASN1_ENUMERATED+0x155>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    1260 <i2a_ASN1_ENUMERATED+0x150>
cmpl   $0x0,-0x1c(%rbp)
je     11da <i2a_ASN1_ENUMERATED+0xca>
mov    -0x1c(%rbp),%eax
mov    $0x23,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11da <i2a_ASN1_ENUMERATED+0xca>
mov    -0x10(%rbp),%rdi
lea    0xe5b(%rip),%rsi
mov    $0x2,%edx
call   1030 <BIO_write@plt>
cmp    $0x2,%eax
je     11d1 <i2a_ASN1_ENUMERATED+0xc1>
jmp    1270 <i2a_ASN1_ENUMERATED+0x160>
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movzbl %al,%eax
sar    $0x4,%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0xe03(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0x22(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movzbl %al,%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0xddd(%rip),%rax
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     1249 <i2a_ASN1_ENUMERATED+0x139>
jmp    1270 <i2a_ASN1_ENUMERATED+0x160>
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1181 <i2a_ASN1_ENUMERATED+0x71>
jmp    1265 <i2a_ASN1_ENUMERATED+0x155>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1277 <i2a_ASN1_ENUMERATED+0x167>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2a_ASN1_ENUMERATED>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebx,%ebx
test   %rsi,%rsi
je     1204 <i2a_ASN1_ENUMERATED+0xf4>
mov    %rsi,%r15
mov    %rdi,%r14
cmpl   $0x0,(%rsi)
je     11e1 <i2a_ASN1_ENUMERATED+0xd1>
jle    1204 <i2a_ASN1_ENUMERATED+0xf4>
xor    %ebp,%ebp
lea    0xebc(%rip),%r12
lea    0x6(%rsp),%r13
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
test   %rbp,%rbp
je     1192 <i2a_ASN1_ENUMERATED+0x82>
mov    %ebp,%eax
mov    $0xd41d41d5,%ecx
imul   %rcx,%rax
shr    $0x20,%rax
mov    %ebp,%ecx
sub    %eax,%ecx
shr    %ecx
add    %eax,%ecx
shr    $0x5,%ecx
imul   $0xffffffdd,%ecx,%eax
add    %ebp,%eax
jne    1192 <i2a_ASN1_ENUMERATED+0x82>
mov    %r14,%rdi
lea    0xe94(%rip),%rsi
mov    $0x2,%edx
call   1030 <BIO_write@plt>
cmp    $0x2,%eax
jne    11ff <i2a_ASN1_ENUMERATED+0xef>
add    $0x2,%ebx
mov    0x8(%r15),%rax
mov    (%rax,%rbp,8),%rax
mov    %eax,%ecx
shr    $0x4,%ecx
and    $0xf,%ecx
movzbl (%rcx,%r12,1),%ecx
mov    %cl,0x6(%rsp)
and    $0xf,%eax
movzbl (%rax,%r12,1),%eax
mov    %al,0x7(%rsp)
mov    %r14,%rdi
mov    %r13,%rsi
mov    $0x2,%edx
call   1030 <BIO_write@plt>
cmp    $0x2,%eax
jne    11ff <i2a_ASN1_ENUMERATED+0xef>
add    $0x2,%ebx
add    $0x1,%rbp
movslq (%r15),%rax
cmp    %rax,%rbp
jl     1150 <i2a_ASN1_ENUMERATED+0x40>
jmp    1204 <i2a_ASN1_ENUMERATED+0xf4>
lea    0xe29(%rip),%rsi
mov    $0x2,%ebx
mov    %r14,%rdi
mov    $0x2,%edx
call   1030 <BIO_write@plt>
cmp    $0x2,%eax
je     1204 <i2a_ASN1_ENUMERATED+0xf4>
mov    $0xffffffff,%ebx
mov    %ebx,%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, i64* }
@i2a_ASN1_ENUMERATED.h = internal constant [17 x i8] c"0123456789ABCDEF\00"
@.str = [3 x i8] c"00\00"
@.str.1 = [3 x i8] c"\\\0A\00"
define i32 @i2a_ASN1_ENUMERATED(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 %90
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 = icmp eq i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %12
%18 = load i32*, i32** %4
%19 = call i32 @BIO_write(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%20 = icmp ne i32 %19, 2
br i1 %20, label %21, label %22
21: ; preds = %17
br label %89
22: ; preds = %17
store i32 2, i32* %7
br label %87
23: ; preds = %12
store i32 0, i32* %6
br label %24
24: ; preds = %83, %23
%25 = load i32, i32* %6
%26 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%27 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = icmp slt i32 %25, %28
br i1 %29, label %30, label %86
30: ; preds = %24
%31 = load i32, i32* %6
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %45
33: ; preds = %30
%34 = load i32, i32* %6
%35 = srem i32 %34, 35
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %45
37: ; preds = %33
%38 = load i32*, i32** %4
%39 = call i32 @BIO_write(i32* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%40 = icmp ne i32 %39, 2
br i1 %40, label %41, label %42
41: ; preds = %37
br label %89
42: ; preds = %37
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 2
store i32 %44, i32* %7
br label %45
45: ; preds = %42, %33, %30
%46 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%47 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %46, i32 0, i32 1
%48 = load i64*, i64** %47
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i64, i64* %48, i64 %50
%52 = load i64, i64* %51
%53 = trunc i64 %52 to i8
%54 = zext i8 %53 to i32
%55 = ashr i32 %54, 4
%56 = and i32 %55, 15
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [17 x i8], [17 x i8]* @i2a_ASN1_ENUMERATED.h, i64 0, i64 %57
%59 = load i8, i8* %58
%60 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
store i8 %59, i8* %60
%61 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%62 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %61, i32 0, i32 1
%63 = load i64*, i64** %62
%64 = load i32, i32* %6
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i64, i64* %63, i64 %65
%67 = load i64, i64* %66
%68 = trunc i64 %67 to i8
%69 = zext i8 %68 to i32
%70 = and i32 %69, 15
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [17 x i8], [17 x i8]* @i2a_ASN1_ENUMERATED.h, i64 0, i64 %71
%73 = load i8, i8* %72
%74 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 1
store i8 %73, i8* %74
%75 = load i32*, i32** %4
%76 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%77 = call i32 @BIO_write(i32* %75, i8* %76, i32 2)
%78 = icmp ne i32 %77, 2
br i1 %78, label %79, label %80
79: ; preds = %45
br label %89
80: ; preds = %45
%81 = load i32, i32* %7
%82 = add nsw i32 %81, 2
store i32 %82, i32* %7
br label %83
83: ; preds = %80
%84 = load i32, i32* %6
%85 = add nsw i32 %84, 1
store i32 %85, i32* %6
br label %24
86: ; preds = %24
br label %87
87: ; preds = %86, %22
%88 = load i32, i32* %7
store i32 %88, i32* %3
br label %90
89: ; preds = %79, %41, %21
store i32 -1, i32* %3
br label %90
90: ; preds = %89, %87, %11
%91 = load i32, i32* %3
ret i32 %91
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i64* }
@i2a_ASN1_ENUMERATED.h = internal unnamed_addr constant [17 x i8] c"0123456789ABCDEF\00"
@.str = [3 x i8] c"00\00"
@.str.1 = [3 x i8] c"\\\0A\00"
define i32 @i2a_ASN1_ENUMERATED(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 %52, 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 = icmp eq i32 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %6
%11 = icmp sgt i32 %8, 0
br i1 %11, label %12, label %52
12: ; preds = %10
%13 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 1
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
br label %18
15: ; preds = %6
%16 = tail call i32 @BIO_write(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%17 = icmp eq i32 %16, 2
br i1 %17, label %52, label %51
18: ; preds = %12, %45
%19 = phi i64 [ 0, %12 ], [ %47, %45 ]
%20 = phi i32 [ 0, %12 ], [ %46, %45 ]
%21 = icmp ne i64 %19, 0
%22 = trunc i64 %19 to i32
%23 = urem i32 %22, 35
%24 = icmp eq i32 %23, 0
%25 = and i1 %21, %24
br i1 %25, label %26, label %31
26: ; preds = %18
%27 = call i32 @BIO_write(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%28 = icmp eq i32 %27, 2
br i1 %28, label %29, label %51
29: ; preds = %26
%30 = add nsw i32 %20, 2
br label %31
31: ; preds = %29, %18
%32 = phi i32 [ %30, %29 ], [ %20, %18 ]
%33 = load i64*, i64** %13
%34 = getelementptr inbounds i64, i64* %33, i64 %19
%35 = load i64, i64* %34
%36 = lshr i64 %35, 4
%37 = and i64 %36, 15
%38 = getelementptr inbounds [17 x i8], [17 x i8]* @i2a_ASN1_ENUMERATED.h, i64 0, i64 %37
%39 = load i8, i8* %38
store i8 %39, i8* %4
%40 = and i64 %35, 15
%41 = getelementptr inbounds [17 x i8], [17 x i8]* @i2a_ASN1_ENUMERATED.h, i64 0, i64 %40
%42 = load i8, i8* %41
store i8 %42, i8* %14
%43 = call i32 @BIO_write(i32* %0, i8* %4, i32 2)
%44 = icmp eq i32 %43, 2
br i1 %44, label %45, label %51
45: ; preds = %31
%46 = add nsw i32 %32, 2
%47 = add nuw nsw i64 %19, 1
%48 = load i32, i32* %7
%49 = sext i32 %48 to i64
%50 = icmp slt i64 %47, %49
br i1 %50, label %18, label %52
51: ; preds = %31, %26, %15
br label %52
52: ; preds = %45, %10, %15, %2, %51
%53 = phi i32 [ -1, %51 ], [ 0, %2 ], [ 2, %15 ], [ 0, %10 ], [ %46, %45 ]
ret i32 %53
}