#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 at_tok_nextint(char **, int *);
int at_tok_nextbool(char **p_cur, char *p_out) {
  int ret;
  int result;
  ret = at_tok_nextint(p_cur, &result);
  if (ret < 0) {
    return -1;
  }
  if (!(result == 0 || result == 1)) {
    return -1;
  }
  if (p_out != NULL) {
    *p_out = (char)result;
  }
  return ret;
}


x86 assembly (clang, -O0):
<at_tok_nextbool>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <at_tok_nextint@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1146 <at_tok_nextbool+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    1182 <at_tok_nextbool+0x72>
cmpl   $0x0,-0x20(%rbp)
je     1166 <at_tok_nextbool+0x56>
cmpl   $0x1,-0x20(%rbp)
je     1166 <at_tok_nextbool+0x56>
movl   $0xffffffff,-0x4(%rbp)
jmp    1182 <at_tok_nextbool+0x72>
cmpq   $0x0,-0x18(%rbp)
je     117c <at_tok_nextbool+0x6c>
mov    -0x20(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<at_tok_nextbool>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0xc(%rsp),%rsi
call   1030 <at_tok_nextint@plt>
mov    $0xffffffff,%ecx
test   %eax,%eax
js     113d <at_tok_nextbool+0x2d>
mov    0xc(%rsp),%edx
cmp    $0x1,%edx
ja     113d <at_tok_nextbool+0x2d>
test   %rbx,%rbx
je     113b <at_tok_nextbool+0x2b>
mov    %dl,(%rbx)
mov    %eax,%ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @at_tok_nextbool(i8** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8** %0, i8*** %4
store i8* %1, i8** %5
%8 = load i8**, i8*** %4
%9 = call i32 @at_tok_nextint(i8** %8, i32* %7)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %29
13: ; preds = %2
%14 = load i32, i32* %7
%15 = icmp eq i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = load i32, i32* %7
%18 = icmp eq i32 %17, 1
br i1 %18, label %20, label %19
19: ; preds = %16
store i32 -1, i32* %3
br label %29
20: ; preds = %16, %13
%21 = load i8*, i8** %5
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* %7
%25 = trunc i32 %24 to i8
%26 = load i8*, i8** %5
store i8 %25, i8* %26
br label %27
27: ; preds = %23, %20
%28 = load i32, i32* %6
store i32 %28, i32* %3
br label %29
29: ; preds = %27, %19, %12
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @at_tok_nextbool(i8** %0, i8* writeonly %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @at_tok_nextint(i8** %0, i32* %3)
%6 = icmp slt i32 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %2
%8 = load i32, i32* %3
%9 = icmp ult i32 %8, 2
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = icmp eq i8* %1, null
br i1 %11, label %14, label %12
12: ; preds = %10
%13 = trunc i32 %8 to i8
store i8 %13, i8* %1
br label %14
14: ; preds = %10, %12, %7, %2
%15 = phi i32 [ -1, %2 ], [ -1, %7 ], [ %5, %12 ], [ %5, %10 ]
ret i32 %15
}