#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 */
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ __ebt_print_error(char *);
int /*<<< orphan*/ free(char *);
int parse_port(char const *, char *);
char *strchr(char *, char);
char *strdup(char const *);
void parse_port_range(const char *protocol, const char *portstring,
                      uint16_t *ports) {
  char *buffer;
  char *cp;
  buffer = strdup(portstring);
  if ((cp = strchr(buffer, ':')) == NULL)
    ports[0] = ports[1] = parse_port(protocol, buffer);
  else {
    *cp = '\0';
    cp++;
    ports[0] = buffer[0] ? parse_port(protocol, buffer) : 0;
    ports[1] = cp[0] ? parse_port(protocol, cp) : 0xFFFF;
    if (ports[0] > ports[1])
      __ebt_print_error("Invalid portrange (min > max)");
    ;
  }
  free(buffer);
}


x86 assembly (clang, -O0):
<parse_port_range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11ae <parse_port_range+0x5e>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <parse_port@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    1259 <parse_port_range+0x109>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11e6 <parse_port_range+0x96>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <parse_port@plt>
mov    %eax,-0x2c(%rbp)
jmp    11f0 <parse_port_range+0xa0>
xor    %eax,%eax
mov    %eax,-0x2c(%rbp)
jmp    11f0 <parse_port_range+0xa0>
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     121e <parse_port_range+0xce>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <parse_port@plt>
mov    %eax,-0x30(%rbp)
jmp    122b <parse_port_range+0xdb>
mov    $0xffff,%eax
mov    %eax,-0x30(%rbp)
jmp    122b <parse_port_range+0xdb>
mov    -0x30(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%rcx
cmp    0x4(%rcx),%eax
jle    1254 <parse_port_range+0x104>
lea    0xdb1(%rip),%rdi
call   1060 <__ebt_print_error@plt>
jmp    1259 <parse_port_range+0x109>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_port_range>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1070 <strdup@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1199 <parse_port_range+0x49>
mov    %rax,%rbx
movb   $0x0,(%rax)
add    $0x1,%rbx
cmpb   $0x0,(%r12)
je     11ad <parse_port_range+0x5d>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <parse_port@plt>
jmp    11af <parse_port_range+0x5f>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <parse_port@plt>
mov    %eax,0x4(%r14)
mov    %eax,(%r14)
jmp    11e2 <parse_port_range+0x92>
xor    %eax,%eax
mov    %eax,(%r14)
cmpb   $0x0,(%rbx)
je     11c9 <parse_port_range+0x79>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <parse_port@plt>
mov    %eax,%ecx
mov    (%r14),%eax
jmp    11ce <parse_port_range+0x7e>
mov    $0xffff,%ecx
mov    %ecx,0x4(%r14)
cmp    %ecx,%eax
jle    11e2 <parse_port_range+0x92>
lea    0xe23(%rip),%rdi
call   1060 <__ebt_print_error@plt>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"Invalid portrange (min > max)\00"
define void @parse_port_range(i8* %0, i8* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
%9 = load i8*, i8** %5
%10 = call i8* @strdup(i8* %9)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = call i8* @strchr(i8* %11, i8 signext 58)
store i8* %12, i8** %8
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %22
14: ; preds = %3
%15 = load i8*, i8** %4
%16 = load i8*, i8** %7
%17 = call i32 @parse_port(i8* %15, i8* %16)
%18 = load i32*, i32** %6
%19 = getelementptr inbounds i32, i32* %18, i64 1
store i32 %17, i32* %19
%20 = load i32*, i32** %6
%21 = getelementptr inbounds i32, i32* %20, i64 0
store i32 %17, i32* %21
br label %64
22: ; preds = %3
%23 = load i8*, i8** %8
store i8 0, i8* %23
%24 = load i8*, i8** %8
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %8
%26 = load i8*, i8** %7
%27 = getelementptr inbounds i8, i8* %26, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %22
%32 = load i8*, i8** %4
%33 = load i8*, i8** %7
%34 = call i32 @parse_port(i8* %32, i8* %33)
br label %36
35: ; preds = %22
br label %36
36: ; preds = %35, %31
%37 = phi i32 [ %34, %31 ], [ 0, %35 ]
%38 = load i32*, i32** %6
%39 = getelementptr inbounds i32, i32* %38, i64 0
store i32 %37, i32* %39
%40 = load i8*, i8** %8
%41 = getelementptr inbounds i8, i8* %40, i64 0
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %36
%46 = load i8*, i8** %4
%47 = load i8*, i8** %8
%48 = call i32 @parse_port(i8* %46, i8* %47)
br label %50
49: ; preds = %36
br label %50
50: ; preds = %49, %45
%51 = phi i32 [ %48, %45 ], [ 65535, %49 ]
%52 = load i32*, i32** %6
%53 = getelementptr inbounds i32, i32* %52, i64 1
store i32 %51, i32* %53
%54 = load i32*, i32** %6
%55 = getelementptr inbounds i32, i32* %54, i64 0
%56 = load i32, i32* %55
%57 = load i32*, i32** %6
%58 = getelementptr inbounds i32, i32* %57, i64 1
%59 = load i32, i32* %58
%60 = icmp sgt i32 %56, %59
br i1 %60, label %61, label %63
61: ; preds = %50
%62 = call i32 @__ebt_print_error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %63
63: ; preds = %61, %50
br label %64
64: ; preds = %63, %14
%65 = load i8*, i8** %7
%66 = call i32 @free(i8* %65)
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"Invalid portrange (min > max)\00"
define void @parse_port_range(i8* %0, i8* nocapture %1, i32* nocapture %2) {
%4 = tail call i8* @strdup(i8* %1)
%5 = tail call i8* @strchr(i8* dereferenceable(1) %4, i8 signext 58)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = tail call i32 @parse_port(i8* %0, i8* %4)
%9 = getelementptr inbounds i32, i32* %2, i64 1
store i32 %8, i32* %9
store i32 %8, i32* %2
br label %30
10: ; preds = %3
store i8 0, i8* %5
%11 = getelementptr inbounds i8, i8* %5, i64 1
%12 = load i8, i8* %4
%13 = icmp eq i8 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i32 @parse_port(i8* %0, i8* %4)
br label %16
16: ; preds = %10, %14
%17 = phi i32 [ %15, %14 ], [ 0, %10 ]
store i32 %17, i32* %2
%18 = load i8, i8* %11
%19 = icmp eq i8 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = tail call i32 @parse_port(i8* %0, i8* %11)
%22 = load i32, i32* %2
br label %23
23: ; preds = %16, %20
%24 = phi i32 [ %22, %20 ], [ %17, %16 ]
%25 = phi i32 [ %21, %20 ], [ 65535, %16 ]
%26 = getelementptr inbounds i32, i32* %2, i64 1
store i32 %25, i32* %26
%27 = icmp sgt i32 %24, %25
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = tail call i32 @__ebt_print_error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %23, %28, %7
%31 = tail call i32 @free(i8* %4)
ret void
}