#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 */
typedef int /*<<< orphan*/ uint16_t;
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
int /*<<< orphan*/ INADDR_LOOPBACK;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ in6addr_loopback;
struct sockaddr *new_any_sockaddr(int, int /*<<< orphan*/);
struct sockaddr *new_loopback_sockaddr(int family, uint16_t port) {
  struct sockaddr *addr = new_any_sockaddr(family, port);
  struct sockaddr_in *addr4;
  struct sockaddr_in6 *addr6;
  switch (family) {
  case AF_INET:
    addr4 = (struct sockaddr_in *)addr;
    addr4->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
    break;
  case AF_INET6:
    addr6 = (struct sockaddr_in6 *)addr;
    addr6->sin6_addr = in6addr_loopback;
    break;
  default:
    error(1, 0, "Unsupported family %d", family);
  }
  return addr;
}


x86 assembly (clang, -O0):
<new_loopback_sockaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <new_any_sockaddr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x80,%eax
je     1199 <new_loopback_sockaddr+0x69>
jmp    1163 <new_loopback_sockaddr+0x33>
mov    -0x24(%rbp),%eax
sub    $0x81,%eax
jne    11b5 <new_loopback_sockaddr+0x85>
jmp    1176 <new_loopback_sockaddr+0x46>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    11cb <new_loopback_sockaddr+0x9b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e40(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    11cb <new_loopback_sockaddr+0x9b>
mov    -0x4(%rbp),%ecx
mov    $0x1,%edi
xor    %esi,%esi
lea    0xe3a(%rip),%rdx
call   1050 <error@plt>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<new_loopback_sockaddr>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
call   1030 <new_any_sockaddr@plt>
mov    %rax,%rbx
cmp    $0x80,%ebp
je     115f <new_loopback_sockaddr+0x2f>
cmp    $0x81,%ebp
jne    116c <new_loopback_sockaddr+0x3c>
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,(%rbx)
jmp    1181 <new_loopback_sockaddr+0x51>
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rbx)
jmp    1181 <new_loopback_sockaddr+0x51>
lea    0xe8d(%rip),%rdx
mov    $0x1,%edi
xor    %esi,%esi
mov    %ebp,%ecx
call   1050 <error@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@INADDR_LOOPBACK = global i32 0
@in6addr_loopback = global i32 0
@.str = [22 x i8] c"Unsupported family %d\00"
define %struct.sockaddr* @new_loopback_sockaddr(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr*
%6 = alloca %struct.sockaddr_in*
%7 = alloca %struct.sockaddr_in6*
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = load i32, i32* %4
%10 = call %struct.sockaddr* @new_any_sockaddr(i32 %8, i32 %9)
store %struct.sockaddr* %10, %struct.sockaddr** %5
%11 = load i32, i32* %3
switch i32 %11, label %26 [
i32 129, label %12
i32 128, label %20
]
12: ; preds = %2
%13 = load %struct.sockaddr*, %struct.sockaddr** %5
%14 = bitcast %struct.sockaddr* %13 to %struct.sockaddr_in*
store %struct.sockaddr_in* %14, %struct.sockaddr_in** %6
%15 = load i32, i32* @INADDR_LOOPBACK
%16 = call i32 @htonl(i32 %15)
%17 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 0
%19 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %18, i32 0, i32 0
store i32 %16, i32* %19
br label %29
20: ; preds = %2
%21 = load %struct.sockaddr*, %struct.sockaddr** %5
%22 = bitcast %struct.sockaddr* %21 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %22, %struct.sockaddr_in6** %7
%23 = load i32, i32* @in6addr_loopback
%24 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %7
%25 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %24, i32 0, i32 0
store i32 %23, i32* %25
br label %29
26: ; preds = %2
%27 = load i32, i32* %3
%28 = call i32 @error(i32 1, i32 0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %26, %20, %12
%30 = load %struct.sockaddr*, %struct.sockaddr** %5
ret %struct.sockaddr* %30
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@INADDR_LOOPBACK = global i32 0
@in6addr_loopback = global i32 0
@.str = [22 x i8] c"Unsupported family %d\00"
define %struct.sockaddr* @new_loopback_sockaddr(i32 %0, i32 %1) {
%3 = tail call %struct.sockaddr* @new_any_sockaddr(i32 %0, i32 %1)
switch i32 %0, label %11 [
i32 129, label %4
i32 128, label %8
]
4: ; preds = %2
%5 = load i32, i32* @INADDR_LOOPBACK
%6 = tail call i32 @htonl(i32 %5)
%7 = getelementptr %struct.sockaddr, %struct.sockaddr* %3, i64 0, i32 0
store i32 %6, i32* %7
br label %13
8: ; preds = %2
%9 = load i32, i32* @in6addr_loopback
%10 = getelementptr %struct.sockaddr, %struct.sockaddr* %3, i64 0, i32 0
store i32 %9, i32* %10
br label %13
11: ; preds = %2
%12 = tail call i32 @error(i32 1, i32 0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %13
13: ; preds = %11, %8, %4
ret %struct.sockaddr* %3
}