#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 /*<<< orphan*/ ports;

/* Variables and functions */
scalar_t__ atoi(char *);
scalar_t__ checknumrange(char *, int, int);
char *strchr(char *, char const);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int checkportrange(const char *portrange, const char separator) {
  char ports[12], *startport, *endport;
  int err = 0;
  if (portrange == NULL)
    err = 1;
  else {
    strncpy(ports, portrange, sizeof(ports));
    startport = ports;
    if ((endport = strchr(ports, separator)) == NULL)
      err = 1;
    else {
      *(endport++) = '\0';
      if (atoi(startport) > atoi(endport))
        err = 1;
      else {
        err += checknumrange(startport, 1, 65534);
        err += checknumrange(endport, 1, 65534);
      }
    }
  }
  return err;
}


x86 assembly (clang, -O0):
<checkportrange>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1170 <checkportrange+0x30>
movl   $0x1,-0x2c(%rbp)
jmp    123f <checkportrange+0xff>
lea    -0x15(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0xc,%edx
call   1030 <strncpy@plt>
lea    -0x15(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x15(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11b1 <checkportrange+0x71>
movl   $0x1,-0x2c(%rbp)
jmp    123a <checkportrange+0xfa>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1060 <atoi@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <atoi@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
jle    11f5 <checkportrange+0xb5>
movl   $0x1,-0x2c(%rbp)
jmp    1235 <checkportrange+0xf5>
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
mov    $0xfffe,%edx
call   1050 <checknumrange@plt>
mov    %rax,%rcx
movslq -0x2c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x1,%esi
mov    $0xfffe,%edx
call   1050 <checknumrange@plt>
mov    %rax,%rcx
movslq -0x2c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x2c(%rbp)
jmp    123a <checkportrange+0xfa>
jmp    123f <checkportrange+0xff>
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkportrange>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0x1,%r14d
test   %rdi,%rdi
je     11ce <checkportrange+0x8e>
mov    %esi,%ebx
mov    %rdi,%rsi
lea    0x4(%rsp),%r15
mov    %r15,%rdi
mov    $0xc,%edx
call   1030 <strncpy@plt>
movsbl %bl,%esi
mov    %r15,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     11ce <checkportrange+0x8e>
mov    %rax,%rbx
add    $0x1,%rbx
movb   $0x0,(%rax)
lea    0x4(%rsp),%rdi
call   1060 <atoi@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1060 <atoi@plt>
cmp    %rax,%r15
jg     11ce <checkportrange+0x8e>
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
mov    $0xfffe,%edx
call   1050 <checknumrange@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0xfffe,%edx
call   1050 <checknumrange@plt>
mov    %rax,%r14
add    %r15d,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @checkportrange(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca [12 x i8]
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i8 %1, i8* %4
store i32 0, i32* %8
%9 = load i8*, i8** %3
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 1, i32* %8
br label %46
12: ; preds = %2
%13 = getelementptr inbounds [12 x i8], [12 x i8]* %5, i64 0, i64 0
%14 = load i8*, i8** %3
%15 = call i32 @strncpy(i8* %13, i8* %14, i32 12)
%16 = getelementptr inbounds [12 x i8], [12 x i8]* %5, i64 0, i64 0
store i8* %16, i8** %6
%17 = getelementptr inbounds [12 x i8], [12 x i8]* %5, i64 0, i64 0
%18 = load i8, i8* %4
%19 = call i8* @strchr(i8* %17, i8 signext %18)
store i8* %19, i8** %7
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %12
store i32 1, i32* %8
br label %45
22: ; preds = %12
%23 = load i8*, i8** %7
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %7
store i8 0, i8* %23
%25 = load i8*, i8** %6
%26 = call i64 @atoi(i8* %25)
%27 = load i8*, i8** %7
%28 = call i64 @atoi(i8* %27)
%29 = icmp sgt i64 %26, %28
br i1 %29, label %30, label %31
30: ; preds = %22
store i32 1, i32* %8
br label %44
31: ; preds = %22
%32 = load i8*, i8** %6
%33 = call i64 @checknumrange(i8* %32, i32 1, i32 65534)
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = add nsw i64 %35, %33
%37 = trunc i64 %36 to i32
store i32 %37, i32* %8
%38 = load i8*, i8** %7
%39 = call i64 @checknumrange(i8* %38, i32 1, i32 65534)
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = add nsw i64 %41, %39
%43 = trunc i64 %42 to i32
store i32 %43, i32* %8
br label %44
44: ; preds = %31, %30
br label %45
45: ; preds = %44, %21
br label %46
46: ; preds = %45, %11
%47 = load i32, i32* %8
ret i32 %47
}

LLVM IR (-O2):
define i32 @checkportrange(i8* %0, i8 signext %1) {
%3 = alloca [12 x i8]
%4 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %0, null
br i1 %5, label %20, label %6
6: ; preds = %2
%7 = call i32 @strncpy(i8* %4, i8* %0, i32 12)
%8 = call i8* @strchr(i8* %4, i8 signext %1)
%9 = icmp eq i8* %8, null
br i1 %9, label %20, label %10
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %8, i64 1
store i8 0, i8* %8
%12 = call i64 @atoi(i8* %4)
%13 = call i64 @atoi(i8* %11)
%14 = icmp sgt i64 %12, %13
br i1 %14, label %20, label %15
15: ; preds = %10
%16 = call i64 @checknumrange(i8* %4, i32 1, i32 65534)
%17 = call i64 @checknumrange(i8* %11, i32 1, i32 65534)
%18 = add i64 %17, %16
%19 = trunc i64 %18 to i32
br label %20
20: ; preds = %10, %6, %2, %15
%21 = phi i32 [ %19, %15 ], [ 1, %2 ], [ 1, %6 ], [ 1, %10 ]
ret i32 %21
}