#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_in6 {
  void *sin6_port;
};
struct sockaddr_in {
  void *sin_port;
};
struct sockaddr {
  scalar_t__ sa_family;
};
typedef void *in_port_t;

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
int /*<<< orphan*/ assert(int);
void chitcp_set_addr_port(struct sockaddr *addr, in_port_t port) {
  assert(addr->sa_family == AF_INET || addr->sa_family == AF_INET6);
  if (addr->sa_family == AF_INET) {
    struct sockaddr_in *sin = (struct sockaddr_in *)addr;
    sin->sin_port = port;
  } else if (addr->sa_family == AF_INET6) {
    struct sockaddr_in6 *sin = (struct sockaddr_in6 *)addr;
    sin->sin6_port = port;
  }
}


x86 assembly (clang, -O0):
<chitcp_set_addr_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
mov    $0x1,%al
mov    0x2eb8(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x21(%rbp)
je     1153 <chitcp_set_addr_port+0x43>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x2e96(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x2e7a(%rip),%rcx
cmp    (%rcx),%rax
jne    118f <chitcp_set_addr_port+0x7f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    11be <chitcp_set_addr_port+0xae>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x2e43(%rip),%rcx
cmp    (%rcx),%rax
jne    11b9 <chitcp_set_addr_port+0xa9>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
jmp    11be <chitcp_set_addr_port+0xae>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chitcp_set_addr_port>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%rax
mov    0x2ec3(%rip),%r12
cmp    (%r12),%rax
sete   %cl
mov    0x2ead(%rip),%r15
cmp    (%r15),%rax
mov    %rsi,%r14
sete   %al
or     %cl,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    (%rbx),%rax
cmp    (%r12),%rax
je     1154 <chitcp_set_addr_port+0x44>
cmp    (%r15),%rax
jne    1157 <chitcp_set_addr_port+0x47>
mov    %r14,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.sockaddr = type { i64 }
@AF_INET = global i64 0
@AF_INET6 = global i64 0
define void @chitcp_set_addr_port(%struct.sockaddr* nocapture %0, i8* %1) {
%3 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%4 = load i64, i64* %3
%5 = load i64, i64* @AF_INET
%6 = icmp eq i64 %4, %5
%7 = load i64, i64* @AF_INET6
%8 = icmp eq i64 %4, %7
%9 = select i1 %6, i1 true, i1 %8
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = load i64, i64* %3
%13 = load i64, i64* @AF_INET
%14 = icmp eq i64 %12, %13
%15 = load i64, i64* @AF_INET6
%16 = icmp eq i64 %12, %15
%17 = select i1 %14, i1 true, i1 %16
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = bitcast %struct.sockaddr* %0 to i8**
store i8* %1, i8** %19
br label %20
20: ; preds = %2, %18
ret void
}