#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_storage {
  scalar_t__ ss_family;
};
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_addr;
  void *sin6_port;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  void *sin_port;
};

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
int /*<<< orphan*/ atoi(char *);
void *htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_pton(scalar_t__, char *, void *);
scalar_t__ strchr(char *, char);
scalar_t__ strstr(char *, char *);
int inet_stosockaddr(char *ip, char *port, struct sockaddr_storage *addr) {
  void *addr_ip;
  char *cp = ip;
  addr->ss_family = (strchr(ip, ':')) ? AF_INET6 : AF_INET;
  if (strstr(ip, "-")) {
    while (*cp != '-' && *cp != '\0')
      cp++;
    if (*cp == '-')
      *cp = 0;
  } else if (strstr(ip, "/")) {
    while (*cp != '/' && *cp != '\0')
      cp++;
    if (*cp == '/')
      *cp = 0;
  }
  if (addr->ss_family == AF_INET6) {
    struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)addr;
    if (port)
      addr6->sin6_port = htons(atoi(port));
    addr_ip = &addr6->sin6_addr;
  } else {
    struct sockaddr_in *addr4 = (struct sockaddr_in *)addr;
    if (port)
      addr4->sin_port = htons(atoi(port));
    addr_ip = &addr4->sin_addr;
  }
  if (!inet_pton(addr->ss_family, ip, addr_ip))
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<inet_stosockaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     1197 <inet_stosockaddr+0x47>
mov    0x2e55(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
jmp    11a5 <inet_stosockaddr+0x55>
mov    0x2e4a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     1231 <inet_stosockaddr+0xe1>
jmp    11cf <inet_stosockaddr+0x7f>
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2d,%ecx
mov    %al,-0x49(%rbp)
je     11f4 <inet_stosockaddr+0xa4>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    1204 <inet_stosockaddr+0xb4>
jmp    1215 <inet_stosockaddr+0xc5>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11cf <inet_stosockaddr+0x7f>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    122c <inet_stosockaddr+0xdc>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
jmp    12b7 <inet_stosockaddr+0x167>
mov    -0x10(%rbp),%rdi
lea    0xdc6(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     12b2 <inet_stosockaddr+0x162>
jmp    1250 <inet_stosockaddr+0x100>
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x4a(%rbp)
je     1275 <inet_stosockaddr+0x125>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x4a(%rbp)
mov    -0x4a(%rbp),%al
test   $0x1,%al
jne    1285 <inet_stosockaddr+0x135>
jmp    1296 <inet_stosockaddr+0x146>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1250 <inet_stosockaddr+0x100>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    12ad <inet_stosockaddr+0x15d>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
jmp    12b2 <inet_stosockaddr+0x162>
jmp    12b7 <inet_stosockaddr+0x167>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2d1b(%rip),%rcx
cmp    (%rcx),%rax
jne    1309 <inet_stosockaddr+0x1b9>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12fc <inet_stosockaddr+0x1ac>
mov    -0x18(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    133f <inet_stosockaddr+0x1ef>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1337 <inet_stosockaddr+0x1e7>
mov    -0x18(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x40(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <inet_pton@plt>
cmp    $0x0,%eax
jne    1368 <inet_stosockaddr+0x218>
movl   $0xffffffff,-0x4(%rbp)
jmp    136f <inet_stosockaddr+0x21f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet_stosockaddr>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    1176 <inet_stosockaddr+0x26>
mov    0x2e74(%rip),%rax
jmp    117d <inet_stosockaddr+0x2d>
mov    0x2e63(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%r14)
lea    0xe76(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strstr@plt>
test   %rax,%rax
je     11b2 <inet_stosockaddr+0x62>
mov    %rbx,%rax
nopw   0x0(%rax,%rax,1)
movzbl (%rax),%ecx
test   %cl,%cl
je     11e5 <inet_stosockaddr+0x95>
cmp    $0x2d,%cl
je     11e2 <inet_stosockaddr+0x92>
add    $0x1,%rax
jmp    11a0 <inet_stosockaddr+0x50>
lea    0xe49(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strstr@plt>
test   %rax,%rax
je     11e5 <inet_stosockaddr+0x95>
mov    %rbx,%rax
nopl   0x0(%rax)
movzbl (%rax),%ecx
test   %cl,%cl
je     11e5 <inet_stosockaddr+0x95>
cmp    $0x2f,%cl
je     11e2 <inet_stosockaddr+0x92>
add    $0x1,%rax
jmp    11d0 <inet_stosockaddr+0x80>
movb   $0x0,(%rax)
test   %r15,%r15
je     11fd <inet_stosockaddr+0xad>
mov    %r15,%rdi
call   1060 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %rax,0x8(%r14)
mov    (%r14),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <inet_pton@plt>
cmp    $0x1,%eax
sbb    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_storage = type { i64 }
%struct.sockaddr_in6 = type { i32, i8* }
%struct.sockaddr_in = type { i32, i8* }
@AF_INET6 = global i64 0
@AF_INET = global i64 0
@.str = [2 x i8] c"-\00"
@.str.1 = [2 x i8] c"/\00"
define i32 @inet_stosockaddr(i8* %0, i8* %1, %struct.sockaddr_storage* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca %struct.sockaddr_storage*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca %struct.sockaddr_in6*
%11 = alloca %struct.sockaddr_in*
store i8* %0, i8** %5
store i8* %1, i8** %6
store %struct.sockaddr_storage* %2, %struct.sockaddr_storage** %7
%12 = load i8*, i8** %5
store i8* %12, i8** %9
%13 = load i8*, i8** %5
%14 = call i64 @strchr(i8* %13, i8 signext 58)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = load i64, i64* @AF_INET6
br label %20
18: ; preds = %3
%19 = load i64, i64* @AF_INET
br label %20
20: ; preds = %18, %16
%21 = phi i64 [ %17, %16 ], [ %19, %18 ]
%22 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %7
%23 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %22, i32 0, i32 0
store i64 %21, i64* %23
%24 = load i8*, i8** %5
%25 = call i64 @strstr(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %51
27: ; preds = %20
br label %28
28: ; preds = %40, %27
%29 = load i8*, i8** %9
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 45
br i1 %32, label %33, label %38
33: ; preds = %28
%34 = load i8*, i8** %9
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 0
br label %38
38: ; preds = %33, %28
%39 = phi i1 [ false, %28 ], [ %37, %33 ]
br i1 %39, label %40, label %43
40: ; preds = %38
%41 = load i8*, i8** %9
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %9
br label %28
43: ; preds = %38
%44 = load i8*, i8** %9
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 45
br i1 %47, label %48, label %50
48: ; preds = %43
%49 = load i8*, i8** %9
store i8 0, i8* %49
br label %50
50: ; preds = %48, %43
br label %80
51: ; preds = %20
%52 = load i8*, i8** %5
%53 = call i64 @strstr(i8* %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %79
55: ; preds = %51
br label %56
56: ; preds = %68, %55
%57 = load i8*, i8** %9
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp ne i32 %59, 47
br i1 %60, label %61, label %66
61: ; preds = %56
%62 = load i8*, i8** %9
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = icmp ne i32 %64, 0
br label %66
66: ; preds = %61, %56
%67 = phi i1 [ false, %56 ], [ %65, %61 ]
br i1 %67, label %68, label %71
68: ; preds = %66
%69 = load i8*, i8** %9
%70 = getelementptr inbounds i8, i8* %69, i32 1
store i8* %70, i8** %9
br label %56
71: ; preds = %66
%72 = load i8*, i8** %9
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp eq i32 %74, 47
br i1 %75, label %76, label %78
76: ; preds = %71
%77 = load i8*, i8** %9
store i8 0, i8* %77
br label %78
78: ; preds = %76, %71
br label %79
79: ; preds = %78, %51
br label %80
80: ; preds = %79, %50
%81 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %7
%82 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %81, i32 0, i32 0
%83 = load i64, i64* %82
%84 = load i64, i64* @AF_INET6
%85 = icmp eq i64 %83, %84
br i1 %85, label %86, label %101
86: ; preds = %80
%87 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %7
%88 = bitcast %struct.sockaddr_storage* %87 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %88, %struct.sockaddr_in6** %10
%89 = load i8*, i8** %6
%90 = icmp ne i8* %89, null
br i1 %90, label %91, label %97
91: ; preds = %86
%92 = load i8*, i8** %6
%93 = call i32 @atoi(i8* %92)
%94 = call i8* @htons(i32 %93)
%95 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %10
%96 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %95, i32 0, i32 1
store i8* %94, i8** %96
br label %97
97: ; preds = %91, %86
%98 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %10
%99 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %98, i32 0, i32 0
%100 = bitcast i32* %99 to i8*
store i8* %100, i8** %8
br label %116
101: ; preds = %80
%102 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %7
%103 = bitcast %struct.sockaddr_storage* %102 to %struct.sockaddr_in*
store %struct.sockaddr_in* %103, %struct.sockaddr_in** %11
%104 = load i8*, i8** %6
%105 = icmp ne i8* %104, null
br i1 %105, label %106, label %112
106: ; preds = %101
%107 = load i8*, i8** %6
%108 = call i32 @atoi(i8* %107)
%109 = call i8* @htons(i32 %108)
%110 = load %struct.sockaddr_in*, %struct.sockaddr_in** %11
%111 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %110, i32 0, i32 1
store i8* %109, i8** %111
br label %112
112: ; preds = %106, %101
%113 = load %struct.sockaddr_in*, %struct.sockaddr_in** %11
%114 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %113, i32 0, i32 0
%115 = bitcast i32* %114 to i8*
store i8* %115, i8** %8
br label %116
116: ; preds = %112, %97
%117 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %7
%118 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %117, i32 0, i32 0
%119 = load i64, i64* %118
%120 = load i8*, i8** %5
%121 = load i8*, i8** %8
%122 = call i32 @inet_pton(i64 %119, i8* %120, i8* %121)
%123 = icmp ne i32 %122, 0
br i1 %123, label %125, label %124
124: ; preds = %116
store i32 -1, i32* %4
br label %126
125: ; preds = %116
store i32 0, i32* %4
br label %126
126: ; preds = %125, %124
%127 = load i32, i32* %4
ret i32 %127
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i64 }
@AF_INET6 = global i64 0
@AF_INET = global i64 0
@.str = [2 x i8] c"-\00"
@.str.1 = [2 x i8] c"/\00"
define i32 @inet_stosockaddr(i8* %0, i8* %1, %struct.sockaddr_storage* %2) {
%4 = tail call i64 @strchr(i8* %0, i8 signext 58)
%5 = icmp eq i64 %4, 0
%6 = load i64, i64* @AF_INET6
%7 = load i64, i64* @AF_INET
%8 = select i1 %5, i64 %7, i64 %6
%9 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %2, i64 0, i32 0
store i64 %8, i64* %9
%10 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %3, %15
%13 = phi i8* [ %16, %15 ], [ %0, %3 ]
%14 = load i8, i8* %13
switch i8 %14, label %15 [
i8 45, label %25
i8 0, label %27
]
15: ; preds = %12
%16 = getelementptr inbounds i8, i8* %13, i64 1
br label %12
17: ; preds = %3
%18 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %27, label %20
20: ; preds = %17, %23
%21 = phi i8* [ %24, %23 ], [ %0, %17 ]
%22 = load i8, i8* %21
switch i8 %22, label %23 [
i8 47, label %25
i8 0, label %27
]
23: ; preds = %20
%24 = getelementptr inbounds i8, i8* %21, i64 1
br label %20
25: ; preds = %12, %20
%26 = phi i8* [ %21, %20 ], [ %13, %12 ]
store i8 0, i8* %26
br label %27
27: ; preds = %12, %20, %25, %17
%28 = icmp eq i8* %1, null
br i1 %28, label %34, label %29
29: ; preds = %27
%30 = tail call i32 @atoi(i8* %1)
%31 = tail call i8* @htons(i32 %30)
%32 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %2, i64 1
%33 = bitcast %struct.sockaddr_storage* %32 to i8**
store i8* %31, i8** %33
br label %34
34: ; preds = %27, %29
%35 = bitcast %struct.sockaddr_storage* %2 to i8*
%36 = load i64, i64* %9
%37 = tail call i32 @inet_pton(i64 %36, i8* %0, i8* %35)
%38 = icmp eq i32 %37, 0
%39 = sext i1 %38 to i32
ret i32 %39
}