#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct sockaddr_storage {
  unsigned int *s6_addr16;
};
struct TYPE_2__ {
  unsigned int s_addr;
};
struct sockaddr_in6 {
  int sin_family;
  int sin6_family;
  struct sockaddr_storage sin6_addr;
  void *sin6_port;
  TYPE_1__ sin_addr;
  void *sin_port;
};
struct sockaddr_in {
  int sin_family;
  int sin6_family;
  struct sockaddr_storage sin6_addr;
  void *sin6_port;
  TYPE_1__ sin_addr;
  void *sin_port;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ sin6;
typedef int /*<<< orphan*/ sin;

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
void *htons(unsigned int);
int /*<<< orphan*/ memcpy(struct sockaddr_storage *, struct sockaddr_in6 *,
                          int);
int /*<<< orphan*/ memset(struct sockaddr_storage *, int, int);
socklen_t anon_addr(int domain, struct sockaddr_storage *sst, unsigned int id,
                    unsigned int id2) {
  memset(sst, 0, sizeof(*sst));
  socklen_t ret = -1;
  switch (domain) {
  case AF_INET:;
    struct sockaddr_in sin;
    sin.sin_family = AF_INET;
    sin.sin_port = htons(id);
    sin.sin_addr.s_addr = id2;
    memcpy(sst, &sin, sizeof(sin));
    ret = sizeof(sin);
    break;
  case AF_INET6:;
    struct sockaddr_in6 sin6;
    sin6.sin6_family = AF_INET6;
    sin6.sin6_port = htons(id);
    memset(&sin6.sin6_addr, -1, sizeof(sin6.sin6_addr));
    sin6.sin6_addr.s6_addr16[4] = id2;
    memcpy(sst, &sin6, sizeof(sin6));
    ret = sizeof(sin6);
    break;
  }
  return ret;
}


x86 assembly (clang, -O0):
<anon_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x74(%rbp)
sub    $0x80,%eax
je     11bf <anon_addr+0x8f>
jmp    1175 <anon_addr+0x45>
mov    -0x74(%rbp),%eax
sub    $0x81,%eax
jne    120c <anon_addr+0xdc>
jmp    1188 <anon_addr+0x58>
movl   $0x81,-0x48(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <htons@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x48(%rbp),%rsi
mov    $0x28,%edx
call   1050 <memcpy@plt>
movl   $0x28,-0x1c(%rbp)
jmp    120c <anon_addr+0xdc>
movl   $0x80,-0x6c(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <htons@plt>
mov    %rax,-0x60(%rbp)
lea    -0x70(%rbp),%rdi
add    $0x8,%rdi
mov    $0xffffffff,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%ecx
mov    -0x68(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x28,%edx
call   1050 <memcpy@plt>
movl   $0x28,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<anon_addr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %rsi,%r12
mov    %edi,%ebx
mov    %rsi,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
cmp    $0x80,%ebx
je     118c <anon_addr+0x5c>
mov    $0xffffffff,%ebp
cmp    $0x81,%ebx
jne    11d3 <anon_addr+0xa3>
movl   $0x81,0x28(%rsp)
mov    %r15d,%edi
call   1030 <htons@plt>
mov    %rax,0x48(%rsp)
mov    %r14d,0x40(%rsp)
lea    0x28(%rsp),%rsi
jmp    11c1 <anon_addr+0x91>
movl   $0x80,0x4(%rsp)
mov    %r15d,%edi
call   1030 <htons@plt>
mov    %rax,0x10(%rsp)
lea    0x8(%rsp),%rdi
mov    $0xffffffff,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x8(%rsp),%rax
mov    %r14d,0x10(%rax)
mov    %rsp,%rsi
mov    $0x28,%ebp
mov    %r12,%rdi
mov    $0x28,%edx
call   1050 <memcpy@plt>
mov    %ebp,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32* }
%struct.sockaddr_in = type { i32, i32, %struct.sockaddr_storage, i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in6 = type { i32, i32, %struct.sockaddr_storage, i8*, %struct.TYPE_2__, i8* }
define i32 @anon_addr(i32 %0, %struct.sockaddr_storage* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.sockaddr_storage*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.sockaddr_in6
store i32 %0, i32* %5
store %struct.sockaddr_storage* %1, %struct.sockaddr_storage** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %6
%13 = call i32 @memset(%struct.sockaddr_storage* %12, i32 0, i32 8)
store i32 -1, i32* %9
%14 = load i32, i32* %5
switch i32 %14, label %40 [
i32 129, label %15
i32 128, label %26
]
15: ; preds = %4
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 129, i32* %16
%17 = load i32, i32* %7
%18 = call i8* @htons(i32 %17)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 5
store i8* %18, i8** %19
%20 = load i32, i32* %8
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 4
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %6
%24 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr_in6*
%25 = call i32 @memcpy(%struct.sockaddr_storage* %23, %struct.sockaddr_in6* %24, i32 40)
store i32 40, i32* %9
br label %40
26: ; preds = %4
%27 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %11, i32 0, i32 1
store i32 128, i32* %27
%28 = load i32, i32* %7
%29 = call i8* @htons(i32 %28)
%30 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %11, i32 0, i32 3
store i8* %29, i8** %30
%31 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %11, i32 0, i32 2
%32 = call i32 @memset(%struct.sockaddr_storage* %31, i32 -1, i32 8)
%33 = load i32, i32* %8
%34 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %11, i32 0, i32 2
%35 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %34, i32 0, i32 0
%36 = load i32*, i32** %35
%37 = getelementptr inbounds i32, i32* %36, i64 4
store i32 %33, i32* %37
%38 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %6
%39 = call i32 @memcpy(%struct.sockaddr_storage* %38, %struct.sockaddr_in6* %11, i32 40)
store i32 40, i32* %9
br label %40
40: ; preds = %4, %26, %15
%41 = load i32, i32* %9
ret i32 %41
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32* }
%struct.sockaddr_in = type { i32, i32, %struct.sockaddr_storage, i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in6 = type { i32, i32, %struct.sockaddr_storage, i8*, %struct.TYPE_2__, i8* }
define i32 @anon_addr(i32 %0, %struct.sockaddr_storage* %1, i32 %2, i32 %3) {
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in6
%7 = tail call i32 @memset(%struct.sockaddr_storage* %1, i32 0, i32 8)
switch i32 %0, label %26 [
i32 129, label %8
i32 128, label %15
]
8: ; preds = %4
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 129, i32* %9
%10 = tail call i8* @htons(i32 %2)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 5
store i8* %10, i8** %11
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 4, i32 0
store i32 %3, i32* %12
%13 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr_in6*
%14 = call i32 @memcpy(%struct.sockaddr_storage* %1, %struct.sockaddr_in6* %13, i32 40)
br label %26
15: ; preds = %4
%16 = bitcast %struct.sockaddr_in6* %6 to i8*
%17 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %6, i64 0, i32 1
store i32 128, i32* %17
%18 = tail call i8* @htons(i32 %2)
%19 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %6, i64 0, i32 3
store i8* %18, i8** %19
%20 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %6, i64 0, i32 2
%21 = call i32 @memset(%struct.sockaddr_storage* %20, i32 -1, i32 8)
%22 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %20, i64 0, i32 0
%23 = load i32*, i32** %22
%24 = getelementptr inbounds i32, i32* %23, i64 4
store i32 %3, i32* %24
%25 = call i32 @memcpy(%struct.sockaddr_storage* %1, %struct.sockaddr_in6* %6, i32 40)
br label %26
26: ; preds = %4, %15, %8
%27 = phi i32 [ -1, %4 ], [ 40, %15 ], [ 40, %8 ]
ret i32 %27
}