#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 */
typedef int uint;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int unpack_boolean(unsigned char **p, unsigned char *e, bool *val) {
  uint len;
  (void)unpack_boolean;
  if ((len = e - *p) != 1) {
    fprintf(stderr, "E: boolean length (%u) out of bounds\n", len);
    return (-1);
  }
  *val = (*p == 0) ? false : true;
  return (0);
}


x86 assembly (clang, -O0):
<unpack_boolean>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
mov    %eax,-0x24(%rbp)
cmp    $0x1,%eax
je     1162 <unpack_boolean+0x52>
mov    0x2e9b(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xeaf(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1184 <unpack_boolean+0x74>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    $0x1,%ecx
xor    %eax,%eax
cmp    $0x0,%rdx
cmove  %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unpack_boolean>:
push   %rax
mov    %rsi,%rax
mov    (%rdi),%rcx
sub    %ecx,%eax
cmp    $0x1,%eax
jne    112c <unpack_boolean+0x1c>
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
mov    %eax,(%rdx)
xor    %eax,%eax
pop    %rcx
ret
mov    0x2ead(%rip),%rcx
mov    (%rcx),%edi
lea    0xec4(%rip),%rsi
mov    %eax,%edx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [38 x i8] c"E: boolean length (%u) out of bounds\0A\00"
define i32 @unpack_boolean(i8** %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
store i8** %0, i8*** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%9 = load i8*, i8** %6
%10 = load i8**, i8*** %5
%11 = load i8*, i8** %10
%12 = ptrtoint i8* %9 to i64
%13 = ptrtoint i8* %11 to i64
%14 = sub i64 %12, %13
%15 = trunc i64 %14 to i32
store i32 %15, i32* %8
%16 = icmp ne i32 %15, 1
br i1 %16, label %17, label %21
17: ; preds = %3
%18 = load i32, i32* @stderr
%19 = load i32, i32* %8
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %19)
store i32 -1, i32* %4
br label %28
21: ; preds = %3
%22 = load i8**, i8*** %5
%23 = load i8*, i8** %22
%24 = icmp eq i8* %23, null
%25 = zext i1 %24 to i64
%26 = select i1 %24, i32 0, i32 1
%27 = load i32*, i32** %7
store i32 %26, i32* %27
store i32 0, i32* %4
br label %28
28: ; preds = %21, %17
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [38 x i8] c"E: boolean length (%u) out of bounds\0A\00"
define i32 @unpack_boolean(i8** nocapture %0, i8* %1, i32* nocapture writeonly %2) {
%4 = load i8*, i8** %0
%5 = ptrtoint i8* %1 to i64
%6 = ptrtoint i8* %4 to i64
%7 = sub i64 %5, %6
%8 = trunc i64 %7 to i32
%9 = icmp eq i32 %8, 1
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %16
13: ; preds = %3
%14 = icmp ne i8* %4, null
%15 = zext i1 %14 to i32
store i32 %15, i32* %2
br label %16
16: ; preds = %13, %10
%17 = phi i32 [ -1, %10 ], [ 0, %13 ]
ret i32 %17
}