#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 flags;
  int length;
  unsigned char *data;
};
typedef TYPE_1__ ASN1_BIT_STRING;

/* Variables and functions */
int ASN1_STRING_FLAG_BITS_LEFT;
int /*<<< orphan*/ ASN1error(int /*<<< orphan*/);
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
unsigned char *recallocarray(unsigned char *, int, int, int);
int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value) {
  int w, v, iv;
  unsigned char *c;
  w = n / 8;
  v = 1 << (7 - (n & 0x07));
  iv = ~v;
  if (!value)
    v = 0;
  if (a == NULL)
    return 0;
  a->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
  if ((a->length < (w + 1)) || (a->data == NULL)) {
    if (!value)
      return (1);
    if ((c = recallocarray(a->data, a->length, w + 1, 1)) == NULL) {
      ASN1error(ERR_R_MALLOC_FAILURE);
      return 0;
    }
    if (w + 1 - a->length > 0)
      memset(c + a->length, 0, w + 1 - a->length);
    a->data = c;
    a->length = w + 1;
  }
  a->data[w] = ((a->data[w]) & iv) | v;
  while ((a->length > 0) && (a->data[a->length - 1] == 0))
    a->length--;
  return (1);
}


x86 assembly (clang, -O0):
<ASN1_BIT_STRING_set_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
and    $0x7,%eax
mov    $0x7,%ecx
sub    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
xor    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1181 <ASN1_BIT_STRING_set_bit+0x51>
movl   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1198 <ASN1_BIT_STRING_set_bit+0x68>
movl   $0x0,-0x4(%rbp)
jmp    1307 <ASN1_BIT_STRING_set_bit+0x1d7>
mov    0x2e51(%rip),%rax
mov    (%rax),%ecx
or     $0x7,%ecx
xor    $0xffffffff,%ecx
mov    -0x10(%rbp),%rax
and    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jl     11d3 <ASN1_BIT_STRING_set_bit+0xa3>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    1282 <ASN1_BIT_STRING_set_bit+0x152>
cmpl   $0x0,-0x18(%rbp)
jne    11e9 <ASN1_BIT_STRING_set_bit+0xb9>
movl   $0x1,-0x4(%rbp)
jmp    1307 <ASN1_BIT_STRING_set_bit+0x1d7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
mov    $0x1,%ecx
call   1030 <recallocarray@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1230 <ASN1_BIT_STRING_set_bit+0x100>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
call   1050 <ASN1error@plt>
movl   $0x0,-0x4(%rbp)
jmp    1307 <ASN1_BIT_STRING_set_bit+0x1d7>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    -0x10(%rbp),%rcx
sub    0x4(%rcx),%eax
cmp    $0x0,%eax
jle    1269 <ASN1_BIT_STRING_set_bit+0x139>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq 0x4(%rax),%rax
add    %rax,%rdi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
mov    -0x10(%rbp),%rax
sub    0x4(%rax),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    -0x24(%rbp),%eax
or     -0x20(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmpl   $0x0,0x4(%rcx)
mov    %al,-0x31(%rbp)
jle    12de <ASN1_BIT_STRING_set_bit+0x1ae>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x10(%rbp),%rcx
mov    0x4(%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
sete   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    12ee <ASN1_BIT_STRING_set_bit+0x1be>
jmp    1300 <ASN1_BIT_STRING_set_bit+0x1d0>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,0x4(%rax)
jmp    12a9 <ASN1_BIT_STRING_set_bit+0x179>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASN1_BIT_STRING_set_bit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ecx
lea    0x7(%rcx),%r13d
test   %esi,%esi
cmovns %esi,%r13d
not    %cl
and    $0x7,%cl
mov    $0x1,%ebp
shl    %cl,%ebp
mov    $0xfffffffe,%r15d
rol    %cl,%r15d
test   %edx,%edx
cmove  %edx,%ebp
xor    %r14d,%r14d
test   %rdi,%rdi
je     1247 <ASN1_BIT_STRING_set_bit+0x117>
mov    %rdi,%rbx
sar    $0x3,%r13d
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
not    %eax
and    (%rdi),%eax
and    $0xfffffff8,%eax
mov    %eax,(%rdi)
mov    0x4(%rdi),%esi
cmp    %r13d,%esi
jle    1197 <ASN1_BIT_STRING_set_bit+0x67>
mov    0x8(%rbx),%r12
test   %r12,%r12
jne    11e2 <ASN1_BIT_STRING_set_bit+0xb2>
test   %edx,%edx
je     1231 <ASN1_BIT_STRING_set_bit+0x101>
lea    0x1(%r13),%edx
mov    0x8(%rbx),%rdi
mov    %edx,0x4(%rsp)
mov    $0x1,%ecx
call   1030 <recallocarray@plt>
test   %rax,%rax
je     1239 <ASN1_BIT_STRING_set_bit+0x109>
mov    %rax,%r12
movslq 0x4(%rbx),%rax
mov    0x4(%rsp),%r14d
mov    %r14d,%edx
sub    %eax,%edx
jle    11da <ASN1_BIT_STRING_set_bit+0xaa>
mov    %r12,%rdi
add    %rax,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %r12,0x8(%rbx)
mov    %r14d,0x4(%rbx)
movslq %r13d,%rax
movzbl (%r12,%rax,1),%ecx
and    %r15d,%ecx
or     %ebp,%ecx
mov    %cl,(%r12,%rax,1)
mov    0x4(%rbx),%eax
mov    $0x1,%r14d
test   %eax,%eax
jle    1247 <ASN1_BIT_STRING_set_bit+0x117>
mov    0x8(%rbx),%rcx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    -0x1(%rax),%rdx
mov    %edx,%esi
cmpb   $0x0,(%rcx,%rsi,1)
jne    1247 <ASN1_BIT_STRING_set_bit+0x117>
add    $0xffffffff,%eax
mov    %eax,0x4(%rbx)
lea    0x1(%rdx),%rsi
mov    %rdx,%rax
cmp    $0x1,%rsi
ja     1210 <ASN1_BIT_STRING_set_bit+0xe0>
jmp    1247 <ASN1_BIT_STRING_set_bit+0x117>
mov    $0x1,%r14d
jmp    1247 <ASN1_BIT_STRING_set_bit+0x117>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
call   1050 <ASN1error@plt>
mov    %r14d,%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, i8* }
@ASN1_STRING_FLAG_BITS_LEFT = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
define i32 @ASN1_BIT_STRING_set_bit(%struct.TYPE_3__* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.TYPE_3__*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store %struct.TYPE_3__* %0, %struct.TYPE_3__** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%12 = load i32, i32* %6
%13 = sdiv i32 %12, 8
store i32 %13, i32* %8
%14 = load i32, i32* %6
%15 = and i32 %14, 7
%16 = sub nsw i32 7, %15
%17 = shl i32 1, %16
store i32 %17, i32* %9
%18 = load i32, i32* %9
%19 = xor i32 %18, -1
store i32 %19, i32* %10
%20 = load i32, i32* %7
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %3
store i32 0, i32* %9
br label %23
23: ; preds = %22, %3
%24 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%25 = icmp eq %struct.TYPE_3__* %24, null
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 0, i32* %4
br label %140
27: ; preds = %23
%28 = load i32, i32* @ASN1_STRING_FLAG_BITS_LEFT
%29 = or i32 %28, 7
%30 = xor i32 %29, -1
%31 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%32 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = and i32 %33, %30
store i32 %34, i32* %32
%35 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%36 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %35, i32 0, i32 1
%37 = load i32, i32* %36
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
%40 = icmp slt i32 %37, %39
br i1 %40, label %46, label %41
41: ; preds = %27
%42 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%43 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %42, i32 0, i32 2
%44 = load i8*, i8** %43
%45 = icmp eq i8* %44, null
br i1 %45, label %46, label %94
46: ; preds = %41, %27
%47 = load i32, i32* %7
%48 = icmp ne i32 %47, 0
br i1 %48, label %50, label %49
49: ; preds = %46
store i32 1, i32* %4
br label %140
50: ; preds = %46
%51 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%52 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %51, i32 0, i32 2
%53 = load i8*, i8** %52
%54 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%55 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %54, i32 0, i32 1
%56 = load i32, i32* %55
%57 = load i32, i32* %8
%58 = add nsw i32 %57, 1
%59 = call i8* @recallocarray(i8* %53, i32 %56, i32 %58, i32 1)
store i8* %59, i8** %11
%60 = icmp eq i8* %59, null
br i1 %60, label %61, label %64
61: ; preds = %50
%62 = load i32, i32* @ERR_R_MALLOC_FAILURE
%63 = call i32 @ASN1error(i32 %62)
store i32 0, i32* %4
br label %140
64: ; preds = %50
%65 = load i32, i32* %8
%66 = add nsw i32 %65, 1
%67 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%68 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %67, i32 0, i32 1
%69 = load i32, i32* %68
%70 = sub nsw i32 %66, %69
%71 = icmp sgt i32 %70, 0
br i1 %71, label %72, label %86
72: ; preds = %64
%73 = load i8*, i8** %11
%74 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%75 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %74, i32 0, i32 1
%76 = load i32, i32* %75
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %73, i64 %77
%79 = load i32, i32* %8
%80 = add nsw i32 %79, 1
%81 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%82 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %81, i32 0, i32 1
%83 = load i32, i32* %82
%84 = sub nsw i32 %80, %83
%85 = call i32 @memset(i8* %78, i32 0, i32 %84)
br label %86
86: ; preds = %72, %64
%87 = load i8*, i8** %11
%88 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%89 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %88, i32 0, i32 2
store i8* %87, i8** %89
%90 = load i32, i32* %8
%91 = add nsw i32 %90, 1
%92 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%93 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %92, i32 0, i32 1
store i32 %91, i32* %93
br label %94
94: ; preds = %86, %41
%95 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%96 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %95, i32 0, i32 2
%97 = load i8*, i8** %96
%98 = load i32, i32* %8
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds i8, i8* %97, i64 %99
%101 = load i8, i8* %100
%102 = zext i8 %101 to i32
%103 = load i32, i32* %10
%104 = and i32 %102, %103
%105 = load i32, i32* %9
%106 = or i32 %104, %105
%107 = trunc i32 %106 to i8
%108 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%109 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %108, i32 0, i32 2
%110 = load i8*, i8** %109
%111 = load i32, i32* %8
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds i8, i8* %110, i64 %112
store i8 %107, i8* %113
br label %114
114: ; preds = %134, %94
%115 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%116 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %115, i32 0, i32 1
%117 = load i32, i32* %116
%118 = icmp sgt i32 %117, 0
br i1 %118, label %119, label %132
119: ; preds = %114
%120 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%121 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %120, i32 0, i32 2
%122 = load i8*, i8** %121
%123 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%124 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %123, i32 0, i32 1
%125 = load i32, i32* %124
%126 = sub nsw i32 %125, 1
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds i8, i8* %122, i64 %127
%129 = load i8, i8* %128
%130 = zext i8 %129 to i32
%131 = icmp eq i32 %130, 0
br label %132
132: ; preds = %119, %114
%133 = phi i1 [ false, %114 ], [ %131, %119 ]
br i1 %133, label %134, label %139
134: ; preds = %132
%135 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%136 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %135, i32 0, i32 1
%137 = load i32, i32* %136
%138 = add nsw i32 %137, -1
store i32 %138, i32* %136
br label %114
139: ; preds = %132
store i32 1, i32* %4
br label %140
140: ; preds = %139, %61, %49, %26
%141 = load i32, i32* %4
ret i32 %141
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32, i8* }
@ASN1_STRING_FLAG_BITS_LEFT = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
define i32 @ASN1_BIT_STRING_set_bit(%struct.TYPE_3__* %0, i32 %1, i32 %2) {
%4 = sdiv i32 %1, 8
%5 = and i32 %1, 7
%6 = xor i32 %5, 7
%7 = shl nuw i32 1, %6
%8 = xor i32 %7, -1
%9 = icmp eq i32 %2, 0
%10 = select i1 %9, i32 0, i32 %7
%11 = icmp eq %struct.TYPE_3__* %0, null
br i1 %11, label %70, label %12
12: ; preds = %3
%13 = load i32, i32* @ASN1_STRING_FLAG_BITS_LEFT
%14 = or i32 %13, 7
%15 = xor i32 %14, -1
%16 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 0
%17 = load i32, i32* %16
%18 = and i32 %17, %15
store i32 %18, i32* %16
%19 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 1
%20 = load i32, i32* %19
%21 = add nsw i32 %4, 1
%22 = icmp sgt i32 %20, %4
br i1 %22, label %23, label %27
23: ; preds = %12
%24 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 2
%25 = load i8*, i8** %24
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %45
27: ; preds = %23, %12
br i1 %9, label %70, label %28
28: ; preds = %27
%29 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 2
%30 = load i8*, i8** %29
%31 = tail call i8* @recallocarray(i8* %30, i32 %20, i32 %21, i32 1)
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = load i32, i32* @ERR_R_MALLOC_FAILURE
%35 = tail call i32 @ASN1error(i32 %34)
br label %70
36: ; preds = %28
%37 = load i32, i32* %19
%38 = sub nsw i32 %21, %37
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = sext i32 %37 to i64
%42 = getelementptr inbounds i8, i8* %31, i64 %41
%43 = tail call i32 @memset(i8* %42, i32 0, i32 %38)
br label %44
44: ; preds = %40, %36
store i8* %31, i8** %29
store i32 %21, i32* %19
br label %45
45: ; preds = %44, %23
%46 = phi i8* [ %31, %44 ], [ %25, %23 ]
%47 = sext i32 %4 to i64
%48 = getelementptr inbounds i8, i8* %46, i64 %47
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = and i32 %50, %8
%52 = or i32 %51, %10
%53 = trunc i32 %52 to i8
store i8 %53, i8* %48
%54 = load i32, i32* %19
%55 = icmp sgt i32 %54, 0
br i1 %55, label %56, label %70
56: ; preds = %45
%57 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 2
%58 = load i8*, i8** %57
%59 = zext i32 %54 to i64
br label %60
60: ; preds = %56, %67
%61 = phi i64 [ %59, %56 ], [ %62, %67 ]
%62 = add nsw i64 %61, -1
%63 = and i64 %62, 4294967295
%64 = getelementptr inbounds i8, i8* %58, i64 %63
%65 = load i8, i8* %64
%66 = icmp eq i8 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %60
%68 = trunc i64 %62 to i32
store i32 %68, i32* %19
%69 = icmp ugt i64 %61, 1
br i1 %69, label %60, label %70
70: ; preds = %67, %60, %45, %27, %3, %33
%71 = phi i32 [ 0, %33 ], [ 0, %3 ], [ 1, %27 ], [ 1, %45 ], [ 1, %60 ], [ 1, %67 ]
ret i32 %71
}