#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 scalar_t__ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ inet_pton(int /*<<< orphan*/, char *, scalar_t__ *);
scalar_t__ ntohl(scalar_t__);
char *strchr(char *, char);
int getsea(uint32_t *saddr, uint32_t *eaddr, char *range) {
  char *p;
  if ((p = strchr(range, '-')) == NULL)
    return -1;
  *p++ = 0;
  if (inet_pton(AF_INET, range, saddr) < 0)
    return -1;
  if (inet_pton(AF_INET, p, eaddr) < 0)
    return -1;
  *saddr = ntohl(*saddr);
  *eaddr = ntohl(*eaddr);
  if (*eaddr < *saddr)
    return -1;
  if (*eaddr - *saddr + 1 > 256)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<getsea>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2d,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    116c <getsea+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1253 <getsea+0x123>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x0,(%rax)
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <inet_pton@plt>
cmp    $0x0,%rax
jge    11aa <getsea+0x7a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1253 <getsea+0x123>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <inet_pton@plt>
cmp    $0x0,%rax
jge    11d6 <getsea+0xa6>
movl   $0xffffffff,-0x4(%rbp)
jmp    1253 <getsea+0x123>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <ntohl@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1050 <ntohl@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jge    1222 <getsea+0xf2>
movl   $0xffffffff,-0x4(%rbp)
jmp    1253 <getsea+0x123>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
sub    (%rcx),%rax
add    $0x1,%rax
cmp    $0x100,%rax
jle    124c <getsea+0x11c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1253 <getsea+0x123>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getsea>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rdx,%rdi
mov    $0x2d,%esi
call   1030 <strchr@plt>
mov    $0xffffffff,%r15d
test   %rax,%rax
je     11c3 <getsea+0x93>
mov    %rax,%rbp
movb   $0x0,(%rax)
mov    0x2e7f(%rip),%r13
mov    0x0(%r13),%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <inet_pton@plt>
test   %rax,%rax
js     11c3 <getsea+0x93>
add    $0x1,%rbp
mov    0x0(%r13),%edi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1040 <inet_pton@plt>
test   %rax,%rax
js     11c3 <getsea+0x93>
mov    (%r12),%rdi
call   1050 <ntohl@plt>
mov    %rax,(%r12)
mov    (%r14),%rdi
call   1050 <ntohl@plt>
mov    %rax,(%r14)
sub    (%r12),%rax
jl     11c3 <getsea+0x93>
xor    %r15d,%r15d
cmp    $0x100,%rax
setge  %r15b
neg    %r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@AF_INET = global i32 0
define i32 @getsea(i64* %0, i64* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i64*
%6 = alloca i64*
%7 = alloca i8*
%8 = alloca i8*
store i64* %0, i64** %5
store i64* %1, i64** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %7
%10 = call i8* @strchr(i8* %9, i8 signext 45)
store i8* %10, i8** %8
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 -1, i32* %4
br label %54
13: ; preds = %3
%14 = load i8*, i8** %8
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %8
store i8 0, i8* %14
%16 = load i32, i32* @AF_INET
%17 = load i8*, i8** %7
%18 = load i64*, i64** %5
%19 = call i64 @inet_pton(i32 %16, i8* %17, i64* %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %13
store i32 -1, i32* %4
br label %54
22: ; preds = %13
%23 = load i32, i32* @AF_INET
%24 = load i8*, i8** %8
%25 = load i64*, i64** %6
%26 = call i64 @inet_pton(i32 %23, i8* %24, i64* %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %22
store i32 -1, i32* %4
br label %54
29: ; preds = %22
%30 = load i64*, i64** %5
%31 = load i64, i64* %30
%32 = call i64 @ntohl(i64 %31)
%33 = load i64*, i64** %5
store i64 %32, i64* %33
%34 = load i64*, i64** %6
%35 = load i64, i64* %34
%36 = call i64 @ntohl(i64 %35)
%37 = load i64*, i64** %6
store i64 %36, i64* %37
%38 = load i64*, i64** %6
%39 = load i64, i64* %38
%40 = load i64*, i64** %5
%41 = load i64, i64* %40
%42 = icmp slt i64 %39, %41
br i1 %42, label %43, label %44
43: ; preds = %29
store i32 -1, i32* %4
br label %54
44: ; preds = %29
%45 = load i64*, i64** %6
%46 = load i64, i64* %45
%47 = load i64*, i64** %5
%48 = load i64, i64* %47
%49 = sub nsw i64 %46, %48
%50 = add nsw i64 %49, 1
%51 = icmp sgt i64 %50, 256
br i1 %51, label %52, label %53
52: ; preds = %44
store i32 -1, i32* %4
br label %54
53: ; preds = %44
store i32 0, i32* %4
br label %54
54: ; preds = %53, %52, %43, %28, %21, %12
%55 = load i32, i32* %4
ret i32 %55
}

LLVM IR (-O2):
@AF_INET = global i32 0
define i32 @getsea(i64* %0, i64* %1, i8* %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %2, i8 signext 45)
%5 = icmp eq i8* %4, null
br i1 %5, label %26, label %6
6: ; preds = %3
store i8 0, i8* %4
%7 = load i32, i32* @AF_INET
%8 = tail call i64 @inet_pton(i32 %7, i8* %2, i64* %0)
%9 = icmp slt i64 %8, 0
br i1 %9, label %26, label %10
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %4, i64 1
%12 = load i32, i32* @AF_INET
%13 = tail call i64 @inet_pton(i32 %12, i8* %11, i64* %1)
%14 = icmp slt i64 %13, 0
br i1 %14, label %26, label %15
15: ; preds = %10
%16 = load i64, i64* %0
%17 = tail call i64 @ntohl(i64 %16)
store i64 %17, i64* %0
%18 = load i64, i64* %1
%19 = tail call i64 @ntohl(i64 %18)
store i64 %19, i64* %1
%20 = load i64, i64* %0
%21 = icmp slt i64 %19, %20
br i1 %21, label %26, label %22
22: ; preds = %15
%23 = sub nsw i64 %19, %20
%24 = icmp sgt i64 %23, 255
%25 = sext i1 %24 to i32
br label %26
26: ; preds = %22, %15, %10, %6, %3
%27 = phi i32 [ -1, %3 ], [ -1, %6 ], [ -1, %10 ], [ -1, %15 ], [ %25, %22 ]
ret i32 %27
}