#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 */
char getchar();
int scanf(char *, char *);
int /*<<< orphan*/ skipspaces();
scalar_t__ strncmp(char *, char *, int);
int read_str_bool(void *dest) {
  char b[4];
  skipspaces();
  if (scanf("%4c", b) == 1) {
    if (strncmp(b, "true", 4) == 0) {
      *(char *)dest = 1;
      return 0;
    } else if (strncmp(b, "fals", 4) == 0 && getchar() == 'e') {
      *(char *)dest = 0;
      return 0;
    } else {
      return 1;
    }
  } else {
    return 1;
  }
}


x86 assembly (clang, -O0):
<read_str_bool>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <skipspaces@plt>
lea    -0x14(%rbp),%rsi
lea    0xea2(%rip),%rdi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    11ef <read_str_bool+0xaf>
lea    -0x14(%rbp),%rdi
lea    0xe8d(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    119e <read_str_bool+0x5e>
mov    -0x10(%rbp),%rax
movb   $0x1,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11f6 <read_str_bool+0xb6>
lea    -0x14(%rbp),%rdi
lea    0xe60(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11e3 <read_str_bool+0xa3>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0x65,%eax
jne    11e3 <read_str_bool+0xa3>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11f6 <read_str_bool+0xb6>
movl   $0x1,-0x4(%rbp)
jmp    11f6 <read_str_bool+0xb6>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_str_bool>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <skipspaces@plt>
lea    0xea7(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    $0x1,%ebp
cmp    $0x1,%eax
jne    11bb <read_str_bool+0x7b>
lea    0xe90(%rip),%rsi
lea    0xc(%rsp),%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11b3 <read_str_bool+0x73>
lea    0xe7a(%rip),%rsi
lea    0xc(%rsp),%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11bb <read_str_bool+0x7b>
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0x65,%al
je     11b6 <read_str_bool+0x76>
jmp    11bb <read_str_bool+0x7b>
mov    $0x1,%r14b
mov    %r14b,(%rbx)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%4c\00"
@.str.1 = [5 x i8] c"true\00"
@.str.2 = [5 x i8] c"fals\00"
define i32 @read_str_bool(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [4 x i8]
store i8* %0, i8** %3
%5 = call i32 (...) @skipspaces()
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%7 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %26
9: ; preds = %1
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%11 = call i64 @strncmp(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = load i8*, i8** %3
store i8 1, i8* %14
store i32 0, i32* %2
br label %27
15: ; preds = %9
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%17 = call i64 @strncmp(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = call signext i8 (...) @getchar()
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 101
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = load i8*, i8** %3
store i8 0, i8* %24
store i32 0, i32* %2
br label %27
25: ; preds = %19, %15
store i32 1, i32* %2
br label %27
26: ; preds = %1
store i32 1, i32* %2
br label %27
27: ; preds = %26, %25, %23, %13
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@.str = [4 x i8] c"%4c\00"
@.str.1 = [5 x i8] c"true\00"
@.str.2 = [5 x i8] c"fals\00"
define i32 @read_str_bool(i8* nocapture writeonly %0) {
%2 = alloca [4 x i8]
%3 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (...) @skipspaces()
%5 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %3)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %18
7: ; preds = %1
%8 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %7
%11 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = call signext i8 (...) @getchar()
%15 = icmp eq i8 %14, 101
br i1 %15, label %16, label %18
16: ; preds = %13, %7
%17 = phi i8 [ 1, %7 ], [ 0, %13 ]
store i8 %17, i8* %0
br label %18
18: ; preds = %16, %1, %10, %13
%19 = phi i32 [ 1, %13 ], [ 1, %10 ], [ 1, %1 ], [ 0, %16 ]
ret i32 %19
}