#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 */
typedef int /*<<< orphan*/ uint16_t;
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_port;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ in_port_t;

/* Variables and functions */
int AF_INET6;
int /*<<< orphan*/ ntohs(int /*<<< orphan*/);
uint16_t br_httpd_get_port(int af, const struct sockaddr *addr) {
  in_port_t port = 0;
  if (af == AF_INET6) {
    struct sockaddr_in6 *a = (struct sockaddr_in6 *)addr;
    port = a->sin6_port;
  } else {
    struct sockaddr_in *a = (struct sockaddr_in *)addr;
    port = a->sin_port;
  }
  return ntohs(port);
}


x86 assembly (clang, -O0):
<br_httpd_get_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2eb8(%rip),%rcx
cmp    (%rcx),%eax
jne    114e <br_httpd_get_port+0x3e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    115f <br_httpd_get_port+0x4f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <ntohs@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<br_httpd_get_port>:
mov    (%rsi),%edi
jmp    1030 <ntohs@plt>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in6 = type { i32 }
%struct.sockaddr_in = type { i32 }
@AF_INET6 = global i32 0
define i32 @br_httpd_get_port(i32 %0, %struct.sockaddr* %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr*
%5 = alloca i32
%6 = alloca %struct.sockaddr_in6*
%7 = alloca %struct.sockaddr_in*
store i32 %0, i32* %3
store %struct.sockaddr* %1, %struct.sockaddr** %4
store i32 0, i32* %5
%8 = load i32, i32* %3
%9 = load i32, i32* @AF_INET6
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load %struct.sockaddr*, %struct.sockaddr** %4
%13 = bitcast %struct.sockaddr* %12 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %13, %struct.sockaddr_in6** %6
%14 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %6
%15 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %14, i32 0, i32 0
%16 = load i32, i32* %15
store i32 %16, i32* %5
br label %23
17: ; preds = %2
%18 = load %struct.sockaddr*, %struct.sockaddr** %4
%19 = bitcast %struct.sockaddr* %18 to %struct.sockaddr_in*
store %struct.sockaddr_in* %19, %struct.sockaddr_in** %7
%20 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %20, i32 0, i32 0
%22 = load i32, i32* %21
store i32 %22, i32* %5
br label %23
23: ; preds = %17, %11
%24 = load i32, i32* %5
%25 = call i32 @ntohs(i32 %24)
ret i32 %25
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@AF_INET6 = global i32 0
define i32 @br_httpd_get_port(i32 %0, %struct.sockaddr* nocapture %1) {
%3 = getelementptr %struct.sockaddr, %struct.sockaddr* %1, i64 0, i32 0
%4 = load i32, i32* %3
%5 = tail call i32 @ntohs(i32 %4)
ret i32 %5
}