#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 uint8_t;

/* Variables and functions */
char *malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *);
int _parse_bool(uint8_t *data, size_t len, char **out) {
  char *buffer;
  if (len != 1)
    return 2;
  if (*data & 0xfe)
    return 3;
  buffer = malloc(6);
  if (buffer == NULL)
    return 1;
  snprintf(buffer, 6, *data ? "true" : "false");
  *out = buffer;
  return 0;
}


x86 assembly (clang, -O0):
<_parse_bool>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x1,-0x18(%rbp)
je     114b <_parse_bool+0x2b>
movl   $0x2,-0x4(%rbp)
jmp    11cb <_parse_bool+0xab>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
and    $0xfe,%eax
cmp    $0x0,%eax
je     116b <_parse_bool+0x4b>
movl   $0x3,-0x4(%rbp)
jmp    11cb <_parse_bool+0xab>
mov    $0x6,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1190 <_parse_bool+0x70>
movl   $0x1,-0x4(%rbp)
jmp    11cb <_parse_bool+0xab>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
lea    0xe64(%rip),%rdx
lea    0xe58(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
mov    $0x6,%esi
call   1030 <snprintf@plt>
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_parse_bool>:
push   %rbp
push   %r14
push   %rbx
mov    $0x2,%eax
cmp    $0x1,%rsi
jne    117e <_parse_bool+0x5e>
mov    (%rdi),%ebp
mov    $0x3,%eax
test   $0xfe,%bpl
jne    117e <_parse_bool+0x5e>
mov    %rdx,%rbx
mov    $0x6,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1179 <_parse_bool+0x59>
mov    %rax,%r14
test   %ebp,%ebp
lea    0xeab(%rip),%rax
lea    0xe9f(%rip),%rdx
cmove  %rax,%rdx
mov    %r14,%rdi
mov    $0x6,%esi
call   1030 <snprintf@plt>
mov    %r14,(%rbx)
xor    %eax,%eax
jmp    117e <_parse_bool+0x5e>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"true\00"
@.str.1 = [6 x i8] c"false\00"
define i32 @_parse_bool(i32* %0, i64 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i8**
%8 = alloca i8*
store i32* %0, i32** %5
store i64 %1, i64* %6
store i8** %2, i8*** %7
%9 = load i64, i64* %6
%10 = icmp ne i64 %9, 1
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 2, i32* %4
br label %33
12: ; preds = %3
%13 = load i32*, i32** %5
%14 = load i32, i32* %13
%15 = and i32 %14, 254
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
store i32 3, i32* %4
br label %33
18: ; preds = %12
%19 = call i8* @malloc(i32 6)
store i8* %19, i8** %8
%20 = load i8*, i8** %8
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 1, i32* %4
br label %33
23: ; preds = %18
%24 = load i8*, i8** %8
%25 = load i32*, i32** %5
%26 = load i32, i32* %25
%27 = icmp ne i32 %26, 0
%28 = zext i1 %27 to i64
%29 = select i1 %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0)
%30 = call i32 @snprintf(i8* %24, i32 6, i8* %29)
%31 = load i8*, i8** %8
%32 = load i8**, i8*** %7
store i8* %31, i8** %32
store i32 0, i32* %4
br label %33
33: ; preds = %23, %22, %17, %11
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
@.str = [5 x i8] c"true\00"
@.str.1 = [6 x i8] c"false\00"
define i32 @_parse_bool(i32* nocapture %0, i64 %1, i8** nocapture writeonly %2) {
%4 = icmp eq i64 %1, 1
br i1 %4, label %5, label %16
5: ; preds = %3
%6 = load i32, i32* %0
%7 = and i32 %6, 254
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %5
%10 = tail call dereferenceable_or_null(6) i8* @malloc(i32 6)
%11 = icmp eq i8* %10, null
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = icmp eq i32 %6, 0
%14 = select i1 %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0)
%15 = tail call i32 @snprintf(i8* %10, i32 6, i8* %14)
store i8* %10, i8** %2
br label %16
16: ; preds = %9, %5, %3, %12
%17 = phi i32 [ 0, %12 ], [ 2, %3 ], [ 3, %5 ], [ 1, %9 ]
ret i32 %17
}