#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 */
unsigned short atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
int parse_source_port(char *port, unsigned short *low, unsigned short *high) {
  char *dash;
  *low = atoi(port);
  dash = strchr(port, '-');
  *high = 0;
  if (dash) {
    *high = atoi(dash + 1);
  }
  if (*high == 0) {
    *high = *low;
  }
  if (*high < *low) {
    fprintf(stderr, "%s: Invalid port range\n", port);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_source_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
mov    %ax,%cx
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x2d,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movw   $0x0,(%rax)
cmpq   $0x0,-0x28(%rbp)
je     1194 <parse_source_port+0x64>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1050 <atoi@plt>
mov    %ax,%cx
mov    -0x20(%rbp),%rax
mov    %cx,(%rax)
mov    -0x20(%rbp),%rax
movzwl (%rax),%eax
cmp    $0x0,%eax
jne    11b2 <parse_source_port+0x82>
mov    -0x18(%rbp),%rax
mov    (%rax),%cx
mov    -0x20(%rbp),%rax
mov    %cx,(%rax)
mov    -0x20(%rbp),%rax
movzwl (%rax),%eax
mov    -0x18(%rbp),%rcx
movzwl (%rcx),%ecx
cmp    %ecx,%eax
jge    11ed <parse_source_port+0xbd>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe24(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f4 <parse_source_port+0xc4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_source_port>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
call   1050 <atoi@plt>
mov    %ax,(%rbx)
mov    %r14,%rdi
mov    $0x2d,%esi
call   1030 <strchr@plt>
movw   $0x0,(%r15)
test   %rax,%rax
je     1173 <parse_source_port+0x43>
add    $0x1,%rax
mov    %rax,%rdi
call   1050 <atoi@plt>
mov    %ax,(%r15)
test   %ax,%ax
jne    117a <parse_source_port+0x4a>
movzwl (%rbx),%eax
mov    %ax,(%r15)
xor    %ecx,%ecx
cmp    (%rbx),%ax
jae    119e <parse_source_port+0x6e>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xe6f(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%ecx
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"%s: Invalid port range\0A\00"
define i32 @parse_source_port(i8* %0, i16* %1, i16* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i16*
%7 = alloca i16*
%8 = alloca i8*
store i8* %0, i8** %5
store i16* %1, i16** %6
store i16* %2, i16** %7
%9 = load i8*, i8** %5
%10 = call zeroext i16 @atoi(i8* %9)
%11 = load i16*, i16** %6
store i16 %10, i16* %11
%12 = load i8*, i8** %5
%13 = call i8* @strchr(i8* %12, i8 signext 45)
store i8* %13, i8** %8
%14 = load i16*, i16** %7
store i16 0, i16* %14
%15 = load i8*, i8** %8
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %22
17: ; preds = %3
%18 = load i8*, i8** %8
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = call zeroext i16 @atoi(i8* %19)
%21 = load i16*, i16** %7
store i16 %20, i16* %21
br label %22
22: ; preds = %17, %3
%23 = load i16*, i16** %7
%24 = load i16, i16* %23
%25 = zext i16 %24 to i32
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = load i16*, i16** %6
%29 = load i16, i16* %28
%30 = load i16*, i16** %7
store i16 %29, i16* %30
br label %31
31: ; preds = %27, %22
%32 = load i16*, i16** %7
%33 = load i16, i16* %32
%34 = zext i16 %33 to i32
%35 = load i16*, i16** %6
%36 = load i16, i16* %35
%37 = zext i16 %36 to i32
%38 = icmp slt i32 %34, %37
br i1 %38, label %39, label %43
39: ; preds = %31
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %5
%42 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %41)
store i32 -1, i32* %4
br label %44
43: ; preds = %31
store i32 0, i32* %4
br label %44
44: ; preds = %43, %39
%45 = load i32, i32* %4
ret i32 %45
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"%s: Invalid port range\0A\00"
define i32 @parse_source_port(i8* %0, i16* nocapture %1, i16* nocapture %2) {
%4 = tail call zeroext i16 @atoi(i8* %0)
store i16 %4, i16* %1
%5 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 45)
store i16 0, i16* %2
%6 = icmp eq i8* %5, null
br i1 %6, label %11, label %7
7: ; preds = %3
%8 = getelementptr inbounds i8, i8* %5, i64 1
%9 = tail call zeroext i16 @atoi(i8* %8)
store i16 %9, i16* %2
%10 = icmp eq i16 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %3, %7
%12 = load i16, i16* %1
store i16 %12, i16* %2
br label %13
13: ; preds = %11, %7
%14 = phi i16 [ %12, %11 ], [ %9, %7 ]
%15 = load i16, i16* %1
%16 = icmp ult i16 %14, %15
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %20
20: ; preds = %13, %17
%21 = phi i32 [ -1, %17 ], [ 0, %13 ]
ret i32 %21
}