#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 *);
char *op_xstrndup(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
char *strtok_r(char *, char *, char **);
unsigned long strtoul(char *, char **, int);
int ibs_parse_counts(char *str, unsigned long int *count) {
  char *tmp, *tok1, *tok2 = NULL, *end = NULL;
  if (!str)
    return -1;
  tmp = op_xstrndup(str, strlen(str));
  tok1 = strtok_r(tmp, ":", &tok2);
  *count = strtoul(tok1, &end, 10);
  if ((end && *end) || *count == 0 || errno == EINVAL || errno == ERANGE) {
    fprintf(stderr, "Invalid count (%s)\n", str);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ibs_parse_counts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1187 <ibs_parse_counts+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    1264 <ibs_parse_counts+0x114>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
call   1070 <op_xstrndup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe4e(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x38(%rbp)
je     11f6 <ibs_parse_counts+0xa6>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1238 <ibs_parse_counts+0xe8>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     1238 <ibs_parse_counts+0xe8>
mov    0x2dc5(%rip),%rax
mov    (%rax),%rax
mov    0x2db3(%rip),%rcx
cmp    (%rcx),%rax
je     1238 <ibs_parse_counts+0xe8>
mov    0x2dab(%rip),%rax
mov    (%rax),%rax
mov    0x2db9(%rip),%rcx
cmp    (%rcx),%rax
jne    125d <ibs_parse_counts+0x10d>
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdb6(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1264 <ibs_parse_counts+0x114>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ibs_parse_counts>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     120a <ibs_parse_counts+0xba>
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <op_xstrndup@plt>
lea    0xe6d(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rax,%rdi
call   1040 <strtok_r@plt>
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    %rax,(%r14)
mov    0x8(%rsp),%rcx
test   %rcx,%rcx
je     11c4 <ibs_parse_counts+0x74>
cmpb   $0x0,(%rcx)
jne    11ed <ibs_parse_counts+0x9d>
test   %rax,%rax
je     11ed <ibs_parse_counts+0x9d>
mov    0x2e00(%rip),%rax
mov    (%rax),%rcx
mov    0x2dee(%rip),%rax
cmp    (%rax),%rcx
je     11ed <ibs_parse_counts+0x9d>
xor    %eax,%eax
mov    0x2e00(%rip),%rdx
cmp    (%rdx),%rcx
jne    120a <ibs_parse_counts+0xba>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

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