#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 */
scalar_t__ strcmp(char *, char *);
int read_str_bool(char *buf, void *dest) {
  if (strcmp(buf, "true") == 0) {
    *(char *)dest = 1;
    return 0;
  } else if (strcmp(buf, "false") == 0) {
    *(char *)dest = 0;
    return 0;
  } else {
    return 1;
  }
}


x86 assembly (clang, -O0):
<read_str_bool>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xed5(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    114d <read_str_bool+0x3d>
mov    -0x18(%rbp),%rax
movb   $0x1,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1181 <read_str_bool+0x71>
mov    -0x10(%rbp),%rdi
lea    0xead(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    117a <read_str_bool+0x6a>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1181 <read_str_bool+0x71>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_str_bool>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xedf(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     114b <read_str_bool+0x3b>
lea    0xed3(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    1152 <read_str_bool+0x42>
xor    %eax,%eax
jmp    114d <read_str_bool+0x3d>
mov    $0x1,%al
mov    %al,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"true\00"
@.str.1 = [6 x i8] c"false\00"
define i32 @read_str_bool(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %4
%7 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = load i8*, i8** %5
store i8 1, i8* %10
store i32 0, i32* %3
br label %18
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = load i8*, i8** %5
store i8 0, i8* %16
store i32 0, i32* %3
br label %18
17: ; preds = %11
store i32 1, i32* %3
br label %18
18: ; preds = %17, %15, %9
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
@.str = [5 x i8] c"true\00"
@.str.1 = [6 x i8] c"false\00"
define i32 @read_str_bool(i8* %0, i8* nocapture writeonly %1) {
%3 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5, %2
%9 = phi i8 [ 1, %2 ], [ 0, %5 ]
store i8 %9, i8* %1
br label %10
10: ; preds = %8, %5
%11 = phi i32 [ 1, %5 ], [ 0, %8 ]
ret i32 %11
}