#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 {
  int dummy;
};
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_addr;
  void *sin6_port;
  void *sin6_family;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  void *sin_port;
  void *sin_family;
};
typedef int socklen_t;

/* Variables and functions */
void *AF_INET;
void *AF_INET6;
#define PF_INET 129
#define PF_INET6 128
int /*<<< orphan*/ abort();
void *htons(int);
int inet_pton(void *, char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_storage *, int /*<<< orphan*/, int);
int /*<<< orphan*/ neubot_info(char *);
scalar_t__ neubot_strtonum(char const *, int /*<<< orphan*/, int,
                           char const **);
int /*<<< orphan*/ neubot_warn(char *);
scalar_t__ strcmp(char const *, char *);
int neubot_storage_init(struct sockaddr_storage *storage, socklen_t *salen,
                        const char *family, const char *address,
                        const char *port) {
  int _family, _port, result;
  const char *errstr;
  neubot_info("utils:neubot_storage_init - enter");
  if (strcmp(family, "PF_INET") == 0) {
    _family = PF_INET;
  } else if (strcmp(family, "PF_INET6") == 0) {
    _family = PF_INET6;
  } else {
    neubot_warn("utils:neubot_storage_init: invalid family");
    return (-1);
  }
  _port = (int)neubot_strtonum(port, 0, 65535, &errstr);
  if (errstr != NULL) {
    neubot_warn("utils:neubot_storage_init: invalid port");
    return (-1);
  }
  memset(storage, 0, sizeof(*storage));
  switch (_family) {
  case PF_INET6: {
    struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)storage;
    sin6->sin6_family = AF_INET6;
    sin6->sin6_port = htons(_port);
    result = inet_pton(AF_INET6, address, &sin6->sin6_addr);
    if (result != 1) {
      neubot_warn("utils:neubot_storage_init: invalid addr");
      return (-1);
    }
    *salen = sizeof(struct sockaddr_in6);
    break;
  }
  case PF_INET: {
    struct sockaddr_in *sin = (struct sockaddr_in *)storage;
    sin->sin_family = AF_INET;
    sin->sin_port = htons(_port);
    result = inet_pton(AF_INET, address, &sin->sin_addr);
    if (result != 1) {
      neubot_warn("utils:neubot_storage_init: invalid addr");
      return (-1);
    }
    *salen = sizeof(struct sockaddr_in);
    break;
  }
  default:
    abort();
  }
  neubot_info("utils:neubot_storage_init - ok");
  return (0);
}


x86 assembly (clang, -O0):
<neubot_storage_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
lea    0xe5d(%rip),%rdi
call   1090 <neubot_info@plt>
mov    -0x20(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11ce <neubot_storage_init+0x4e>
movl   $0x81,-0x34(%rbp)
jmp    1211 <neubot_storage_init+0x91>
mov    -0x20(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11f4 <neubot_storage_init+0x74>
movl   $0x80,-0x34(%rbp)
jmp    120c <neubot_storage_init+0x8c>
lea    0xe38(%rip),%rdi
call   10a0 <neubot_warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    138e <neubot_storage_init+0x20e>
jmp    1211 <neubot_storage_init+0x91>
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0xffff,%edx
lea    -0x48(%rbp),%rcx
call   1070 <neubot_strtonum@plt>
mov    %eax,-0x38(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     124b <neubot_storage_init+0xcb>
lea    0xe23(%rip),%rdi
call   10a0 <neubot_warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    138e <neubot_storage_init+0x20e>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x5c(%rbp)
sub    $0x80,%eax
je     1284 <neubot_storage_init+0x104>
jmp    1271 <neubot_storage_init+0xf1>
mov    -0x5c(%rbp),%eax
sub    $0x81,%eax
je     12fc <neubot_storage_init+0x17c>
jmp    1374 <neubot_storage_init+0x1f4>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x2d4d(%rip),%rax
mov    (%rax),%rcx
mov    -0x50(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x38(%rbp),%edi
call   1040 <htons@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    0x2d28(%rip),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x50(%rbp),%rdx
call   1080 <inet_pton@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x1,-0x3c(%rbp)
je     12ed <neubot_storage_init+0x16d>
lea    0xda9(%rip),%rdi
call   10a0 <neubot_warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    138e <neubot_storage_init+0x20e>
mov    -0x18(%rbp),%rax
movl   $0x18,(%rax)
jmp    137b <neubot_storage_init+0x1fb>
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2cdd(%rip),%rax
mov    (%rax),%rcx
mov    -0x58(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x38(%rbp),%edi
call   1040 <htons@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    0x2cb8(%rip),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x58(%rbp),%rdx
call   1080 <inet_pton@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x1,-0x3c(%rbp)
je     1365 <neubot_storage_init+0x1e5>
lea    0xd31(%rip),%rdi
call   10a0 <neubot_warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    138e <neubot_storage_init+0x20e>
mov    -0x18(%rbp),%rax
movl   $0x18,(%rax)
jmp    137b <neubot_storage_init+0x1fb>
mov    $0x0,%al
call   1030 <abort@plt>
lea    0xd2b(%rip),%rdi
call   1090 <neubot_info@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<neubot_storage_init>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r13
mov    %rcx,%r15
mov    %rdx,%rbp
mov    %rsi,%r14
mov    %rdi,%r12
lea    0xe6f(%rip),%rdi
call   1080 <neubot_info@plt>
lea    0xe85(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11cd <neubot_storage_init+0x5d>
lea    0xe76(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11cd <neubot_storage_init+0x5d>
lea    0xe6b(%rip),%rdi
jmp    125c <neubot_storage_init+0xec>
mov    %rsp,%rcx
mov    %r13,%rdi
xor    %esi,%esi
mov    $0xffff,%edx
call   1060 <neubot_strtonum@plt>
cmpq   $0x0,(%rsp)
je     11ef <neubot_storage_init+0x7f>
lea    0xe70(%rip),%rdi
jmp    125c <neubot_storage_init+0xec>
mov    %rax,%r13
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
test   %rbx,%rbx
je     120f <neubot_storage_init+0x9f>
mov    0x2dd3(%rip),%rbx
jmp    1216 <neubot_storage_init+0xa6>
mov    0x2dd2(%rip),%rbx
mov    (%rbx),%rax
mov    %rax,0x10(%r12)
mov    %r13d,%edi
call   1030 <htons@plt>
mov    %rax,0x8(%r12)
mov    (%rbx),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1070 <inet_pton@plt>
cmp    $0x1,%eax
jne    1255 <neubot_storage_init+0xe5>
movl   $0x18,(%r14)
lea    0xe61(%rip),%rdi
call   1080 <neubot_info@plt>
xor    %eax,%eax
jmp    1266 <neubot_storage_init+0xf6>
lea    0xe29(%rip),%rdi
call   1090 <neubot_warn@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr_in6 = type { i32, i8*, i8* }
%struct.sockaddr_in = type { i32, i8*, i8* }
@.str = [34 x i8] c"utils:neubot_storage_init - enter\00"
@.str.1 = [8 x i8] c"PF_INET\00"
@.str.2 = [9 x i8] c"PF_INET6\00"
@.str.3 = [42 x i8] c"utils:neubot_storage_init: invalid family\00"
@.str.4 = [40 x i8] c"utils:neubot_storage_init: invalid port\00"
@AF_INET6 = global i8* null
@.str.5 = [40 x i8] c"utils:neubot_storage_init: invalid addr\00"
@AF_INET = global i8* null
@.str.6 = [31 x i8] c"utils:neubot_storage_init - ok\00"
define i32 @neubot_storage_init(%struct.sockaddr_storage* %0, i32* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca %struct.sockaddr_storage*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
%16 = alloca %struct.sockaddr_in6*
%17 = alloca %struct.sockaddr_in*
store %struct.sockaddr_storage* %0, %struct.sockaddr_storage** %7
store i32* %1, i32** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
%18 = call i32 @neubot_info(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%19 = load i8*, i8** %9
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %5
store i32 129, i32* %12
br label %31
23: ; preds = %5
%24 = load i8*, i8** %9
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 128, i32* %12
br label %30
28: ; preds = %23
%29 = call i32 @neubot_warn(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %6
br label %89
30: ; preds = %27
br label %31
31: ; preds = %30, %22
%32 = load i8*, i8** %11
%33 = call i64 @neubot_strtonum(i8* %32, i32 0, i32 65535, i8** %15)
%34 = trunc i64 %33 to i32
store i32 %34, i32* %13
%35 = load i8*, i8** %15
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %39
37: ; preds = %31
%38 = call i32 @neubot_warn(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %6
br label %89
39: ; preds = %31
%40 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %7
%41 = call i32 @memset(%struct.sockaddr_storage* %40, i32 0, i32 4)
%42 = load i32, i32* %12
switch i32 %42, label %85 [
i32 128, label %43
i32 129, label %64
]
43: ; preds = %39
%44 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %7
%45 = bitcast %struct.sockaddr_storage* %44 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %45, %struct.sockaddr_in6** %16
%46 = load i8*, i8** @AF_INET6
%47 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %16
%48 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %47, i32 0, i32 2
store i8* %46, i8** %48
%49 = load i32, i32* %13
%50 = call i8* @htons(i32 %49)
%51 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %16
%52 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %51, i32 0, i32 1
store i8* %50, i8** %52
%53 = load i8*, i8** @AF_INET6
%54 = load i8*, i8** %10
%55 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %16
%56 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %55, i32 0, i32 0
%57 = call i32 @inet_pton(i8* %53, i8* %54, i32* %56)
store i32 %57, i32* %14
%58 = load i32, i32* %14
%59 = icmp ne i32 %58, 1
br i1 %59, label %60, label %62
60: ; preds = %43
%61 = call i32 @neubot_warn(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %6
br label %89
62: ; preds = %43
%63 = load i32*, i32** %8
store i32 24, i32* %63
br label %87
64: ; preds = %39
%65 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %7
%66 = bitcast %struct.sockaddr_storage* %65 to %struct.sockaddr_in*
store %struct.sockaddr_in* %66, %struct.sockaddr_in** %17
%67 = load i8*, i8** @AF_INET
%68 = load %struct.sockaddr_in*, %struct.sockaddr_in** %17
%69 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %68, i32 0, i32 2
store i8* %67, i8** %69
%70 = load i32, i32* %13
%71 = call i8* @htons(i32 %70)
%72 = load %struct.sockaddr_in*, %struct.sockaddr_in** %17
%73 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %72, i32 0, i32 1
store i8* %71, i8** %73
%74 = load i8*, i8** @AF_INET
%75 = load i8*, i8** %10
%76 = load %struct.sockaddr_in*, %struct.sockaddr_in** %17
%77 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %76, i32 0, i32 0
%78 = call i32 @inet_pton(i8* %74, i8* %75, i32* %77)
store i32 %78, i32* %14
%79 = load i32, i32* %14
%80 = icmp ne i32 %79, 1
br i1 %80, label %81, label %83
81: ; preds = %64
%82 = call i32 @neubot_warn(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %6
br label %89
83: ; preds = %64
%84 = load i32*, i32** %8
store i32 24, i32* %84
br label %87
85: ; preds = %39
%86 = call i32 (...) @abort()
unreachable
87: ; preds = %83, %62
%88 = call i32 @neubot_info(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %6
br label %89
89: ; preds = %87, %81, %60, %37, %28
%90 = load i32, i32* %6
ret i32 %90
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
@.str = [34 x i8] c"utils:neubot_storage_init - enter\00"
@.str.1 = [8 x i8] c"PF_INET\00"
@.str.2 = [9 x i8] c"PF_INET6\00"
@.str.3 = [42 x i8] c"utils:neubot_storage_init: invalid family\00"
@.str.4 = [40 x i8] c"utils:neubot_storage_init: invalid port\00"
@AF_INET6 = global i8* null
@.str.5 = [40 x i8] c"utils:neubot_storage_init: invalid addr\00"
@AF_INET = global i8* null
@.str.6 = [31 x i8] c"utils:neubot_storage_init - ok\00"
define i32 @neubot_storage_init(%struct.sockaddr_storage* %0, i32* nocapture writeonly %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i8*
%7 = bitcast i8** %6 to i8*
%8 = tail call i32 @neubot_info(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%9 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %5
%12 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = tail call i32 @neubot_warn(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %53
16: ; preds = %11, %5
%17 = call i64 @neubot_strtonum(i8* %4, i32 0, i32 65535, i8** %6)
%18 = trunc i64 %17 to i32
%19 = load i8*, i8** %6
%20 = icmp eq i8* %19, null
br i1 %20, label %23, label %21
21: ; preds = %16
%22 = call i32 @neubot_warn(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
br label %53
23: ; preds = %16
%24 = call i32 @memset(%struct.sockaddr_storage* %0, i32 0, i32 4)
br i1 %10, label %38, label %25
25: ; preds = %23
%26 = load i8*, i8** @AF_INET6
%27 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %0, i64 4
%28 = bitcast %struct.sockaddr_storage* %27 to i8**
store i8* %26, i8** %28
%29 = call i8* @htons(i32 %18)
%30 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %0, i64 2
%31 = bitcast %struct.sockaddr_storage* %30 to i8**
store i8* %29, i8** %31
%32 = load i8*, i8** @AF_INET6
%33 = getelementptr %struct.sockaddr_storage, %struct.sockaddr_storage* %0, i64 0, i32 0
%34 = call i32 @inet_pton(i8* %32, i8* %3, i32* %33)
%35 = icmp eq i32 %34, 1
br i1 %35, label %51, label %36
36: ; preds = %25
%37 = call i32 @neubot_warn(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
br label %53
38: ; preds = %23
%39 = load i8*, i8** @AF_INET
%40 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %0, i64 4
%41 = bitcast %struct.sockaddr_storage* %40 to i8**
store i8* %39, i8** %41
%42 = call i8* @htons(i32 %18)
%43 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %0, i64 2
%44 = bitcast %struct.sockaddr_storage* %43 to i8**
store i8* %42, i8** %44
%45 = load i8*, i8** @AF_INET
%46 = getelementptr %struct.sockaddr_storage, %struct.sockaddr_storage* %0, i64 0, i32 0
%47 = call i32 @inet_pton(i8* %45, i8* %3, i32* %46)
%48 = icmp eq i32 %47, 1
br i1 %48, label %51, label %49
49: ; preds = %38
%50 = call i32 @neubot_warn(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
br label %53
51: ; preds = %38, %25
store i32 24, i32* %1
%52 = call i32 @neubot_info(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
br label %53
53: ; preds = %49, %36, %51, %21, %14
%54 = phi i32 [ -1, %21 ], [ 0, %51 ], [ -1, %49 ], [ -1, %36 ], [ -1, %14 ]
ret i32 %54
}