#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 atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ is_number(char *);
scalar_t__ isdigit(char);
int /*<<< orphan*/ stderr;
char *strdup(char *);
int strlen(char *);
char *strstr(char *, char *);
int parse_range(char *r, char **prefix, int *start, int *end) {
  char *range;
  char *first_part;
  char *ptr;
  char *end_str;
  char *start_str;
  int i, l;
  range = strdup(r);
  if (!(ptr = strstr(range, ".."))) {
    *prefix = range;
    *start = -1;
    return 1;
  }
  first_part = range;
  *ptr = '\0';
  l = strlen(first_part);
  for (i = 0; i < l; i++)
    if (isdigit(first_part[i]))
      break;
  if (i == l) {
    fprintf(stderr, "First part of range does not have digits\n");
    goto bad_range;
  }
  start_str = &first_part[i];
  if (!is_number(start_str)) {
    fprintf(stderr, "Start of range is not a number\n");
    goto bad_range;
  }
  *start = atoi(start_str);
  *start_str = '\0';
  *prefix = strdup(first_part);
  ptr++;
  ptr++;
  if (!ptr) {
    fprintf(stderr, "Error bad range");
    goto bad_range;
  }
  end_str = ptr;
  if (!is_number(end_str)) {
    fprintf(stderr, "End of range is not a number\n");
    goto bad_range;
  }
  *end = atoi(end_str);
  if (*end <= *start)
    goto bad_range;
  return 1;
bad_range:
  free(range);
  return 0;
}


x86 assembly (clang, -O0):
<parse_range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    11e4 <parse_range+0x64>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
movl   $0xffffffff,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1386 <parse_range+0x206>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x58(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x58(%rbp),%eax
jge    1245 <parse_range+0xc5>
mov    -0x38(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     1232 <parse_range+0xb2>
jmp    1245 <parse_range+0xc5>
jmp    1237 <parse_range+0xb7>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1206 <parse_range+0x86>
mov    -0x54(%rbp),%eax
cmp    -0x58(%rbp),%eax
jne    126b <parse_range+0xeb>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xda2(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1376 <parse_range+0x1f6>
mov    -0x38(%rbp),%rax
movslq -0x54(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
call   1050 <is_number@plt>
cmp    $0x0,%eax
jne    12a6 <parse_range+0x126>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
lea    0xd91(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1376 <parse_range+0x1f6>
mov    -0x50(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x50(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    130e <parse_range+0x18e>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
lea    0xd49(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1376 <parse_range+0x1f6>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1050 <is_number@plt>
cmp    $0x0,%eax
jne    1342 <parse_range+0x1c2>
mov    0x2cb1(%rip),%rax
mov    (%rax),%edi
lea    0xd25(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1376 <parse_range+0x1f6>
mov    -0x48(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jg     136a <parse_range+0x1ea>
jmp    1376 <parse_range+0x1f6>
movl   $0x1,-0x4(%rbp)
jmp    1386 <parse_range+0x206>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_range>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r12
mov    %rdx,%r15
mov    %rsi,%rbp
call   1090 <strdup@plt>
mov    %rax,%r13
mov    %rax,%rbx
lea    0xe57(%rip),%rsi
mov    %rax,%rdi
call   10a0 <strstr@plt>
test   %rax,%rax
je     11fa <parse_range+0x7a>
mov    %rax,0x10(%rsp)
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %eax,%r14d
test   %eax,%eax
mov    %r12,0x8(%rsp)
jle    120c <parse_range+0x8c>
mov    %r15,(%rsp)
mov    %r14d,%r15d
xor    %r12d,%r12d
nopl   0x0(%rax)
movsbl (%rbx,%r12,1),%edi
call   1040 <isdigit@plt>
test   %rax,%rax
jne    1242 <parse_range+0xc2>
add    $0x1,%r12
cmp    %r12,%r15
jne    11e0 <parse_range+0x60>
jmp    1214 <parse_range+0x94>
mov    %rbx,0x0(%rbp)
movl   $0xffffffff,(%r15)
mov    $0x1,%eax
jmp    1233 <parse_range+0xb3>
xor    %r12d,%r12d
cmp    %r14d,%r12d
jne    124b <parse_range+0xcb>
lea    0xde8(%rip),%rsi
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsp),%r15
cmp    %r14d,%r12d
je     1214 <parse_range+0x94>
mov    %r12d,%eax
add    %rax,%r13
mov    %r13,%rdi
call   1050 <is_number@plt>
test   %eax,%eax
je     12ab <parse_range+0x12b>
mov    %r13,%rdi
call   1080 <atoi@plt>
mov    %eax,(%r15)
movb   $0x0,0x0(%r13)
mov    %rbx,%rdi
call   1090 <strdup@plt>
mov    %rax,0x0(%rbp)
mov    0x10(%rsp),%rbp
add    $0x2,%rbp
mov    %rbp,%rdi
call   1050 <is_number@plt>
test   %eax,%eax
je     12b7 <parse_range+0x137>
mov    %rbp,%rdi
call   1080 <atoi@plt>
mov    %eax,%ecx
mov    0x8(%rsp),%rax
mov    %ecx,(%rax)
mov    $0x1,%eax
cmp    (%r15),%ecx
jle    1229 <parse_range+0xa9>
jmp    1233 <parse_range+0xb3>
lea    0xd7b(%rip),%rsi
jmp    121b <parse_range+0x9b>
lea    0xd8f(%rip),%rsi
jmp    121b <parse_range+0x9b>

LLVM IR (-O0):
@.str = [3 x i8] c"..\00"
@stderr = global i32 0
@.str.1 = [42 x i8] c"First part of range does not have digits\0A\00"
@.str.2 = [32 x i8] c"Start of range is not a number\0A\00"
@.str.3 = [16 x i8] c"Error bad range\00"
@.str.4 = [30 x i8] c"End of range is not a number\0A\00"
define i32 @parse_range(i8* %0, i8** %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
store i8* %0, i8** %6
store i8** %1, i8*** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%17 = load i8*, i8** %6
%18 = call i8* @strdup(i8* %17)
store i8* %18, i8** %10
%19 = load i8*, i8** %10
%20 = call i8* @strstr(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %20, i8** %12
%21 = icmp ne i8* %20, null
br i1 %21, label %26, label %22
22: ; preds = %4
%23 = load i8*, i8** %10
%24 = load i8**, i8*** %7
store i8* %23, i8** %24
%25 = load i32*, i32** %8
store i32 -1, i32* %25
store i32 1, i32* %5
br label %105
26: ; preds = %4
%27 = load i8*, i8** %10
store i8* %27, i8** %11
%28 = load i8*, i8** %12
store i8 0, i8* %28
%29 = load i8*, i8** %11
%30 = call i32 @strlen(i8* %29)
store i32 %30, i32* %16
store i32 0, i32* %15
br label %31
31: ; preds = %45, %26
%32 = load i32, i32* %15
%33 = load i32, i32* %16
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %48
35: ; preds = %31
%36 = load i8*, i8** %11
%37 = load i32, i32* %15
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8, i8* %39
%41 = call i64 @isdigit(i8 signext %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %35
br label %48
44: ; preds = %35
br label %45
45: ; preds = %44
%46 = load i32, i32* %15
%47 = add nsw i32 %46, 1
store i32 %47, i32* %15
br label %31
48: ; preds = %43, %31
%49 = load i32, i32* %15
%50 = load i32, i32* %16
%51 = icmp eq i32 %49, %50
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = load i32, i32* @stderr
%54 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
br label %102
55: ; preds = %48
%56 = load i8*, i8** %11
%57 = load i32, i32* %15
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
store i8* %59, i8** %14
%60 = load i8*, i8** %14
%61 = call i32 @is_number(i8* %60)
%62 = icmp ne i32 %61, 0
br i1 %62, label %66, label %63
63: ; preds = %55
%64 = load i32, i32* @stderr
%65 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %102
66: ; preds = %55
%67 = load i8*, i8** %14
%68 = call i32 @atoi(i8* %67)
%69 = load i32*, i32** %8
store i32 %68, i32* %69
%70 = load i8*, i8** %14
store i8 0, i8* %70
%71 = load i8*, i8** %11
%72 = call i8* @strdup(i8* %71)
%73 = load i8**, i8*** %7
store i8* %72, i8** %73
%74 = load i8*, i8** %12
%75 = getelementptr inbounds i8, i8* %74, i32 1
store i8* %75, i8** %12
%76 = load i8*, i8** %12
%77 = getelementptr inbounds i8, i8* %76, i32 1
store i8* %77, i8** %12
%78 = load i8*, i8** %12
%79 = icmp ne i8* %78, null
br i1 %79, label %83, label %80
80: ; preds = %66
%81 = load i32, i32* @stderr
%82 = call i32 @fprintf(i32 %81, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %102
83: ; preds = %66
%84 = load i8*, i8** %12
store i8* %84, i8** %13
%85 = load i8*, i8** %13
%86 = call i32 @is_number(i8* %85)
%87 = icmp ne i32 %86, 0
br i1 %87, label %91, label %88
88: ; preds = %83
%89 = load i32, i32* @stderr
%90 = call i32 @fprintf(i32 %89, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %102
91: ; preds = %83
%92 = load i8*, i8** %13
%93 = call i32 @atoi(i8* %92)
%94 = load i32*, i32** %9
store i32 %93, i32* %94
%95 = load i32*, i32** %9
%96 = load i32, i32* %95
%97 = load i32*, i32** %8
%98 = load i32, i32* %97
%99 = icmp sle i32 %96, %98
br i1 %99, label %100, label %101
100: ; preds = %91
br label %102
101: ; preds = %91
store i32 1, i32* %5
br label %105
102: ; preds = %100, %88, %80, %63, %52
%103 = load i8*, i8** %10
%104 = call i32 @free(i8* %103)
store i32 0, i32* %5
br label %105
105: ; preds = %102, %101, %22
%106 = load i32, i32* %5
ret i32 %106
}

LLVM IR (-O2):
@.str = [3 x i8] c"..\00"
@stderr = global i32 0
@.str.1 = [42 x i8] c"First part of range does not have digits\0A\00"
@.str.2 = [32 x i8] c"Start of range is not a number\0A\00"
@.str.4 = [30 x i8] c"End of range is not a number\0A\00"
define i32 @parse_range(i8* nocapture %0, i8** nocapture writeonly %1, i32* nocapture %2, i32* nocapture writeonly %3) {
%5 = tail call i8* @strdup(i8* %0)
%6 = tail call i8* @strstr(i8* dereferenceable(1) %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %4
store i8* %5, i8** %1
store i32 -1, i32* %2
br label %49
9: ; preds = %4
store i8 0, i8* %6
%10 = tail call i32 @strlen(i8* %5)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %25
12: ; preds = %9
%13 = zext i32 %10 to i64
br label %14
14: ; preds = %12, %20
%15 = phi i64 [ 0, %12 ], [ %21, %20 ]
%16 = getelementptr inbounds i8, i8* %5, i64 %15
%17 = load i8, i8* %16
%18 = tail call i64 @isdigit(i8 signext %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = add nuw nsw i64 %15, 1
%22 = icmp eq i64 %21, %13
br i1 %22, label %43, label %14
23: ; preds = %14
%24 = trunc i64 %15 to i32
br label %25
25: ; preds = %23, %9
%26 = phi i32 [ 0, %9 ], [ %24, %23 ]
%27 = icmp eq i32 %26, %10
br i1 %27, label %43, label %28
28: ; preds = %25
%29 = zext i32 %26 to i64
%30 = getelementptr inbounds i8, i8* %5, i64 %29
%31 = tail call i32 @is_number(i8* %30)
%32 = icmp eq i32 %31, 0
br i1 %32, label %43, label %33
33: ; preds = %28
%34 = tail call i32 @atoi(i8* %30)
store i32 %34, i32* %2
store i8 0, i8* %30
%35 = tail call i8* @strdup(i8* %5)
store i8* %35, i8** %1
%36 = getelementptr inbounds i8, i8* %6, i64 2
%37 = tail call i32 @is_number(i8* %36)
%38 = icmp eq i32 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %33
%40 = tail call i32 @atoi(i8* %36)
store i32 %40, i32* %3
%41 = load i32, i32* %2
%42 = icmp sgt i32 %40, %41
br i1 %42, label %49, label %47
43: ; preds = %20, %33, %28, %25
%44 = phi i8* [ getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), %25 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), %28 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), %33 ], [ getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), %20 ]
%45 = load i32, i32* @stderr
%46 = tail call i32 @fprintf(i32 %45, i8* %44)
br label %47
47: ; preds = %43, %39
%48 = tail call i32 @free(i8* %5)
br label %49
49: ; preds = %39, %47, %8
%50 = phi i32 [ 0, %47 ], [ 1, %8 ], [ 1, %39 ]
ret i32 %50
}