#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 /*<<< orphan*/ free(char *);
int read_devattr(char const *, char **);
int read_devattr_bool(const char *attr, bool *value) {
  char *buf;
  int ret;
  ret = read_devattr(attr, &buf);
  if (ret < 0)
    return ret;
  if (buf[0] == '1' && buf[1] == '\0')
    *value = true;
  else
    *value = false;
  free(buf);
  return 0;
}


x86 assembly (clang, -O0):
<read_devattr_bool>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <read_devattr@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1155 <read_devattr_bool+0x35>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119f <read_devattr_bool+0x7f>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x31,%eax
jne    1185 <read_devattr_bool+0x65>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1185 <read_devattr_bool+0x65>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    118f <read_devattr_bool+0x6f>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_devattr_bool>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rsi
call   1030 <read_devattr@plt>
test   %eax,%eax
js     1158 <read_devattr_bool+0x38>
mov    0x8(%rsp),%rdi
cmpb   $0x31,(%rdi)
jne    1146 <read_devattr_bool+0x26>
cmpb   $0x0,0x1(%rdi)
je     114a <read_devattr_bool+0x2a>
xor    %eax,%eax
jmp    114f <read_devattr_bool+0x2f>
mov    $0x1,%eax
mov    %eax,(%rbx)
call   1040 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @read_devattr_bool(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%8 = load i8*, i8** %4
%9 = call i32 @read_devattr(i8* %8, i8** %6)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i32, i32* %7
store i32 %13, i32* %3
br label %33
14: ; preds = %2
%15 = load i8*, i8** %6
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 49
br i1 %19, label %20, label %28
20: ; preds = %14
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = load i32*, i32** %5
store i32 1, i32* %27
br label %30
28: ; preds = %20, %14
%29 = load i32*, i32** %5
store i32 0, i32* %29
br label %30
30: ; preds = %28, %26
%31 = load i8*, i8** %6
%32 = call i32 @free(i8* %31)
store i32 0, i32* %3
br label %33
33: ; preds = %30, %12
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
define i32 @read_devattr_bool(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i32 @read_devattr(i8* %0, i8** %3)
%6 = icmp slt i32 %5, 0
br i1 %6, label %19, label %7
7: ; preds = %2
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 49
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = getelementptr inbounds i8, i8* %8, i64 1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %11, %7
br label %16
16: ; preds = %11, %15
%17 = phi i32 [ 0, %15 ], [ 1, %11 ]
store i32 %17, i32* %1
%18 = call i32 @free(i8* %8)
br label %19
19: ; preds = %2, %16
%20 = phi i32 [ 0, %16 ], [ %5, %2 ]
ret i32 %20
}