#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_R_INVALID_NUMBER;
int /*<<< orphan*/ ASN1error(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) {
    ASN1error(ASN1_R_INVALID_NUMBER);
    return 0;
  }
  if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) {
    ASN1error(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    1210 <bitstr_cb+0xe0>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1030 <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    1210 <bitstr_cb+0xe0>
cmpq   $0x0,-0x28(%rbp)
jge    11d4 <bitstr_cb+0xa4>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1050 <ASN1error@plt>
movl   $0x0,-0x4(%rbp)
jmp    1210 <bitstr_cb+0xe0>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x1,%edx
call   1040 <ASN1_BIT_STRING_set_bit@plt>
cmp    $0x0,%eax
jne    1209 <bitstr_cb+0xd9>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
call   1050 <ASN1error@plt>
movl   $0x0,-0x4(%rbp)
jmp    1210 <bitstr_cb+0xe0>
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     11a4 <bitstr_cb+0x74>
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbx
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <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    11a4 <bitstr_cb+0x74>
test   %rax,%rax
js     1194 <bitstr_cb+0x64>
mov    $0x1,%ebp
mov    %r14,%rdi
mov    %rax,%rsi
mov    $0x1,%edx
call   1040 <ASN1_BIT_STRING_set_bit@plt>
test   %eax,%eax
jne    11a4 <bitstr_cb+0x74>
mov    0x2e4e(%rip),%rax
jmp    119b <bitstr_cb+0x6b>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1050 <ASN1error@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@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 %46
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 %46
31: ; preds = %23, %18, %13
%32 = load i64, i64* %8
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i32, i32* @ASN1_R_INVALID_NUMBER
%36 = call i32 @ASN1error(i32 %35)
store i32 0, i32* %4
br label %46
37: ; preds = %31
%38 = load i8*, i8** %7
%39 = load i64, i64* %8
%40 = call i32 @ASN1_BIT_STRING_set_bit(i8* %38, i64 %39, i32 1)
%41 = icmp ne i32 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %37
%43 = load i32, i32* @ERR_R_MALLOC_FAILURE
%44 = call i32 @ASN1error(i32 %43)
store i32 0, i32* %4
br label %46
45: ; preds = %37
store i32 1, i32* %4
br label %46
46: ; preds = %45, %42, %34, %30, %12
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
@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 %27, 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 %27
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 %27
23: ; preds = %20, %18
%24 = phi i32* [ @ASN1_R_INVALID_NUMBER, %18 ], [ @ERR_R_MALLOC_FAILURE, %20 ]
%25 = load i32, i32* %24
%26 = tail call i32 @ASN1error(i32 %25)
br label %27
27: ; preds = %23, %20, %11, %3
%28 = phi i32 [ 0, %3 ], [ 0, %11 ], [ 1, %20 ], [ 0, %23 ]
ret i32 %28
}