#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_port;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
};

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
void aeron_ip_copy_port(struct sockaddr_storage *dest_addr,
                        struct sockaddr_storage *src_addr) {
  if (AF_INET6 == src_addr->ss_family) {
    struct sockaddr_in6 *dest = (struct sockaddr_in6 *)dest_addr;
    struct sockaddr_in6 *src = (struct sockaddr_in6 *)src_addr;
    dest->sin6_port = src->sin6_port;
  } else if (AF_INET == src_addr->ss_family) {
    struct sockaddr_in *dest = (struct sockaddr_in *)dest_addr;
    struct sockaddr_in *src = (struct sockaddr_in *)src_addr;
    dest->sin_port = src->sin_port;
  }
}


x86 assembly (clang, -O0):
<aeron_ip_copy_port>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ecd(%rip),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jne    1144 <aeron_ip_copy_port+0x44>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    117c <aeron_ip_copy_port+0x7c>
mov    0x2e9d(%rip),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jne    1177 <aeron_ip_copy_port+0x77>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
jmp    117c <aeron_ip_copy_port+0x7c>
pop    %rbp
ret

x86 assembly (clang, -O2):
<aeron_ip_copy_port>:
mov    0x2ed9(%rip),%rcx
mov    (%rsi),%rax
cmp    %rax,(%rcx)
je     111c <aeron_ip_copy_port+0x1c>
mov    0x2ed2(%rip),%rcx
cmp    %rax,(%rcx)
je     111c <aeron_ip_copy_port+0x1c>
ret
mov    %eax,(%rdi)
ret

LLVM IR (-O0):
%struct.sockaddr_storage = type { i64 }
%struct.sockaddr_in6 = type { i32 }
%struct.sockaddr_in = type { i32 }
@AF_INET6 = global i64 0
@AF_INET = global i64 0
define void @aeron_ip_copy_port(%struct.sockaddr_storage* %0, %struct.sockaddr_storage* %1) {
%3 = alloca %struct.sockaddr_storage*
%4 = alloca %struct.sockaddr_storage*
%5 = alloca %struct.sockaddr_in6*
%6 = alloca %struct.sockaddr_in6*
%7 = alloca %struct.sockaddr_in*
%8 = alloca %struct.sockaddr_in*
store %struct.sockaddr_storage* %0, %struct.sockaddr_storage** %3
store %struct.sockaddr_storage* %1, %struct.sockaddr_storage** %4
%9 = load i64, i64* @AF_INET6
%10 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %4
%11 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %10, i32 0, i32 0
%12 = load i64, i64* %11
%13 = icmp eq i64 %9, %12
br i1 %13, label %14, label %24
14: ; preds = %2
%15 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %3
%16 = bitcast %struct.sockaddr_storage* %15 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %16, %struct.sockaddr_in6** %5
%17 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %4
%18 = bitcast %struct.sockaddr_storage* %17 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %18, %struct.sockaddr_in6** %6
%19 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %6
%20 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %5
%23 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %22, i32 0, i32 0
store i32 %21, i32* %23
br label %41
24: ; preds = %2
%25 = load i64, i64* @AF_INET
%26 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %4
%27 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %26, i32 0, i32 0
%28 = load i64, i64* %27
%29 = icmp eq i64 %25, %28
br i1 %29, label %30, label %40
30: ; preds = %24
%31 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %3
%32 = bitcast %struct.sockaddr_storage* %31 to %struct.sockaddr_in*
store %struct.sockaddr_in* %32, %struct.sockaddr_in** %7
%33 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %4
%34 = bitcast %struct.sockaddr_storage* %33 to %struct.sockaddr_in*
store %struct.sockaddr_in* %34, %struct.sockaddr_in** %8
%35 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %35, i32 0, i32 0
%37 = load i32, i32* %36
%38 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %38, i32 0, i32 0
store i32 %37, i32* %39
br label %40
40: ; preds = %30, %24
br label %41
41: ; preds = %40, %14
ret void
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i64 }
@AF_INET6 = global i64 0
@AF_INET = global i64 0
define void @aeron_ip_copy_port(%struct.sockaddr_storage* nocapture writeonly %0, %struct.sockaddr_storage* nocapture %1) {
%3 = load i64, i64* @AF_INET6
%4 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %1, i64 0, i32 0
%5 = load i64, i64* %4
%6 = icmp eq i64 %3, %5
%7 = load i64, i64* @AF_INET
%8 = icmp eq i64 %7, %5
%9 = select i1 %6, i1 true, i1 %8
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = trunc i64 %5 to i32
%12 = bitcast %struct.sockaddr_storage* %0 to i32*
store i32 %11, i32* %12
br label %13
13: ; preds = %2, %10
ret void
}