#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*/ memset(char *, char, int);
int /*<<< orphan*/ re_match(char const *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int sscanf(char const *, char *, int *, int *);
int /*<<< orphan*/ validate_port(char *);
int validate_portrange(const char *str) {
  if (!str)
    return 0;
  int start, stop;
  start = stop = 0;
  char start_str[6], stop_str[6];
  memset(start_str, '\0', 6);
  memset(stop_str, '\0', 6);
  if (!re_match(str, "^[0-9]+-[0-9]+$"))
    return 0;
  if (sscanf(str, "%d-%d", &start, &stop) != 2)
    return 0;
  sprintf(start_str, "%d", start);
  sprintf(stop_str, "%d", stop);
  if (!validate_port(start_str))
    return 0;
  if (!validate_port(stop_str))
    return 0;
  if (stop <= start) {
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<validate_portrange>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1173 <validate_portrange+0x23>
movl   $0x0,-0x4(%rbp)
jmp    1274 <validate_portrange+0x124>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x1e(%rbp),%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1050 <memset@plt>
lea    -0x24(%rbp),%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1030 <re_match@plt>
cmp    $0x0,%eax
jne    11c6 <validate_portrange+0x76>
movl   $0x0,-0x4(%rbp)
jmp    1274 <validate_portrange+0x124>
mov    -0x10(%rbp),%rdi
lea    0xe3f(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   1060 <sscanf@plt>
cmp    $0x2,%eax
je     11f3 <validate_portrange+0xa3>
movl   $0x0,-0x4(%rbp)
jmp    1274 <validate_portrange+0x124>
lea    -0x1e(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe12(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x24(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xdff(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x1e(%rbp),%rdi
call   1040 <validate_port@plt>
cmp    $0x0,%eax
jne    1237 <validate_portrange+0xe7>
movl   $0x0,-0x4(%rbp)
jmp    1274 <validate_portrange+0x124>
lea    -0x24(%rbp),%rdi
call   1040 <validate_port@plt>
cmp    $0x0,%eax
jne    1255 <validate_portrange+0x105>
movl   $0x0,-0x4(%rbp)
jmp    1274 <validate_portrange+0x124>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     126d <validate_portrange+0x11d>
movl   $0x0,-0x4(%rbp)
jmp    1274 <validate_portrange+0x124>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_portrange>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
test   %rdi,%rdi
je     121f <validate_portrange+0xcf>
mov    %rdi,%rbx
movl   $0x0,0xc(%rsp)
movl   $0x0,0x10(%rsp)
lea    0x1a(%rsp),%rdi
xor    %ebp,%ebp
xor    %esi,%esi
mov    $0x6,%edx
call   1050 <memset@plt>
lea    0x14(%rsp),%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1050 <memset@plt>
lea    0xe61(%rip),%rsi
mov    %rbx,%rdi
call   1030 <re_match@plt>
test   %eax,%eax
je     1221 <validate_portrange+0xd1>
lea    0xe5e(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
call   1060 <sscanf@plt>
cmp    $0x2,%eax
jne    1221 <validate_portrange+0xd1>
mov    0x10(%rsp),%edx
lea    0xe3f(%rip),%rbx
lea    0x1a(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <sprintf@plt>
mov    0xc(%rsp),%edx
lea    0x14(%rsp),%rdi
mov    %rbx,%rsi
call   1070 <sprintf@plt>
mov    %r14,%rdi
call   1040 <validate_port@plt>
test   %eax,%eax
je     1221 <validate_portrange+0xd1>
lea    0x14(%rsp),%rdi
call   1040 <validate_port@plt>
test   %eax,%eax
je     1221 <validate_portrange+0xd1>
mov    0xc(%rsp),%eax
xor    %ebp,%ebp
cmp    0x10(%rsp),%eax
setg   %bpl
jmp    1221 <validate_portrange+0xd1>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"^[0-9]+-[0-9]+$\00"
@.str.1 = [6 x i8] c"%d-%d\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @validate_portrange(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [6 x i8]
%7 = alloca [6 x i8]
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
store i32 0, i32* %2
br label %47
11: ; preds = %1
store i32 0, i32* %5
store i32 0, i32* %4
%12 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i8 signext 0, i32 6)
%14 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i8 signext 0, i32 6)
%16 = load i8*, i8** %3
%17 = call i32 @re_match(i8* %16, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%18 = icmp ne i32 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %11
store i32 0, i32* %2
br label %47
20: ; preds = %11
%21 = load i8*, i8** %3
%22 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32* %5)
%23 = icmp ne i32 %22, 2
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 0, i32* %2
br label %47
25: ; preds = %20
%26 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%27 = load i32, i32* %4
%28 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%30 = load i32, i32* %5
%31 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%33 = call i32 @validate_port(i8* %32)
%34 = icmp ne i32 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %25
store i32 0, i32* %2
br label %47
36: ; preds = %25
%37 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%38 = call i32 @validate_port(i8* %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %36
store i32 0, i32* %2
br label %47
41: ; preds = %36
%42 = load i32, i32* %5
%43 = load i32, i32* %4
%44 = icmp sle i32 %42, %43
br i1 %44, label %45, label %46
45: ; preds = %41
store i32 0, i32* %2
br label %47
46: ; preds = %41
store i32 1, i32* %2
br label %47
47: ; preds = %46, %45, %40, %35, %24, %19, %10
%48 = load i32, i32* %2
ret i32 %48
}

LLVM IR (-O2):
@.str = [16 x i8] c"^[0-9]+-[0-9]+$\00"
@.str.1 = [6 x i8] c"%d-%d\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @validate_portrange(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [6 x i8]
%5 = alloca [6 x i8]
%6 = icmp eq i8* %0, null
br i1 %6, label %36, label %7
7: ; preds = %1
%8 = bitcast i32* %2 to i8*
%9 = bitcast i32* %3 to i8*
store i32 0, i32* %3
store i32 0, i32* %2
%10 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%12 = call i32 @memset(i8* %10, i8 signext 0, i32 6)
%13 = call i32 @memset(i8* %11, i8 signext 0, i32 6)
%14 = call i32 @re_match(i8* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i32 %14, 0
br i1 %15, label %34, label %16
16: ; preds = %7
%17 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3)
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %34
19: ; preds = %16
%20 = load i32, i32* %2
%21 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %3
%23 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = call i32 @validate_port(i8* %10)
%25 = icmp eq i32 %24, 0
br i1 %25, label %34, label %26
26: ; preds = %19
%27 = call i32 @validate_port(i8* %11)
%28 = icmp eq i32 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %26
%30 = load i32, i32* %3
%31 = load i32, i32* %2
%32 = icmp sgt i32 %30, %31
%33 = zext i1 %32 to i32
br label %34
34: ; preds = %29, %26, %19, %16, %7
%35 = phi i32 [ 0, %7 ], [ 0, %16 ], [ 0, %19 ], [ 0, %26 ], [ %33, %29 ]
br label %36
36: ; preds = %1, %34
%37 = phi i32 [ %35, %34 ], [ 0, %1 ]
ret i32 %37
}