#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 */

/* Variables and functions */
int /*<<< orphan*/ ASN1_BIT_STRING_set_bit(void *, long, int);
int /*<<< orphan*/ ASN1_F_BITSTR_CB;
int /*<<< orphan*/ ASN1_R_INVALID_NUMBER;
int /*<<< orphan*/ ASN1err(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
long strtoul(char const *, char **, int);
int bitstr_cb(const char *elem, int len, void *bitstr) {
  long bitnum;
  char *eptr;
  if (!elem)
    return 0;
  bitnum = strtoul(elem, &eptr, 10);
  if (eptr && *eptr && (eptr != elem + len))
    return 0;
  if (bitnum < 0) {
    ASN1err(ASN1_F_BITSTR_CB, ASN1_R_INVALID_NUMBER);
    return 0;
  }
  if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) {
    ASN1err(ASN1_F_BITSTR_CB, ERR_R_MALLOC_FAILURE);
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<bitstr_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115a <bitstr_cb+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    1222 <bitstr_cb+0xf2>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11af <bitstr_cb+0x7f>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11af <bitstr_cb+0x7f>
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x14(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
je     11af <bitstr_cb+0x7f>
movl   $0x0,-0x4(%rbp)
jmp    1222 <bitstr_cb+0xf2>
cmpq   $0x0,-0x28(%rbp)
jge    11dd <bitstr_cb+0xad>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
call   1030 <ASN1err@plt>
movl   $0x0,-0x4(%rbp)
jmp    1222 <bitstr_cb+0xf2>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x1,%edx
call   1050 <ASN1_BIT_STRING_set_bit@plt>
cmp    $0x0,%eax
jne    121b <bitstr_cb+0xeb>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
call   1030 <ASN1err@plt>
movl   $0x0,-0x4(%rbp)
jmp    1222 <bitstr_cb+0xf2>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitstr_cb>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     11ad <bitstr_cb+0x7d>
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbx
mov    %rsp,%rsi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    (%rsp),%rcx
test   %rcx,%rcx
je     116d <bitstr_cb+0x3d>
cmpb   $0x0,(%rcx)
je     116d <bitstr_cb+0x3d>
movslq %r15d,%rdx
add    %rdx,%rbx
cmp    %rbx,%rcx
jne    11ad <bitstr_cb+0x7d>
test   %rax,%rax
js     1194 <bitstr_cb+0x64>
mov    $0x1,%ebp
mov    %r14,%rdi
mov    %rax,%rsi
mov    $0x1,%edx
call   1050 <ASN1_BIT_STRING_set_bit@plt>
test   %eax,%eax
jne    11ad <bitstr_cb+0x7d>
mov    0x2e46(%rip),%rax
jmp    119b <bitstr_cb+0x6b>
mov    0x2e45(%rip),%rax
mov    0x2e46(%rip),%rcx
mov    (%rcx),%edi
mov    (%rax),%esi
call   1030 <ASN1err@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ASN1_F_BITSTR_CB = global i32 0
@ASN1_R_INVALID_NUMBER = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
define i32 @bitstr_cb(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %3
store i32 0, i32* %4
br label %48
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = call i64 @strtoul(i8* %14, i8** %9, i32 10)
store i64 %15, i64* %8
%16 = load i8*, i8** %9
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %31
18: ; preds = %13
%19 = load i8*, i8** %9
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %18
%24 = load i8*, i8** %9
%25 = load i8*, i8** %5
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = icmp ne i8* %24, %28
br i1 %29, label %30, label %31
30: ; preds = %23
store i32 0, i32* %4
br label %48
31: ; preds = %23, %18, %13
%32 = load i64, i64* %8
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i32, i32* @ASN1_F_BITSTR_CB
%36 = load i32, i32* @ASN1_R_INVALID_NUMBER
%37 = call i32 @ASN1err(i32 %35, i32 %36)
store i32 0, i32* %4
br label %48
38: ; preds = %31
%39 = load i8*, i8** %7
%40 = load i64, i64* %8
%41 = call i32 @ASN1_BIT_STRING_set_bit(i8* %39, i64 %40, i32 1)
%42 = icmp ne i32 %41, 0
br i1 %42, label %47, label %43
43: ; preds = %38
%44 = load i32, i32* @ASN1_F_BITSTR_CB
%45 = load i32, i32* @ERR_R_MALLOC_FAILURE
%46 = call i32 @ASN1err(i32 %44, i32 %45)
store i32 0, i32* %4
br label %48
47: ; preds = %38
store i32 1, i32* %4
br label %48
48: ; preds = %47, %43, %34, %30, %12
%49 = load i32, i32* %4
ret i32 %49
}

LLVM IR (-O2):
@ASN1_F_BITSTR_CB = global i32 0
@ASN1_R_INVALID_NUMBER = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
define i32 @bitstr_cb(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = icmp eq i8* %0, null
br i1 %6, label %28, label %7
7: ; preds = %3
%8 = call i64 @strtoul(i8* %0, i8** %4, i32 10)
%9 = load i8*, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %18, label %11
11: ; preds = %7
%12 = load i8, i8* %9
%13 = icmp eq i8 %12, 0
%14 = sext i32 %1 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = icmp eq i8* %9, %15
%17 = select i1 %13, i1 true, i1 %16
br i1 %17, label %18, label %28
18: ; preds = %11, %7
%19 = icmp slt i64 %8, 0
br i1 %19, label %23, label %20
20: ; preds = %18
%21 = tail call i32 @ASN1_BIT_STRING_set_bit(i8* %2, i64 %8, i32 1)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %20, %18
%24 = phi i32* [ @ASN1_R_INVALID_NUMBER, %18 ], [ @ERR_R_MALLOC_FAILURE, %20 ]
%25 = load i32, i32* @ASN1_F_BITSTR_CB
%26 = load i32, i32* %24
%27 = tail call i32 @ASN1err(i32 %25, i32 %26)
br label %28
28: ; preds = %23, %20, %11, %3
%29 = phi i32 [ 0, %3 ], [ 0, %11 ], [ 1, %20 ], [ 0, %23 ]
ret i32 %29
}