#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 */

/* Variables and functions */
unsigned short *calloc(int, int);
int /*<<< orphan*/ free(unsigned short *);
int /*<<< orphan*/ memcpy(unsigned short *, unsigned short *, int);
unsigned short *tcp_listen_ports(int *);
unsigned short *udp_listen_ports(int *);
unsigned short *listen_ports(int *size) {
  unsigned short *t, *u, *p;
  int sizet, sizeu;
  t = tcp_listen_ports(&sizet);
  u = udp_listen_ports(&sizeu);
  p = calloc(1, sizet + sizeu);
  memcpy(p, t, sizet);
  memcpy(p + sizet / sizeof(short), u, sizeu);
  *size = sizet + sizeu;
  free(t);
  free(u);
  return p;
}


x86 assembly (clang, -O0):
<listen_ports>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x24(%rbp),%rdi
call   1040 <tcp_listen_ports@plt>
mov    %rax,-0x10(%rbp)
lea    -0x28(%rbp),%rdi
call   1050 <udp_listen_ports@plt>
mov    %rax,-0x18(%rbp)
mov    -0x24(%rbp),%esi
add    -0x28(%rbp),%esi
mov    $0x1,%edi
call   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1070 <memcpy@plt>
mov    -0x20(%rbp),%rdi
movslq -0x24(%rbp),%rax
shr    $0x1,%rax
shl    $0x1,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1070 <memcpy@plt>
mov    -0x24(%rbp),%ecx
add    -0x28(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<listen_ports>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
lea    0xc(%rsp),%rdi
call   1040 <tcp_listen_ports@plt>
mov    %rax,%r15
lea    0x8(%rsp),%rdi
call   1050 <udp_listen_ports@plt>
mov    %rax,%r12
mov    0xc(%rsp),%ebp
mov    0x8(%rsp),%esi
add    %ebp,%esi
mov    $0x1,%edi
call   1060 <calloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1070 <memcpy@plt>
movslq 0xc(%rsp),%rdi
and    $0xfffffffffffffffe,%rdi
add    %rbx,%rdi
mov    0x8(%rsp),%edx
mov    %r12,%rsi
call   1070 <memcpy@plt>
mov    0x8(%rsp),%eax
add    0xc(%rsp),%eax
mov    %eax,(%r14)
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i16* @listen_ports(i32* %0) {
%2 = alloca i32*
%3 = alloca i16*
%4 = alloca i16*
%5 = alloca i16*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %2
%8 = call i16* @tcp_listen_ports(i32* %6)
store i16* %8, i16** %3
%9 = call i16* @udp_listen_ports(i32* %7)
store i16* %9, i16** %4
%10 = load i32, i32* %6
%11 = load i32, i32* %7
%12 = add nsw i32 %10, %11
%13 = call i16* @calloc(i32 1, i32 %12)
store i16* %13, i16** %5
%14 = load i16*, i16** %5
%15 = load i16*, i16** %3
%16 = load i32, i32* %6
%17 = call i32 @memcpy(i16* %14, i16* %15, i32 %16)
%18 = load i16*, i16** %5
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = udiv i64 %20, 2
%22 = getelementptr inbounds i16, i16* %18, i64 %21
%23 = load i16*, i16** %4
%24 = load i32, i32* %7
%25 = call i32 @memcpy(i16* %22, i16* %23, i32 %24)
%26 = load i32, i32* %6
%27 = load i32, i32* %7
%28 = add nsw i32 %26, %27
%29 = load i32*, i32** %2
store i32 %28, i32* %29
%30 = load i16*, i16** %3
%31 = call i32 @free(i16* %30)
%32 = load i16*, i16** %4
%33 = call i32 @free(i16* %32)
%34 = load i16*, i16** %5
ret i16* %34
}

LLVM IR (-O2):
define i16* @listen_ports(i32* nocapture writeonly %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = call i16* @tcp_listen_ports(i32* %2)
%7 = call i16* @udp_listen_ports(i32* %3)
%8 = load i32, i32* %2
%9 = load i32, i32* %3
%10 = add nsw i32 %9, %8
%11 = call i16* @calloc(i32 1, i32 %10)
%12 = call i32 @memcpy(i16* %11, i16* %6, i32 %8)
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = lshr i64 %14, 1
%16 = getelementptr inbounds i16, i16* %11, i64 %15
%17 = load i32, i32* %3
%18 = call i32 @memcpy(i16* %16, i16* %7, i32 %17)
%19 = load i32, i32* %2
%20 = load i32, i32* %3
%21 = add nsw i32 %20, %19
store i32 %21, i32* %0
%22 = call i32 @free(i16* %6)
%23 = call i32 @free(i16* %7)
ret i16* %11
}