#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 dummy;
};
struct sockaddr_in {
  scalar_t__ sin_family;
  int /*<<< orphan*/ sin_port;
  struct in_addr sin_addr;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addrtype;
  scalar_t__ h_addr;
};

/* Variables and functions */
scalar_t__ AF_INET;
int atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_aton(char *, struct in_addr *);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
char *strdup(char *);
int strtoul(char *, char **, int);
int net_address(struct sockaddr *sa, char *name, int port, int flags) {
  struct hostent *he;
  struct sockaddr_in *sai;
  char *ptr, *host, *copy, *end;
  int p, t, result;
  if (sa == NULL) {
    return -1;
  }
  sai = (struct sockaddr_in *)sa;
  p = port;
  if (name == NULL) {
    return -1;
  }
  copy = strdup(name);
  if (copy == NULL) {
    if (flags & 0x01) {
      fprintf(stderr, "address: internal allocation failure\n");
    }
    return -1;
  }
  result = 0;
  ptr = strchr(copy, ':');
  if (ptr) {
    p = atoi(ptr + 1);
    if (ptr == copy) {
      host = NULL;
    } else {
      host = copy;
      ptr[0] = '\0';
    }
  } else {
    ptr = strchr(copy, '.');
    if (ptr) {
      host = copy;
    } else {
      t = strtoul(copy, &end, 10);
      if (end[0] == '\0') {
        p = t;
        host = NULL;
      } else {
        host = copy;
      }
    }
  }
  if (host) {
    if (inet_aton(host, &(sai->sin_addr)) == 0) {
      he = gethostbyname(host);
      if ((he == NULL) || (he->h_addrtype != AF_INET)) {
        if (flags & 0x01) {
          fprintf(stderr, "address: unable to resolve %s to ipv4 address\n",
                  host);
        }
        result = (-1);
      } else {
        sai->sin_addr = *(struct in_addr *)he->h_addr;
      }
    }
  } else {
    result = 1;
  }
  free(copy);
  if (p > 0) {
    if (p > 0xffff) {
      if (flags & 0x01) {
        fprintf(stderr, "address: port %d unreasonably large\n", p);
      }
      result = (-1);
    } else {
      sai->sin_port = htons(p);
    }
  } else {
    if (result == 0) {
      result = 1;
    }
  }
  sai->sin_family = AF_INET;
  return result;
}


x86 assembly (clang, -O0):
<net_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11bd <net_address+0x2d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1448 <net_address+0x2b8>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x54(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e2 <net_address+0x52>
movl   $0xffffffff,-0x4(%rbp)
jmp    1448 <net_address+0x2b8>
mov    -0x18(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    122c <net_address+0x9c>
mov    -0x20(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1220 <net_address+0x90>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xde7(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1448 <net_address+0x2b8>
movl   $0x0,-0x5c(%rbp)
mov    -0x48(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     128f <net_address+0xff>
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x54(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x48(%rbp),%rax
jne    127b <net_address+0xeb>
movq   $0x0,-0x40(%rbp)
jmp    128a <net_address+0xfa>
mov    -0x48(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
jmp    1303 <net_address+0x173>
mov    -0x48(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     12b9 <net_address+0x129>
mov    -0x48(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    12fe <net_address+0x16e>
mov    -0x48(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0xa,%edx
call   1090 <strtoul@plt>
mov    %eax,-0x58(%rbp)
mov    -0x50(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    12f1 <net_address+0x161>
mov    -0x58(%rbp),%eax
mov    %eax,-0x54(%rbp)
movq   $0x0,-0x40(%rbp)
jmp    12f9 <net_address+0x169>
mov    -0x48(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    12fe <net_address+0x16e>
jmp    1303 <net_address+0x173>
cmpq   $0x0,-0x40(%rbp)
je     13a9 <net_address+0x219>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
add    $0xc,%rsi
call   1080 <inet_aton@plt>
cmp    $0x0,%rax
jne    13a4 <net_address+0x214>
mov    -0x40(%rbp),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1358 <net_address+0x1c8>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    0x2c99(%rip),%rcx
cmp    (%rcx),%rax
je     138e <net_address+0x1fe>
mov    -0x20(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1382 <net_address+0x1f2>
mov    0x2c6a(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rdx
lea    0xcab(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x5c(%rbp)
jmp    139f <net_address+0x20f>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    0x8(%rcx),%rcx
mov    (%rcx),%ecx
mov    %ecx,0xc(%rax)
jmp    13a4 <net_address+0x214>
jmp    13b0 <net_address+0x220>
movl   $0x1,-0x5c(%rbp)
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x54(%rbp)
jle    141b <net_address+0x28b>
cmpl   $0xffff,-0x54(%rbp)
jle    1405 <net_address+0x275>
mov    -0x20(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     13f9 <net_address+0x269>
mov    0x2bf2(%rip),%rax
mov    (%rax),%edi
mov    -0x54(%rbp),%edx
lea    0xc63(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x5c(%rbp)
jmp    1416 <net_address+0x286>
mov    -0x54(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,0x8(%rax)
jmp    1431 <net_address+0x2a1>
cmpl   $0x0,-0x5c(%rbp)
jne    142c <net_address+0x29c>
movl   $0x1,-0x5c(%rbp)
jmp    1431 <net_address+0x2a1>
mov    0x2bb0(%rip),%rax
mov    (%rax),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x5c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<net_address>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     1332 <net_address+0x1a2>
test   %rsi,%rsi
je     1332 <net_address+0x1a2>
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %rdi,%r12
mov    %rsi,%rdi
call   10b0 <strdup@plt>
test   %rax,%rax
je     11fb <net_address+0x6b>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1221 <net_address+0x91>
mov    %rax,%rbp
lea    0x1(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r15d
cmp    %rbx,%rbp
je     1297 <net_address+0x107>
movb   $0x0,0x0(%rbp)
jmp    1250 <net_address+0xc0>
test   $0x1,%r14b
je     1332 <net_address+0x1a2>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
lea    0xdeb(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1332 <net_address+0x1a2>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
test   %rax,%rax
jne    1250 <net_address+0xc0>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1090 <strtoul@plt>
mov    (%rsp),%rcx
cmpb   $0x0,(%rcx)
je     1343 <net_address+0x1b3>
lea    0xc(%r12),%r13
mov    %rbx,%rdi
mov    %r13,%rsi
call   1080 <inet_aton@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     126f <net_address+0xdf>
xor    %r13d,%r13d
jmp    12d7 <net_address+0x147>
mov    %rbx,%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     12a4 <net_address+0x114>
mov    (%rax),%rcx
mov    0x2d62(%rip),%rdx
cmp    (%rdx),%rcx
jne    12a4 <net_address+0x114>
mov    0x8(%rax),%rax
mov    (%rax),%eax
mov    %eax,0x0(%r13)
jmp    126a <net_address+0xda>
mov    $0x1,%ebp
mov    $0x1,%r13d
jmp    12d7 <net_address+0x147>
mov    $0xffffffff,%ebp
test   $0x1,%r14b
jne    12b7 <net_address+0x127>
mov    $0xffffffff,%r13d
jmp    12d7 <net_address+0x147>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
lea    0xd5f(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%r13d
mov    %rbx,%rdi
call   1030 <free@plt>
test   %r15d,%r15d
jle    1324 <net_address+0x194>
cmp    $0x10000,%r15d
jb     1314 <net_address+0x184>
mov    $0xffffffff,%ebp
test   $0x1,%r14b
je     1324 <net_address+0x194>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
lea    0xd4d(%rip),%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1324 <net_address+0x194>
mov    %r15d,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%r12)
mov    %r13d,%ebp
mov    0x2cbd(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%r12)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebp
mov    %eax,%r15d
jmp    129c <net_address+0x10c>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.hostent = type { i64, i64 }
%struct.sockaddr_in = type { i64, i32, %struct.in_addr }
%struct.in_addr = type { i32 }
@stderr = global i32 0
@.str = [38 x i8] c"address: internal allocation failure\0A\00"
@AF_INET = global i64 0
@.str.1 = [47 x i8] c"address: unable to resolve %s to ipv4 address\0A\00"
@.str.2 = [37 x i8] c"address: port %d unreasonably large\0A\00"
define i32 @net_address(%struct.sockaddr* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.sockaddr*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.hostent*
%11 = alloca %struct.sockaddr_in*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store %struct.sockaddr* %0, %struct.sockaddr** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%19 = load %struct.sockaddr*, %struct.sockaddr** %6
%20 = icmp eq %struct.sockaddr* %19, null
br i1 %20, label %21, label %22
21: ; preds = %4
store i32 -1, i32* %5
br label %155
22: ; preds = %4
%23 = load %struct.sockaddr*, %struct.sockaddr** %6
%24 = bitcast %struct.sockaddr* %23 to %struct.sockaddr_in*
store %struct.sockaddr_in* %24, %struct.sockaddr_in** %11
%25 = load i32, i32* %8
store i32 %25, i32* %16
%26 = load i8*, i8** %7
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %29
28: ; preds = %22
store i32 -1, i32* %5
br label %155
29: ; preds = %22
%30 = load i8*, i8** %7
%31 = call i8* @strdup(i8* %30)
store i8* %31, i8** %14
%32 = load i8*, i8** %14
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %42
34: ; preds = %29
%35 = load i32, i32* %9
%36 = and i32 %35, 1
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %41
41: ; preds = %38, %34
store i32 -1, i32* %5
br label %155
42: ; preds = %29
store i32 0, i32* %18
%43 = load i8*, i8** %14
%44 = call i8* @strchr(i8* %43, i8 signext 58)
store i8* %44, i8** %12
%45 = load i8*, i8** %12
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %60
47: ; preds = %42
%48 = load i8*, i8** %12
%49 = getelementptr inbounds i8, i8* %48, i64 1
%50 = call i32 @atoi(i8* %49)
store i32 %50, i32* %16
%51 = load i8*, i8** %12
%52 = load i8*, i8** %14
%53 = icmp eq i8* %51, %52
br i1 %53, label %54, label %55
54: ; preds = %47
store i8* null, i8** %13
br label %59
55: ; preds = %47
%56 = load i8*, i8** %14
store i8* %56, i8** %13
%57 = load i8*, i8** %12
%58 = getelementptr inbounds i8, i8* %57, i64 0
store i8 0, i8* %58
br label %59
59: ; preds = %55, %54
br label %81
60: ; preds = %42
%61 = load i8*, i8** %14
%62 = call i8* @strchr(i8* %61, i8 signext 46)
store i8* %62, i8** %12
%63 = load i8*, i8** %12
%64 = icmp ne i8* %63, null
br i1 %64, label %65, label %67
65: ; preds = %60
%66 = load i8*, i8** %14
store i8* %66, i8** %13
br label %80
67: ; preds = %60
%68 = load i8*, i8** %14
%69 = call i32 @strtoul(i8* %68, i8** %15, i32 10)
store i32 %69, i32* %17
%70 = load i8*, i8** %15
%71 = getelementptr inbounds i8, i8* %70, i64 0
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = icmp eq i32 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %67
%76 = load i32, i32* %17
store i32 %76, i32* %16
store i8* null, i8** %13
br label %79
77: ; preds = %67
%78 = load i8*, i8** %14
store i8* %78, i8** %13
br label %79
79: ; preds = %77, %75
br label %80
80: ; preds = %79, %65
br label %81
81: ; preds = %80, %59
%82 = load i8*, i8** %13
%83 = icmp ne i8* %82, null
br i1 %83, label %84, label %121
84: ; preds = %81
%85 = load i8*, i8** %13
%86 = load %struct.sockaddr_in*, %struct.sockaddr_in** %11
%87 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %86, i32 0, i32 2
%88 = call i64 @inet_aton(i8* %85, %struct.in_addr* %87)
%89 = icmp eq i64 %88, 0
br i1 %89, label %90, label %120
90: ; preds = %84
%91 = load i8*, i8** %13
%92 = call %struct.hostent* @gethostbyname(i8* %91)
store %struct.hostent* %92, %struct.hostent** %10
%93 = load %struct.hostent*, %struct.hostent** %10
%94 = icmp eq %struct.hostent* %93, null
br i1 %94, label %101, label %95
95: ; preds = %90
%96 = load %struct.hostent*, %struct.hostent** %10
%97 = getelementptr inbounds %struct.hostent, %struct.hostent* %96, i32 0, i32 0
%98 = load i64, i64* %97
%99 = load i64, i64* @AF_INET
%100 = icmp ne i64 %98, %99
br i1 %100, label %101, label %110
101: ; preds = %95, %90
%102 = load i32, i32* %9
%103 = and i32 %102, 1
%104 = icmp ne i32 %103, 0
br i1 %104, label %105, label %109
105: ; preds = %101
%106 = load i32, i32* @stderr
%107 = load i8*, i8** %13
%108 = call i32 (i32, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i8* %107)
br label %109
109: ; preds = %105, %101
store i32 -1, i32* %18
br label %119
110: ; preds = %95
%111 = load %struct.sockaddr_in*, %struct.sockaddr_in** %11
%112 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %111, i32 0, i32 2
%113 = load %struct.hostent*, %struct.hostent** %10
%114 = getelementptr inbounds %struct.hostent, %struct.hostent* %113, i32 0, i32 1
%115 = load i64, i64* %114
%116 = inttoptr i64 %115 to %struct.in_addr*
%117 = bitcast %struct.in_addr* %112 to i8*
%118 = bitcast %struct.in_addr* %116 to i8*
br label %119
119: ; preds = %110, %109
br label %120
120: ; preds = %119, %84
br label %122
121: ; preds = %81
store i32 1, i32* %18
br label %122
122: ; preds = %121, %120
%123 = load i8*, i8** %14
%124 = call i32 @free(i8* %123)
%125 = load i32, i32* %16
%126 = icmp sgt i32 %125, 0
br i1 %126, label %127, label %145
127: ; preds = %122
%128 = load i32, i32* %16
%129 = icmp sgt i32 %128, 65535
br i1 %129, label %130, label %139
130: ; preds = %127
%131 = load i32, i32* %9
%132 = and i32 %131, 1
%133 = icmp ne i32 %132, 0
br i1 %133, label %134, label %138
134: ; preds = %130
%135 = load i32, i32* @stderr
%136 = load i32, i32* %16
%137 = call i32 (i32, i8*, ...) @fprintf(i32 %135, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %136)
br label %138
138: ; preds = %134, %130
store i32 -1, i32* %18
br label %144
139: ; preds = %127
%140 = load i32, i32* %16
%141 = call i32 @htons(i32 %140)
%142 = load %struct.sockaddr_in*, %struct.sockaddr_in** %11
%143 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %142, i32 0, i32 1
store i32 %141, i32* %143
br label %144
144: ; preds = %139, %138
br label %150
145: ; preds = %122
%146 = load i32, i32* %18
%147 = icmp eq i32 %146, 0
br i1 %147, label %148, label %149
148: ; preds = %145
store i32 1, i32* %18
br label %149
149: ; preds = %148, %145
br label %150
150: ; preds = %149, %144
%151 = load i64, i64* @AF_INET
%152 = load %struct.sockaddr_in*, %struct.sockaddr_in** %11
%153 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %152, i32 0, i32 0
store i64 %151, i64* %153
%154 = load i32, i32* %18
store i32 %154, i32* %5
br label %155
155: ; preds = %150, %41, %28, %21
%156 = load i32, i32* %5
ret i32 %156
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64, i64 }
@stderr = global i32 0
@.str = [38 x i8] c"address: internal allocation failure\0A\00"
@AF_INET = global i64 0
@.str.1 = [47 x i8] c"address: unable to resolve %s to ipv4 address\0A\00"
@.str.2 = [37 x i8] c"address: port %d unreasonably large\0A\00"
define i32 @net_address(%struct.sockaddr* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
%7 = icmp eq %struct.sockaddr* %0, null
%8 = icmp eq i8* %1, null
%9 = or i1 %7, %8
br i1 %9, label %82, label %10
10: ; preds = %4
%11 = tail call i8* @strdup(i8* %1)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = and i32 %3, 1
%15 = icmp eq i32 %14, 0
br i1 %15, label %82, label %16
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %82
19: ; preds = %10
%20 = tail call i8* @strchr(i8* %11, i8 signext 58)
%21 = icmp eq i8* %20, null
br i1 %21, label %27, label %22
22: ; preds = %19
%23 = getelementptr inbounds i8, i8* %20, i64 1
%24 = tail call i32 @atoi(i8* %23)
%25 = icmp eq i8* %20, %11
br i1 %25, label %61, label %26
26: ; preds = %22
store i8 0, i8* %20
br label %35
27: ; preds = %19
%28 = tail call i8* @strchr(i8* %11, i8 signext 46)
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = call i32 @strtoul(i8* %11, i8** %5, i32 10)
%32 = load i8*, i8** %5
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 0
br i1 %34, label %61, label %35
35: ; preds = %26, %27, %30
%36 = phi i32 [ %2, %30 ], [ %2, %27 ], [ %24, %26 ]
%37 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 3
%38 = bitcast %struct.sockaddr* %37 to %struct.in_addr*
%39 = tail call i64 @inet_aton(i8* %11, %struct.in_addr* %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %61
41: ; preds = %35
%42 = tail call %struct.hostent* @gethostbyname(i8* %11)
%43 = icmp eq %struct.hostent* %42, null
br i1 %43, label %49, label %44
44: ; preds = %41
%45 = getelementptr inbounds %struct.hostent, %struct.hostent* %42, i64 0, i32 0
%46 = load i64, i64* %45
%47 = load i64, i64* @AF_INET
%48 = icmp eq i64 %46, %47
br i1 %48, label %55, label %49
49: ; preds = %44, %41
%50 = and i32 %3, 1
%51 = icmp eq i32 %50, 0
br i1 %51, label %61, label %52
52: ; preds = %49
%53 = load i32, i32* @stderr
%54 = tail call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %61
55: ; preds = %44
%56 = getelementptr inbounds %struct.hostent, %struct.hostent* %42, i64 0, i32 1
%57 = load i64, i64* %56
%58 = inttoptr i64 %57 to i32*
%59 = getelementptr %struct.sockaddr, %struct.sockaddr* %37, i64 0, i32 0
%60 = load i32, i32* %58
store i32 %60, i32* %59
br label %61
61: ; preds = %30, %22, %49, %52, %35, %55
%62 = phi i32 [ %36, %35 ], [ %36, %55 ], [ %36, %52 ], [ %36, %49 ], [ %24, %22 ], [ %31, %30 ]
%63 = phi i32 [ 1, %35 ], [ 1, %55 ], [ -1, %52 ], [ -1, %49 ], [ 1, %22 ], [ 1, %30 ]
%64 = phi i32 [ 0, %35 ], [ 0, %55 ], [ -1, %52 ], [ -1, %49 ], [ 1, %22 ], [ 1, %30 ]
%65 = tail call i32 @free(i8* %11)
%66 = icmp sgt i32 %62, 0
br i1 %66, label %67, label %78
67: ; preds = %61
%68 = icmp ugt i32 %62, 65535
br i1 %68, label %69, label %75
69: ; preds = %67
%70 = and i32 %3, 1
%71 = icmp eq i32 %70, 0
br i1 %71, label %78, label %72
72: ; preds = %69
%73 = load i32, i32* @stderr
%74 = tail call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %62)
br label %78
75: ; preds = %67
%76 = tail call i32 @htons(i32 %62)
%77 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 2, i32 0
store i32 %76, i32* %77
br label %78
78: ; preds = %61, %69, %72, %75
%79 = phi i32 [ %64, %75 ], [ -1, %72 ], [ -1, %69 ], [ %63, %61 ]
%80 = load i64, i64* @AF_INET
%81 = bitcast %struct.sockaddr* %0 to i64*
store i64 %80, i64* %81
br label %82
82: ; preds = %13, %16, %4, %78
%83 = phi i32 [ %79, %78 ], [ -1, %4 ], [ -1, %16 ], [ -1, %13 ]
ret i32 %83
}