#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 */
struct in_addr {
  int /*<<< orphan*/ s_addr;
};
struct hostent {
  scalar_t__ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
struct hostent *gethostbyname(char const *);
char *index(char *, char);
scalar_t__ inet_aton(char const *, struct in_addr *);
scalar_t__ ntohl(int /*<<< orphan*/);
char *strdup(char const *);
int parse_address_range(const char *str, struct in_addr *addr_low,
                        struct in_addr *addr_high) {
  char *str_copy, *tmp_ptr;
  struct hostent *addr2 = NULL;
  if (inet_aton(str, addr_low)) {
    addr_high->s_addr = addr_low->s_addr;
    return 1;
  }
  if ((addr2 = gethostbyname(str)) != NULL) {
    addr_low->s_addr = ((struct in_addr *)addr2->h_addr)->s_addr;
    addr_high->s_addr = addr_low->s_addr;
    return 1;
  }
  str_copy = strdup(str);
  if ((tmp_ptr = index(str_copy, '-')) == NULL) {
    free(str_copy);
    return 0;
  }
  *tmp_ptr = '\0';
  if (!inet_aton(str_copy, addr_low) &&
      ((addr2 = gethostbyname(str_copy)) == NULL)) {
    free(str_copy);
    return 0;
  }
  if (addr2 != NULL) {
    addr_low->s_addr = ((struct in_addr *)addr2->h_addr)->s_addr;
    addr2 = NULL;
  }
  if (!inet_aton(tmp_ptr + 1, addr_high) &&
      ((addr2 = gethostbyname(tmp_ptr + 1)) == NULL)) {
    free(str_copy);
    return 0;
  }
  free(str_copy);
  if (addr2 != NULL)
    addr_high->s_addr = ((struct in_addr *)addr2->h_addr)->s_addr;
  if (ntohl(addr_low->s_addr) > ntohl(addr_high->s_addr))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<parse_address_range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <inet_aton@plt>
cmp    $0x0,%rax
je     11ab <parse_address_range+0x4b>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    133e <parse_address_range+0x1de>
mov    -0x10(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     11e9 <parse_address_range+0x89>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    133e <parse_address_range+0x1de>
mov    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x2d,%esi
call   1040 <index@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1227 <parse_address_range+0xc7>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    133e <parse_address_range+0x1de>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <inet_aton@plt>
cmp    $0x0,%rax
jne    1271 <parse_address_range+0x111>
mov    -0x28(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1271 <parse_address_range+0x111>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    133e <parse_address_range+0x1de>
cmpq   $0x0,-0x38(%rbp)
je     1293 <parse_address_range+0x133>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
mov    -0x20(%rbp),%rsi
call   1060 <inet_aton@plt>
cmp    $0x0,%rax
jne    12de <parse_address_range+0x17e>
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    12de <parse_address_range+0x17e>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    133e <parse_address_range+0x1de>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x38(%rbp)
je     1301 <parse_address_range+0x1a1>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1070 <ntohl@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1070 <ntohl@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
jle    1337 <parse_address_range+0x1d7>
movl   $0x0,-0x4(%rbp)
jmp    133e <parse_address_range+0x1de>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_address_range>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%rbx
call   1060 <inet_aton@plt>
test   %rax,%rax
je     1182 <parse_address_range+0x22>
mov    0x0(%r13),%eax
jmp    1198 <parse_address_range+0x38>
mov    %rbx,%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     11aa <parse_address_range+0x4a>
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,0x0(%r13)
mov    %eax,(%r14)
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
call   1080 <strdup@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x2d,%esi
call   1040 <index@plt>
test   %rax,%rax
je     1211 <parse_address_range+0xb1>
mov    %rax,%r12
movb   $0x0,(%rax)
mov    %r15,%rdi
mov    %r13,%rsi
call   1060 <inet_aton@plt>
test   %rax,%rax
jne    11f3 <parse_address_range+0x93>
mov    %r15,%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     1211 <parse_address_range+0xb1>
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,0x0(%r13)
add    $0x1,%r12
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <inet_aton@plt>
test   %rax,%rax
je     121d <parse_address_range+0xbd>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    123d <parse_address_range+0xdd>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    11a0 <parse_address_range+0x40>
mov    %r12,%rdi
call   1050 <gethostbyname@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
test   %rbx,%rbx
je     1261 <parse_address_range+0x101>
mov    (%rbx),%rax
mov    (%rax),%eax
mov    %eax,(%r14)
mov    0x0(%r13),%edi
call   1070 <ntohl@plt>
mov    %rax,%rbx
mov    (%r14),%edi
call   1070 <ntohl@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rbx
setle  %al
jmp    11a0 <parse_address_range+0x40>
xor    %eax,%eax
jmp    11a0 <parse_address_range+0x40>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
define i32 @parse_address_range(i8* %0, %struct.in_addr* %1, %struct.in_addr* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.in_addr*
%7 = alloca %struct.in_addr*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca %struct.hostent*
store i8* %0, i8** %5
store %struct.in_addr* %1, %struct.in_addr** %6
store %struct.in_addr* %2, %struct.in_addr** %7
store %struct.hostent* null, %struct.hostent** %10
%11 = load i8*, i8** %5
%12 = load %struct.in_addr*, %struct.in_addr** %6
%13 = call i64 @inet_aton(i8* %11, %struct.in_addr* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %3
%16 = load %struct.in_addr*, %struct.in_addr** %6
%17 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = load %struct.in_addr*, %struct.in_addr** %7
%20 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %19, i32 0, i32 0
store i32 %18, i32* %20
store i32 1, i32* %4
br label %113
21: ; preds = %3
%22 = load i8*, i8** %5
%23 = call %struct.hostent* @gethostbyname(i8* %22)
store %struct.hostent* %23, %struct.hostent** %10
%24 = icmp ne %struct.hostent* %23, null
br i1 %24, label %25, label %39
25: ; preds = %21
%26 = load %struct.hostent*, %struct.hostent** %10
%27 = getelementptr inbounds %struct.hostent, %struct.hostent* %26, i32 0, i32 0
%28 = load i64, i64* %27
%29 = inttoptr i64 %28 to %struct.in_addr*
%30 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %29, i32 0, i32 0
%31 = load i32, i32* %30
%32 = load %struct.in_addr*, %struct.in_addr** %6
%33 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %32, i32 0, i32 0
store i32 %31, i32* %33
%34 = load %struct.in_addr*, %struct.in_addr** %6
%35 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = load %struct.in_addr*, %struct.in_addr** %7
%38 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %37, i32 0, i32 0
store i32 %36, i32* %38
store i32 1, i32* %4
br label %113
39: ; preds = %21
%40 = load i8*, i8** %5
%41 = call i8* @strdup(i8* %40)
store i8* %41, i8** %8
%42 = load i8*, i8** %8
%43 = call i8* @index(i8* %42, i8 signext 45)
store i8* %43, i8** %9
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %48
45: ; preds = %39
%46 = load i8*, i8** %8
%47 = call i32 @free(i8* %46)
store i32 0, i32* %4
br label %113
48: ; preds = %39
%49 = load i8*, i8** %9
store i8 0, i8* %49
%50 = load i8*, i8** %8
%51 = load %struct.in_addr*, %struct.in_addr** %6
%52 = call i64 @inet_aton(i8* %50, %struct.in_addr* %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %61, label %54
54: ; preds = %48
%55 = load i8*, i8** %8
%56 = call %struct.hostent* @gethostbyname(i8* %55)
store %struct.hostent* %56, %struct.hostent** %10
%57 = icmp eq %struct.hostent* %56, null
br i1 %57, label %58, label %61
58: ; preds = %54
%59 = load i8*, i8** %8
%60 = call i32 @free(i8* %59)
store i32 0, i32* %4
br label %113
61: ; preds = %54, %48
%62 = load %struct.hostent*, %struct.hostent** %10
%63 = icmp ne %struct.hostent* %62, null
br i1 %63, label %64, label %73
64: ; preds = %61
%65 = load %struct.hostent*, %struct.hostent** %10
%66 = getelementptr inbounds %struct.hostent, %struct.hostent* %65, i32 0, i32 0
%67 = load i64, i64* %66
%68 = inttoptr i64 %67 to %struct.in_addr*
%69 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %68, i32 0, i32 0
%70 = load i32, i32* %69
%71 = load %struct.in_addr*, %struct.in_addr** %6
%72 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %71, i32 0, i32 0
store i32 %70, i32* %72
store %struct.hostent* null, %struct.hostent** %10
br label %73
73: ; preds = %64, %61
%74 = load i8*, i8** %9
%75 = getelementptr inbounds i8, i8* %74, i64 1
%76 = load %struct.in_addr*, %struct.in_addr** %7
%77 = call i64 @inet_aton(i8* %75, %struct.in_addr* %76)
%78 = icmp ne i64 %77, 0
br i1 %78, label %87, label %79
79: ; preds = %73
%80 = load i8*, i8** %9
%81 = getelementptr inbounds i8, i8* %80, i64 1
%82 = call %struct.hostent* @gethostbyname(i8* %81)
store %struct.hostent* %82, %struct.hostent** %10
%83 = icmp eq %struct.hostent* %82, null
br i1 %83, label %84, label %87
84: ; preds = %79
%85 = load i8*, i8** %8
%86 = call i32 @free(i8* %85)
store i32 0, i32* %4
br label %113
87: ; preds = %79, %73
%88 = load i8*, i8** %8
%89 = call i32 @free(i8* %88)
%90 = load %struct.hostent*, %struct.hostent** %10
%91 = icmp ne %struct.hostent* %90, null
br i1 %91, label %92, label %101
92: ; preds = %87
%93 = load %struct.hostent*, %struct.hostent** %10
%94 = getelementptr inbounds %struct.hostent, %struct.hostent* %93, i32 0, i32 0
%95 = load i64, i64* %94
%96 = inttoptr i64 %95 to %struct.in_addr*
%97 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %96, i32 0, i32 0
%98 = load i32, i32* %97
%99 = load %struct.in_addr*, %struct.in_addr** %7
%100 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %99, i32 0, i32 0
store i32 %98, i32* %100
br label %101
101: ; preds = %92, %87
%102 = load %struct.in_addr*, %struct.in_addr** %6
%103 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %102, i32 0, i32 0
%104 = load i32, i32* %103
%105 = call i64 @ntohl(i32 %104)
%106 = load %struct.in_addr*, %struct.in_addr** %7
%107 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %106, i32 0, i32 0
%108 = load i32, i32* %107
%109 = call i64 @ntohl(i32 %108)
%110 = icmp sgt i64 %105, %109
br i1 %110, label %111, label %112
111: ; preds = %101
store i32 0, i32* %4
br label %113
112: ; preds = %101
store i32 1, i32* %4
br label %113
113: ; preds = %112, %111, %84, %58, %45, %25, %15
%114 = load i32, i32* %4
ret i32 %114
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
define i32 @parse_address_range(i8* %0, %struct.in_addr* %1, %struct.in_addr* %2) {
%4 = tail call i64 @inet_aton(i8* %0, %struct.in_addr* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %1, i64 0, i32 0
%8 = load i32, i32* %7
%9 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %2, i64 0, i32 0
store i32 %8, i32* %9
br label %68
10: ; preds = %3
%11 = tail call %struct.hostent* @gethostbyname(i8* %0)
%12 = icmp eq %struct.hostent* %11, null
br i1 %12, label %21, label %13
13: ; preds = %10
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %11, i64 0, i32 0
%15 = load i64, i64* %14
%16 = inttoptr i64 %15 to %struct.in_addr*
%17 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %16, i64 0, i32 0
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %1, i64 0, i32 0
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %2, i64 0, i32 0
store i32 %18, i32* %20
br label %68
21: ; preds = %10
%22 = tail call i8* @strdup(i8* %0)
%23 = tail call i8* @index(i8* %22, i8 signext 45)
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = tail call i32 @free(i8* %22)
br label %68
27: ; preds = %21
store i8 0, i8* %23
%28 = tail call i64 @inet_aton(i8* %22, %struct.in_addr* %1)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %42
30: ; preds = %27
%31 = tail call %struct.hostent* @gethostbyname(i8* %22)
%32 = icmp eq %struct.hostent* %31, null
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = tail call i32 @free(i8* %22)
br label %68
35: ; preds = %30
%36 = getelementptr inbounds %struct.hostent, %struct.hostent* %31, i64 0, i32 0
%37 = load i64, i64* %36
%38 = inttoptr i64 %37 to %struct.in_addr*
%39 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %38, i64 0, i32 0
%40 = load i32, i32* %39
%41 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %1, i64 0, i32 0
store i32 %40, i32* %41
br label %42
42: ; preds = %27, %35
%43 = getelementptr inbounds i8, i8* %23, i64 1
%44 = tail call i64 @inet_aton(i8* %43, %struct.in_addr* %2)
%45 = icmp eq i64 %44, 0
br i1 %45, label %48, label %46
46: ; preds = %42
%47 = tail call i32 @free(i8* %22)
br label %59
48: ; preds = %42
%49 = tail call %struct.hostent* @gethostbyname(i8* %43)
%50 = icmp eq %struct.hostent* %49, null
%51 = tail call i32 @free(i8* %22)
br i1 %50, label %68, label %52
52: ; preds = %48
%53 = getelementptr inbounds %struct.hostent, %struct.hostent* %49, i64 0, i32 0
%54 = load i64, i64* %53
%55 = inttoptr i64 %54 to %struct.in_addr*
%56 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %55, i64 0, i32 0
%57 = load i32, i32* %56
%58 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %2, i64 0, i32 0
store i32 %57, i32* %58
br label %59
59: ; preds = %46, %52
%60 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %1, i64 0, i32 0
%61 = load i32, i32* %60
%62 = tail call i64 @ntohl(i32 %61)
%63 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %2, i64 0, i32 0
%64 = load i32, i32* %63
%65 = tail call i64 @ntohl(i32 %64)
%66 = icmp sle i64 %62, %65
%67 = zext i1 %66 to i32
br label %68
68: ; preds = %48, %59, %33, %25, %13, %6
%69 = phi i32 [ 1, %6 ], [ 1, %13 ], [ 0, %25 ], [ 0, %33 ], [ %67, %59 ], [ 0, %48 ]
ret i32 %69
}