#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;
  } else {
    return -1;
  }
  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    1193 <at_tok_nextbool+0x83>
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    1193 <at_tok_nextbool+0x83>
cmpq   $0x0,-0x18(%rbp)
je     1181 <at_tok_nextbool+0x71>
mov    -0x20(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
jmp    118d <at_tok_nextbool+0x7d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1193 <at_tok_nextbool+0x83>
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    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
js     113f <at_tok_nextbool+0x2f>
test   %rbx,%rbx
je     113f <at_tok_nextbool+0x2f>
mov    0xc(%rsp),%edx
cmp    $0x1,%edx
ja     113f <at_tok_nextbool+0x2f>
mov    %dl,(%rbx)
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 %30
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 %30
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 %28
27: ; preds = %20
store i32 -1, i32* %3
br label %30
28: ; preds = %23
%29 = load i32, i32* %6
store i32 %29, i32* %3
br label %30
30: ; preds = %28, %27, %19, %12
%31 = load i32, i32* %3
ret i32 %31
}

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 ugt i32 %8, 1
%10 = icmp eq i8* %1, null
%11 = or i1 %10, %9
br i1 %11, label %14, label %12
12: ; preds = %7
%13 = trunc i32 %8 to i8
store i8 %13, i8* %1
br label %14
14: ; preds = %7, %2, %12
%15 = phi i32 [ %5, %12 ], [ -1, %2 ], [ -1, %7 ]
ret i32 %15
}