#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*/ assert(int /*<<< orphan*/);
int strtol(char const *, char **, int);
int log_level_from_str(const char *str) {
  assert(str != NULL);
  char *end;
  int level = strtol(str, &end, 10);
  if (*end != '\0' || !((level) >= 0 && (level) <= 3)) {
    return -1;
  } else {
    return level;
  }
}


x86 assembly (clang, -O0):
<log_level_from_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1177 <log_level_from_str+0x57>
cmpl   $0x0,-0x1c(%rbp)
jl     1177 <log_level_from_str+0x57>
cmpl   $0x3,-0x1c(%rbp)
jle    1183 <log_level_from_str+0x63>
movl   $0xffffffff,-0x4(%rbp)
jmp    1189 <log_level_from_str+0x69>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_level_from_str>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1030 <assert@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
cmp    $0x4,%eax
mov    $0xffffffff,%ecx
cmovl  %eax,%ecx
mov    $0xffffffff,%edx
test   %eax,%eax
cmovs  %edx,%ecx
mov    0x8(%rsp),%rax
xor    %edx,%edx
cmp    (%rax),%dl
sbb    %eax,%eax
or     %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @log_level_from_str(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i8*, i8** %3
%11 = call i32 @strtol(i8* %10, i8** %4, i32 10)
store i32 %11, i32* %5
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %22, label %16
16: ; preds = %1
%17 = load i32, i32* %5
%18 = icmp sge i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* %5
%21 = icmp sle i32 %20, 3
br i1 %21, label %23, label %22
22: ; preds = %19, %16, %1
store i32 -1, i32* %2
br label %25
23: ; preds = %19
%24 = load i32, i32* %5
store i32 %24, i32* %2
br label %25
25: ; preds = %23, %22
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
define i32 @log_level_from_str(i8* %0) {
%2 = alloca i8*
%3 = icmp ne i8* %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = bitcast i8** %2 to i8*
%7 = call i32 @strtol(i8* %0, i8** %2, i32 10)
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
%11 = icmp sgt i32 %7, -1
%12 = select i1 %10, i1 %11, i1 false
%13 = icmp slt i32 %7, 4
%14 = select i1 %12, i1 %13, i1 false
%15 = select i1 %14, i32 %7, i32 -1
ret i32 %15
}