#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 sockaddr_in6 {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ assert(char const *);
int /*<<< orphan*/ free(char *);
int host_is_ipv6_with_port(char const *, char **, char **);
int inet_pton(int /*<<< orphan*/, char const *, struct sockaddr_in6 *);
scalar_t__ isdigit(char);
char *strchr(char const *, char);
char *strdup(char const *);
scalar_t__ strlen(char *);
int host_is_host_with_port(const char *host, char **addr, char **port) {
  char *str = NULL;
  int rv = -1;
  int is_host_with_port = 0;
  int ret;
  assert(host);
  if ((ret = host_is_ipv6_with_port(host, addr, port)) < 0)
    goto cleanup;
  if (ret) {
    rv = ret;
    goto cleanup;
  }
  if (strchr(host, ':')) {
    struct sockaddr_in6 saddr;
    char *addrptr;
    char *portptr;
    char *lastcolonptr = NULL;
    char *tmp;
    if (inet_pton(AF_INET6, host, &saddr) == 1)
      goto out;
    if (!(str = strdup(host)))
      goto cleanup;
    addrptr = str;
    portptr = addrptr;
    while ((tmp = strchr(portptr, ':'))) {
      lastcolonptr = tmp;
      portptr = tmp + 1;
    }
    *lastcolonptr = '\0';
    tmp = portptr;
    while (isdigit(*tmp))
      tmp++;
    if (*tmp == '\0' && strlen(portptr)) {
      is_host_with_port = 1;
      if (addr) {
        if (!(*addr = strdup(addrptr)))
          goto cleanup;
      }
      if (port) {
        if (!(*port = strdup(portptr))) {
          free(*addr);
          goto cleanup;
        }
      }
    }
  }
out:
  rv = is_host_with_port;
cleanup:
  free(str);
  return (rv);
}


x86 assembly (clang, -O0):
<host_is_host_with_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <host_is_ipv6_with_port@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    11d5 <host_is_host_with_port+0x55>
jmp    136e <host_is_host_with_port+0x1ee>
cmpl   $0x0,-0x2c(%rbp)
je     11ea <host_is_host_with_port+0x6a>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    136e <host_is_host_with_port+0x1ee>
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1070 <strchr@plt>
cmp    $0x0,%rax
je     1363 <host_is_host_with_port+0x1e3>
movq   $0x0,-0x48(%rbp)
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1090 <inet_pton@plt>
cmp    $0x1,%eax
jne    122e <host_is_host_with_port+0xae>
jmp    1368 <host_is_host_with_port+0x1e8>
mov    -0x8(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    124a <host_is_host_with_port+0xca>
jmp    136e <host_is_host_with_port+0x1ee>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    $0x3a,%esi
call   1070 <strchr@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
je     128f <host_is_host_with_port+0x10f>
mov    -0x50(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    125a <host_is_host_with_port+0xda>
mov    -0x48(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     12c5 <host_is_host_with_port+0x145>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    129e <host_is_host_with_port+0x11e>
mov    -0x50(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    135e <host_is_host_with_port+0x1de>
mov    -0x40(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x0,%rax
je     135e <host_is_host_with_port+0x1de>
movl   $0x1,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     131e <host_is_host_with_port+0x19e>
mov    -0x38(%rbp),%rdi
call   10a0 <strdup@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    1319 <host_is_host_with_port+0x199>
jmp    136e <host_is_host_with_port+0x1ee>
jmp    131e <host_is_host_with_port+0x19e>
cmpq   $0x0,-0x18(%rbp)
je     1359 <host_is_host_with_port+0x1d9>
mov    -0x40(%rbp),%rdi
call   10a0 <strdup@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    1354 <host_is_host_with_port+0x1d4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
jmp    136e <host_is_host_with_port+0x1ee>
jmp    1359 <host_is_host_with_port+0x1d9>
jmp    135e <host_is_host_with_port+0x1de>
jmp    1363 <host_is_host_with_port+0x1e3>
jmp    1368 <host_is_host_with_port+0x1e8>
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<host_is_host_with_port>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%rbx
call   1070 <assert@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <host_is_ipv6_with_port@plt>
mov    $0xffffffff,%ebp
xor    %r14d,%r14d
test   %eax,%eax
js     11a9 <host_is_host_with_port+0x39>
test   %eax,%eax
je     11c2 <host_is_host_with_port+0x52>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     11f6 <host_is_host_with_port+0x86>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rdx
mov    %rbx,%rsi
call   1080 <inet_pton@plt>
cmp    $0x1,%eax
jne    11fa <host_is_host_with_port+0x8a>
xor    %eax,%eax
xor    %r14d,%r14d
mov    %eax,%ebp
jmp    11a9 <host_is_host_with_port+0x39>
xor    %ebp,%ebp
jmp    11a9 <host_is_host_with_port+0x39>
mov    %rbx,%rdi
call   1090 <strdup@plt>
mov    %rax,%r14
test   %rax,%rax
je     11a9 <host_is_host_with_port+0x39>
xor    %eax,%eax
mov    %r14,%rcx
nop
mov    %rax,%rbx
mov    %rcx,%r13
mov    %rcx,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
lea    0x1(%rax),%rcx
test   %rax,%rax
jne    1210 <host_is_host_with_port+0xa0>
movb   $0x0,(%rbx)
mov    %r13,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl (%rbx),%edi
call   1040 <isdigit@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1240 <host_is_host_with_port+0xd0>
xor    %eax,%eax
cmpb   $0x0,-0x1(%rbx)
je     1260 <host_is_host_with_port+0xf0>
mov    %eax,%ebp
jmp    11a9 <host_is_host_with_port+0x39>
cmpb   $0x0,0x0(%r13)
je     1259 <host_is_host_with_port+0xe9>
test   %r15,%r15
je     1280 <host_is_host_with_port+0x110>
mov    %r14,%rdi
call   1090 <strdup@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     11a9 <host_is_host_with_port+0x39>
mov    $0x1,%eax
test   %r12,%r12
je     1259 <host_is_host_with_port+0xe9>
mov    %r13,%rdi
call   1090 <strdup@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     12a2 <host_is_host_with_port+0x132>
mov    $0x1,%eax
jmp    1259 <host_is_host_with_port+0xe9>
mov    (%r15),%rdi
call   1030 <free@plt>
jmp    11a9 <host_is_host_with_port+0x39>

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

LLVM IR (-O2):
%struct.sockaddr_in6 = type { i32 }
@AF_INET6 = global i32 0
define i32 @host_is_host_with_port(i8* %0, i8** %1, i8** %2) {
%4 = alloca %struct.sockaddr_in6
%5 = tail call i32 @assert(i8* %0)
%6 = tail call i32 @host_is_ipv6_with_port(i8* %0, i8** %1, i8** %2)
%7 = icmp slt i32 %6, 0
br i1 %7, label %57, label %8
8: ; preds = %3
%9 = icmp eq i32 %6, 0
br i1 %9, label %10, label %57
10: ; preds = %8
%11 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%12 = icmp eq i8* %11, null
br i1 %12, label %57, label %13
13: ; preds = %10
%14 = bitcast %struct.sockaddr_in6* %4 to i8*
%15 = load i32, i32* @AF_INET6
%16 = call i32 @inet_pton(i32 %15, i8* %0, %struct.sockaddr_in6* %4)
%17 = icmp eq i32 %16, 1
br i1 %17, label %53, label %18
18: ; preds = %13
%19 = call i8* @strdup(i8* %0)
%20 = icmp eq i8* %19, null
br i1 %20, label %56, label %21
21: ; preds = %18, %21
%22 = phi i8* [ %26, %21 ], [ %19, %18 ]
%23 = phi i8* [ %24, %21 ], [ null, %18 ]
%24 = call i8* @strchr(i8* %22, i8 signext 58)
%25 = icmp eq i8* %24, null
%26 = getelementptr inbounds i8, i8* %24, i64 1
br i1 %25, label %27, label %21
27: ; preds = %21
store i8 0, i8* %23
br label %28
28: ; preds = %28, %27
%29 = phi i8* [ %22, %27 ], [ %33, %28 ]
%30 = load i8, i8* %29
%31 = call i64 @isdigit(i8 signext %30)
%32 = icmp eq i64 %31, 0
%33 = getelementptr inbounds i8, i8* %29, i64 1
br i1 %32, label %34, label %28
34: ; preds = %28
%35 = load i8, i8* %29
%36 = icmp eq i8 %35, 0
br i1 %36, label %37, label %53
37: ; preds = %34
%38 = load i8, i8* %22
%39 = icmp eq i8 %38, 0
br i1 %39, label %53, label %40
40: ; preds = %37
%41 = icmp eq i8** %1, null
br i1 %41, label %45, label %42
42: ; preds = %40
%43 = call i8* @strdup(i8* %19)
store i8* %43, i8** %1
%44 = icmp eq i8* %43, null
br i1 %44, label %56, label %45
45: ; preds = %42, %40
%46 = icmp eq i8** %2, null
br i1 %46, label %53, label %47
47: ; preds = %45
%48 = call i8* @strdup(i8* %22)
store i8* %48, i8** %2
%49 = icmp eq i8* %48, null
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = load i8*, i8** %1
%52 = call i32 @free(i8* %51)
br label %56
53: ; preds = %13, %45, %47, %37, %34
%54 = phi i32 [ 0, %34 ], [ 0, %37 ], [ 1, %45 ], [ 1, %47 ], [ 0, %13 ]
%55 = phi i8* [ %19, %34 ], [ %19, %37 ], [ %19, %45 ], [ %19, %47 ], [ null, %13 ]
br label %57
56: ; preds = %42, %18, %50
br label %57
57: ; preds = %3, %8, %56, %53, %10
%58 = phi i32 [ -1, %3 ], [ -1, %56 ], [ %6, %8 ], [ 0, %10 ], [ %54, %53 ]
%59 = phi i8* [ null, %3 ], [ %19, %56 ], [ null, %8 ], [ null, %10 ], [ %55, %53 ]
%60 = call i32 @free(i8* %59)
ret i32 %58
}