#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int rm_so;
};
typedef TYPE_1__ regmatch_t;
typedef int /*<<< orphan*/ regex_t;
typedef int /*<<< orphan*/ errbuf;

/* Variables and functions */
int /*<<< orphan*/ REG_EXTENDED;
int REG_NOMATCH;
scalar_t__ atol(char const *);
int /*<<< orphan*/ err(char *, char const *, char const *, ...);
int regcomp(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ regerror(int, int /*<<< orphan*/ *, char *, int);
int regexec(int /*<<< orphan*/ *, char const *, int, TYPE_1__ *,
            int /*<<< orphan*/);
int parse_int_range(const char *str, int *start, int *end) {
  regex_t ex;
  int e;
  static const char *pattern =
      "^[[:space:]]*([0-9]+)[[:space:]]*(-([0-9]+))?[[:space:]]*$";
  if ((e = regcomp(&ex, pattern, REG_EXTENDED)) != 0) {
    char errbuf[128];
    regerror(e, &ex, errbuf, sizeof(errbuf) - 1);
    errbuf[sizeof(errbuf) - 1] = '\0';
    err("regcomp(%s): %s\n", pattern, errbuf);
    return -1;
  }
  regmatch_t matches[4];
  if ((e = regexec(&ex, str, 4, matches, 0)) != 0) {
    char errbuf[128];
    regerror(e, &ex, errbuf, sizeof(errbuf) - 1);
    errbuf[sizeof(errbuf) - 1] = '\0';
    if (e != REG_NOMATCH)
      err("regexec: Couldn't match '%s' in '%s': %s\n", pattern, str, errbuf);
    return -1;
  }
  *start = (int)atol(str + matches[1].rm_so);
  if (matches[3].rm_so != -1)
    *end = (int)atol(str + matches[3].rm_so);
  else
    *end = *start;
  return 0;
}


x86 assembly (clang, -O0):
<parse_int_range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2eda(%rip),%rsi
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
lea    -0x24(%rbp),%rdi
call   1030 <regcomp@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
je     11d0 <parse_int_range+0x80>
mov    -0x28(%rbp),%edi
lea    -0xb0(%rbp),%rdx
lea    -0x24(%rbp),%rsi
mov    $0x7f,%ecx
call   1040 <regerror@plt>
movb   $0x0,-0x31(%rbp)
mov    0x2e99(%rip),%rsi
lea    -0xb0(%rbp),%rdx
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1050 <err@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b0 <parse_int_range+0x160>
mov    -0x10(%rbp),%rsi
lea    -0xc0(%rbp),%rcx
lea    -0x24(%rbp),%rdi
mov    $0x4,%edx
xor    %r8d,%r8d
call   1060 <regexec@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
je     1255 <parse_int_range+0x105>
mov    -0x28(%rbp),%edi
lea    -0x140(%rbp),%rdx
lea    -0x24(%rbp),%rsi
mov    $0x7f,%ecx
call   1040 <regerror@plt>
movb   $0x0,-0xc1(%rbp)
mov    -0x28(%rbp),%eax
mov    0x2dc7(%rip),%rcx
cmp    (%rcx),%eax
je     1249 <parse_int_range+0xf9>
mov    0x2e18(%rip),%rsi
mov    -0x10(%rbp),%rdx
lea    -0x140(%rbp),%rcx
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1050 <err@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b0 <parse_int_range+0x160>
mov    -0x10(%rbp),%rdi
movslq -0xbc(%rbp),%rax
add    %rax,%rdi
call   1070 <atol@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0xffffffff,-0xb4(%rbp)
je     129d <parse_int_range+0x14d>
mov    -0x10(%rbp),%rdi
movslq -0xb4(%rbp),%rax
add    %rax,%rdi
call   1070 <atol@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    12a9 <parse_int_range+0x159>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int_range>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xa8,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    0x2e6b(%rip),%rax
mov    (%rax),%edx
lea    0xe8a(%rip),%rsi
lea    0xc(%rsp),%rdi
call   1030 <regcomp@plt>
test   %eax,%eax
je     11c7 <parse_int_range+0x77>
lea    0xc(%rsp),%rsi
lea    0x20(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rdx
mov    $0x7f,%ecx
call   1040 <regerror@plt>
movb   $0x0,0x9f(%rsp)
lea    0xe8f(%rip),%rdi
lea    0xe4d(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <err@plt>
mov    $0xffffffff,%eax
jmp    125f <parse_int_range+0x10f>
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rcx
mov    %rbx,%rsi
mov    $0x4,%edx
xor    %r8d,%r8d
call   1060 <regexec@plt>
test   %eax,%eax
je     1234 <parse_int_range+0xe4>
mov    %eax,%ebp
lea    0xc(%rsp),%rsi
lea    0x20(%rsp),%rdx
mov    %eax,%edi
mov    $0x7f,%ecx
call   1040 <regerror@plt>
movb   $0x0,0x9f(%rsp)
mov    0x2ddc(%rip),%rax
cmp    (%rax),%ebp
je     122d <parse_int_range+0xdd>
lea    0xe35(%rip),%rdi
lea    0xde2(%rip),%rsi
lea    0x20(%rsp),%rcx
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <err@plt>
mov    $0xffffffff,%eax
jmp    125f <parse_int_range+0x10f>
movslq 0x14(%rsp),%rdi
add    %rbx,%rdi
call   1070 <atol@plt>
mov    %eax,(%r15)
movslq 0x1c(%rsp),%rcx
cmp    $0xffffffffffffffff,%rcx
je     125a <parse_int_range+0x10a>
add    %rcx,%rbx
mov    %rbx,%rdi
call   1070 <atol@plt>
mov    %eax,(%r14)
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32 }
@parse_int_range.pattern = internal global i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i32 0, i32 0)
@.str = [59 x i8] c"^[[:space:]]*([0-9]+)[[:space:]]*(-([0-9]+))?[[:space:]]*$\00"
@REG_EXTENDED = global i32 0
@.str.1 = [17 x i8] c"regcomp(%s): %s\0A\00"
@REG_NOMATCH = global i32 0
@.str.2 = [42 x i8] c"regexec: Couldn't match '%s' in '%s': %s\0A\00"
define i32 @parse_int_range(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [128 x i8]
%11 = alloca [4 x %struct.TYPE_3__]
%12 = alloca [128 x i8]
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%13 = load i8*, i8** @parse_int_range.pattern
%14 = load i32, i32* @REG_EXTENDED
%15 = call i32 @regcomp(i32* %8, i8* %13, i32 %14)
store i32 %15, i32* %9
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %3
%18 = load i32, i32* %9
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%20 = call i32 @regerror(i32 %18, i32* %8, i8* %19, i32 127)
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 127
store i8 0, i8* %21
%22 = load i8*, i8** @parse_int_range.pattern
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%24 = call i32 (i8*, i8*, i8*, ...) @err(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8* %23)
store i32 -1, i32* %4
br label %73
25: ; preds = %3
%26 = load i8*, i8** %5
%27 = getelementptr inbounds [4 x %struct.TYPE_3__], [4 x %struct.TYPE_3__]* %11, i64 0, i64 0
%28 = call i32 @regexec(i32* %8, i8* %26, i32 4, %struct.TYPE_3__* %27, i32 0)
store i32 %28, i32* %9
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %44
30: ; preds = %25
%31 = load i32, i32* %9
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%33 = call i32 @regerror(i32 %31, i32* %8, i8* %32, i32 127)
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 127
store i8 0, i8* %34
%35 = load i32, i32* %9
%36 = load i32, i32* @REG_NOMATCH
%37 = icmp ne i32 %35, %36
br i1 %37, label %38, label %43
38: ; preds = %30
%39 = load i8*, i8** @parse_int_range.pattern
%40 = load i8*, i8** %5
%41 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%42 = call i32 (i8*, i8*, i8*, ...) @err(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %39, i8* %40, i8* %41)
br label %43
43: ; preds = %38, %30
store i32 -1, i32* %4
br label %73
44: ; preds = %25
%45 = load i8*, i8** %5
%46 = getelementptr inbounds [4 x %struct.TYPE_3__], [4 x %struct.TYPE_3__]* %11, i64 0, i64 1
%47 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %46, i32 0, i32 0
%48 = load i32, i32* %47
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %45, i64 %49
%51 = call i64 @atol(i8* %50)
%52 = trunc i64 %51 to i32
%53 = load i32*, i32** %6
store i32 %52, i32* %53
%54 = getelementptr inbounds [4 x %struct.TYPE_3__], [4 x %struct.TYPE_3__]* %11, i64 0, i64 3
%55 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %54, i32 0, i32 0
%56 = load i32, i32* %55
%57 = icmp ne i32 %56, -1
br i1 %57, label %58, label %68
58: ; preds = %44
%59 = load i8*, i8** %5
%60 = getelementptr inbounds [4 x %struct.TYPE_3__], [4 x %struct.TYPE_3__]* %11, i64 0, i64 3
%61 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %60, i32 0, i32 0
%62 = load i32, i32* %61
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %59, i64 %63
%65 = call i64 @atol(i8* %64)
%66 = trunc i64 %65 to i32
%67 = load i32*, i32** %7
store i32 %66, i32* %67
br label %72
68: ; preds = %44
%69 = load i32*, i32** %6
%70 = load i32, i32* %69
%71 = load i32*, i32** %7
store i32 %70, i32* %71
br label %72
72: ; preds = %68, %58
store i32 0, i32* %4
br label %73
73: ; preds = %72, %43, %17
%74 = load i32, i32* %4
ret i32 %74
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32 }
@.str = [59 x i8] c"^[[:space:]]*([0-9]+)[[:space:]]*(-([0-9]+))?[[:space:]]*$\00"
@REG_EXTENDED = global i32 0
@.str.1 = [17 x i8] c"regcomp(%s): %s\0A\00"
@REG_NOMATCH = global i32 0
@.str.2 = [42 x i8] c"regexec: Couldn't match '%s' in '%s': %s\0A\00"
define i32 @parse_int_range(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = alloca [128 x i8]
%6 = alloca [4 x %struct.TYPE_3__]
%7 = alloca [128 x i8]
%8 = bitcast i32* %4 to i8*
%9 = load i32, i32* @REG_EXTENDED
%10 = call i32 @regcomp(i32* %4, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %3
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%14 = call i32 @regerror(i32 %10, i32* %4, i8* %13, i32 127)
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 127
store i8 0, i8* %15
%16 = call i32 (i8*, i8*, i8*, ...) @err(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %50
17: ; preds = %3
%18 = bitcast [4 x %struct.TYPE_3__]* %6 to i8*
%19 = getelementptr inbounds [4 x %struct.TYPE_3__], [4 x %struct.TYPE_3__]* %6, i64 0, i64 0
%20 = call i32 @regexec(i32* %4, i8* %0, i32 4, %struct.TYPE_3__* %19, i32 0)
%21 = icmp eq i32 %20, 0
br i1 %21, label %31, label %22
22: ; preds = %17
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%24 = call i32 @regerror(i32 %20, i32* %4, i8* %23, i32 127)
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 127
store i8 0, i8* %25
%26 = load i32, i32* @REG_NOMATCH
%27 = icmp eq i32 %20, %26
br i1 %27, label %30, label %28
28: ; preds = %22
%29 = call i32 (i8*, i8*, i8*, ...) @err(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %23)
br label %30
30: ; preds = %28, %22
br label %48
31: ; preds = %17
%32 = getelementptr inbounds [4 x %struct.TYPE_3__], [4 x %struct.TYPE_3__]* %6, i64 0, i64 1, i32 0
%33 = load i32, i32* %32
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %0, i64 %34
%36 = call i64 @atol(i8* %35)
%37 = trunc i64 %36 to i32
store i32 %37, i32* %1
%38 = getelementptr inbounds [4 x %struct.TYPE_3__], [4 x %struct.TYPE_3__]* %6, i64 0, i64 3, i32 0
%39 = load i32, i32* %38
%40 = icmp eq i32 %39, -1
br i1 %40, label %46, label %41
41: ; preds = %31
%42 = sext i32 %39 to i64
%43 = getelementptr inbounds i8, i8* %0, i64 %42
%44 = call i64 @atol(i8* %43)
%45 = trunc i64 %44 to i32
br label %46
46: ; preds = %31, %41
%47 = phi i32 [ %45, %41 ], [ %37, %31 ]
store i32 %47, i32* %2
br label %48
48: ; preds = %46, %30
%49 = phi i32 [ -1, %30 ], [ 0, %46 ]
br label %50
50: ; preds = %48, %12
%51 = phi i32 [ -1, %12 ], [ %49, %48 ]
ret i32 %51
}