#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__ EINVAL;
scalar_t__ ERANGE;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
unsigned long strtoul(char const *, char **, int);
int ibs_parse_and_set_um_op(char const *str, unsigned long int *ibs_op_um) {
  char *end = NULL;
  if (!str)
    return -1;
  *ibs_op_um = strtoul(str, &end, 16);
  if ((end && *end) || errno == EINVAL || errno == ERANGE) {
    fprintf(stderr, "Invalid unitmaks (%s)\n", str);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ibs_parse_and_set_um_op>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114f <ibs_parse_and_set_um_op+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e6 <ibs_parse_and_set_um_op+0xc6>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1040 <strtoul@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     1186 <ibs_parse_and_set_um_op+0x66>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11ba <ibs_parse_and_set_um_op+0x9a>
mov    0x2e43(%rip),%rax
mov    (%rax),%rax
mov    0x2e31(%rip),%rcx
cmp    (%rcx),%rax
je     11ba <ibs_parse_and_set_um_op+0x9a>
mov    0x2e29(%rip),%rax
mov    (%rax),%rax
mov    0x2e37(%rip),%rcx
cmp    (%rcx),%rax
jne    11df <ibs_parse_and_set_um_op+0xbf>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe32(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e6 <ibs_parse_and_set_um_op+0xc6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ibs_parse_and_set_um_op>:
push   %r14
push   %rbx
push   %rax
movq   $0x0,(%rsp)
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     119b <ibs_parse_and_set_um_op+0x7b>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rsi
mov    $0x10,%edx
call   1040 <strtoul@plt>
mov    %rax,(%r14)
mov    (%rsp),%rax
test   %rax,%rax
je     115a <ibs_parse_and_set_um_op+0x3a>
cmpb   $0x0,(%rax)
jne    117e <ibs_parse_and_set_um_op+0x5e>
mov    0x2e6f(%rip),%rax
mov    (%rax),%rcx
mov    0x2e5d(%rip),%rax
cmp    (%rax),%rcx
je     117e <ibs_parse_and_set_um_op+0x5e>
xor    %eax,%eax
mov    0x2e6f(%rip),%rdx
cmp    (%rdx),%rcx
jne    119b <ibs_parse_and_set_um_op+0x7b>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i64 0
@EINVAL = global i64 0
@ERANGE = global i64 0
@stderr = global i32 0
@.str = [23 x i8] c"Invalid unitmaks (%s)\0A\00"
define i32 @ibs_parse_and_set_um_op(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i8*
store i8* %0, i8** %4
store i64* %1, i64** %5
store i8* null, i8** %6
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %2
store i32 -1, i32* %3
br label %34
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i64 @strtoul(i8* %11, i8** %6, i32 16)
%13 = load i64*, i64** %5
store i64 %12, i64* %13
%14 = load i8*, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %21
16: ; preds = %10
%17 = load i8*, i8** %6
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %29, label %21
21: ; preds = %16, %10
%22 = load i64, i64* @errno
%23 = load i64, i64* @EINVAL
%24 = icmp eq i64 %22, %23
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = load i64, i64* @errno
%27 = load i64, i64* @ERANGE
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %33
29: ; preds = %25, %21, %16
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %4
%32 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %31)
store i32 -1, i32* %3
br label %34
33: ; preds = %25
store i32 0, i32* %3
br label %34
34: ; preds = %33, %29, %9
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@errno = global i64 0
@EINVAL = global i64 0
@ERANGE = global i64 0
@stderr = global i32 0
@.str = [23 x i8] c"Invalid unitmaks (%s)\0A\00"
define i32 @ibs_parse_and_set_um_op(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%5 = icmp eq i8* %0, null
br i1 %5, label %23, label %6
6: ; preds = %2
%7 = call i64 @strtoul(i8* %0, i8** %3, i32 16)
store i64 %7, i64* %1
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = load i8, i8* %8
%12 = icmp eq i8 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %10, %6
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINVAL
%16 = icmp eq i64 %14, %15
%17 = load i64, i64* @ERANGE
%18 = icmp eq i64 %14, %17
%19 = select i1 %16, i1 true, i1 %18
br i1 %19, label %20, label %23
20: ; preds = %13, %10
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %23
23: ; preds = %13, %2, %20
%24 = phi i32 [ -1, %20 ], [ -1, %2 ], [ 0, %13 ]
ret i32 %24
}