#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 asn1_get_tag(unsigned char **, unsigned char *, int *, int);
int asn1_get_bool(unsigned char **p, unsigned char *end, int *val) {
  int ret, len;
  if ((ret = asn1_get_tag(p, end, &len, 0x01)) != 0)
    return (ret);
  if (len != 1)
    return (-0x0018);
  *val = (**p != 0) ? 1 : 0;
  (*p)++;
  return (0);
}


x86 assembly (clang, -O0):
<asn1_get_bool>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x28(%rbp),%rdx
mov    $0x1,%ecx
call   1030 <asn1_get_tag@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     1151 <asn1_get_bool+0x41>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1199 <asn1_get_bool+0x89>
cmpl   $0x1,-0x28(%rbp)
je     1167 <asn1_get_bool+0x57>
movl   $0xffffffe8,-0x4(%rbp)
jmp    1199 <asn1_get_bool+0x89>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movzbl (%rax),%edx
xor    %ecx,%ecx
mov    $0x1,%eax
cmp    $0x0,%edx
cmovne %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asn1_get_bool>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
lea    0x4(%rsp),%rdx
mov    $0x1,%ecx
call   1030 <asn1_get_tag@plt>
test   %eax,%eax
jne    1150 <asn1_get_bool+0x40>
mov    $0xffffffe8,%eax
cmpl   $0x1,0x4(%rsp)
jne    1150 <asn1_get_bool+0x40>
mov    (%rbx),%rax
xor    %ecx,%ecx
cmpb   $0x0,(%rax)
setne  %cl
mov    %ecx,(%r14)
add    $0x1,%rax
mov    %rax,(%rbx)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @asn1_get_bool(i8** %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i8** %0, i8*** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%10 = load i8**, i8*** %5
%11 = load i8*, i8** %6
%12 = call i32 @asn1_get_tag(i8** %10, i8* %11, i32* %9, i32 1)
store i32 %12, i32* %8
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = load i32, i32* %8
store i32 %15, i32* %4
br label %32
16: ; preds = %3
%17 = load i32, i32* %9
%18 = icmp ne i32 %17, 1
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 -24, i32* %4
br label %32
20: ; preds = %16
%21 = load i8**, i8*** %5
%22 = load i8*, i8** %21
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = icmp ne i32 %24, 0
%26 = zext i1 %25 to i64
%27 = select i1 %25, i32 1, i32 0
%28 = load i32*, i32** %7
store i32 %27, i32* %28
%29 = load i8**, i8*** %5
%30 = load i8*, i8** %29
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %29
store i32 0, i32* %4
br label %32
32: ; preds = %20, %19, %14
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
define i32 @asn1_get_bool(i8** %0, i8* %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = call i32 @asn1_get_tag(i8** %0, i8* %1, i32* %4, i32 1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %3
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = load i8*, i8** %0
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 0
%15 = zext i1 %14 to i32
store i32 %15, i32* %2
%16 = getelementptr inbounds i8, i8* %12, i64 1
store i8* %16, i8** %0
br label %17
17: ; preds = %8, %3, %11
%18 = phi i32 [ 0, %11 ], [ %6, %3 ], [ -24, %8 ]
ret i32 %18
}