#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__ atoi(char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char tolower(char);
int epk_str2bool(const char *str) {
  char strbuf[128];
  char *ptr = strbuf;
  strncpy(strbuf, str, 128);
  while (*ptr) {
    *ptr = tolower(*ptr);
    ++ptr;
  }
  if (strcmp(strbuf, "yes") == 0 || strcmp(strbuf, "true") == 0 ||
      atoi(strbuf) > 0) {
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<epk_str2bool>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x80,%edx
call   1030 <strncpy@plt>
mov    -0x98(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b3 <epk_str2bool+0x73>
mov    -0x98(%rbp),%rax
movsbl (%rax),%edi
call   1050 <tolower@plt>
mov    %al,%cl
mov    -0x98(%rbp),%rax
mov    %cl,(%rax)
mov    -0x98(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x98(%rbp)
jmp    1172 <epk_str2bool+0x32>
lea    -0x90(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1203 <epk_str2bool+0xc3>
lea    -0x90(%rbp),%rdi
lea    0xe26(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1203 <epk_str2bool+0xc3>
lea    -0x90(%rbp),%rdi
call   1060 <atoi@plt>
cmp    $0x0,%rax
jle    120f <epk_str2bool+0xcf>
movl   $0x1,-0x4(%rbp)
jmp    1216 <epk_str2bool+0xd6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<epk_str2bool>:
push   %rbx
sub    $0x80,%rsp
mov    %rdi,%rsi
mov    %rsp,%rdi
mov    $0x80,%edx
call   1030 <strncpy@plt>
mov    (%rsp),%al
test   %al,%al
je     1186 <epk_str2bool+0x46>
lea    0x1(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl %al,%edi
call   1050 <tolower@plt>
mov    %al,-0x1(%rbx)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1170 <epk_str2bool+0x30>
lea    0xe73(%rip),%rsi
mov    %rsp,%rdi
call   1040 <strcmp@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     11c3 <epk_str2bool+0x83>
lea    0xe5e(%rip),%rsi
mov    %rsp,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11c3 <epk_str2bool+0x83>
mov    %rsp,%rdi
call   1060 <atoi@plt>
xor    %ebx,%ebx
test   %rax,%rax
setg   %bl
mov    %ebx,%eax
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"yes\00"
@.str.1 = [5 x i8] c"true\00"
define i32 @epk_str2bool(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [128 x i8]
%5 = alloca i8*
store i8* %0, i8** %3
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
store i8* %6, i8** %5
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = call i32 @strncpy(i8* %7, i8* %8, i32 128)
br label %10
10: ; preds = %14, %1
%11 = load i8*, i8** %5
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %10
%15 = load i8*, i8** %5
%16 = load i8, i8* %15
%17 = call signext i8 @tolower(i8 signext %16)
%18 = load i8*, i8** %5
store i8 %17, i8* %18
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %5
br label %10
21: ; preds = %10
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %33, label %25
25: ; preds = %21
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %25
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%31 = call i64 @atoi(i8* %30)
%32 = icmp sgt i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %29, %25, %21
store i32 1, i32* %2
br label %35
34: ; preds = %29
store i32 0, i32* %2
br label %35
35: ; preds = %34, %33
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@.str = [4 x i8] c"yes\00"
@.str.1 = [5 x i8] c"true\00"
define i32 @epk_str2bool(i8* %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%4 = call i32 @strncpy(i8* %3, i8* %0, i32 128)
%5 = load i8, i8* %3
%6 = icmp eq i8 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %1, %7
%8 = phi i8 [ %12, %7 ], [ %5, %1 ]
%9 = phi i8* [ %11, %7 ], [ %3, %1 ]
%10 = call signext i8 @tolower(i8 signext %8)
store i8 %10, i8* %9
%11 = getelementptr inbounds i8, i8* %9, i64 1
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %7
14: ; preds = %7, %1
%15 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %24, label %17
17: ; preds = %14
%18 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %17
%21 = call i64 @atoi(i8* %3)
%22 = icmp sgt i64 %21, 0
%23 = zext i1 %22 to i32
br label %24
24: ; preds = %20, %14, %17
%25 = phi i32 [ 1, %17 ], [ 1, %14 ], [ %23, %20 ]
ret i32 %25
}