#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 uint32_t;
struct sockaddr {
  int /*<<< orphan*/ sa_family;
};
typedef int /*<<< orphan*/ ip;

/* Variables and functions */
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ chitcp_get_addr(struct sockaddr *);
int chitcp_get_addr_port(struct sockaddr *);
int chitcp_ntohs(int);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                             int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, int);
char *chitcp_addr_str(struct sockaddr *addr, char *buf, int len) {
  char ip[INET6_ADDRSTRLEN];
  uint32_t port;
  inet_ntop(addr->sa_family, chitcp_get_addr(addr), ip, sizeof(ip));
  port = chitcp_get_addr_port(addr);
  port = chitcp_ntohs(port);
  snprintf(buf, len, "%s:%i", ip, port);
  return buf;
}


x86 assembly (clang, -O0):
<chitcp_addr_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e7e(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <chitcp_get_addr@plt>
mov    -0x44(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %eax,%esi
mov    -0x40(%rbp),%rax
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x8(%rbp),%rdi
call   1060 <chitcp_get_addr_port@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1050 <chitcp_ntohs@plt>
mov    -0x38(%rbp),%rcx
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x2c(%rbp),%r8d
lea    0xe1a(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chitcp_addr_str>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,-0x2c(%rbp)
mov    %rsi,%r15
mov    %rdi,%r12
mov    0x2e7a(%rip),%rax
mov    (%rax),%r13d
mov    %rsp,%rbx
mov    %r13,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    (%rdi),%r14d
call   1070 <chitcp_get_addr@plt>
mov    %r14d,%edi
mov    %eax,%esi
mov    %rbx,%rdx
mov    %r13d,%ecx
call   1030 <inet_ntop@plt>
mov    %r12,%rdi
call   1060 <chitcp_get_addr_port@plt>
mov    %eax,%edi
call   1050 <chitcp_ntohs@plt>
lea    0xe4d(%rip),%rdx
mov    %r15,%rdi
mov    -0x2c(%rbp),%esi
mov    %rbx,%rcx
mov    %eax,%r8d
call   1040 <snprintf@plt>
mov    %r15,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@.str = [6 x i8] c"%s:%i\00"
define i8* @chitcp_addr_str(%struct.sockaddr* %0, i8* %1, i32 %2) {
%4 = alloca %struct.sockaddr*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store %struct.sockaddr* %0, %struct.sockaddr** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i32, i32* @INET6_ADDRSTRLEN
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %7
%13 = alloca i8, i64 %11
store i64 %11, i64* %8
%14 = load %struct.sockaddr*, %struct.sockaddr** %4
%15 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = load %struct.sockaddr*, %struct.sockaddr** %4
%18 = call i32 @chitcp_get_addr(%struct.sockaddr* %17)
%19 = trunc i64 %11 to i32
%20 = call i32 @inet_ntop(i32 %16, i32 %18, i8* %13, i32 %19)
%21 = load %struct.sockaddr*, %struct.sockaddr** %4
%22 = call i32 @chitcp_get_addr_port(%struct.sockaddr* %21)
store i32 %22, i32* %9
%23 = load i32, i32* %9
%24 = call i32 @chitcp_ntohs(i32 %23)
store i32 %24, i32* %9
%25 = load i8*, i8** %5
%26 = load i32, i32* %6
%27 = load i32, i32* %9
%28 = call i32 @snprintf(i8* %25, i32 %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %13, i32 %27)
%29 = load i8*, i8** %5
%30 = load i8*, i8** %7
ret i8* %29
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@.str = [6 x i8] c"%s:%i\00"
define i8* @chitcp_addr_str(%struct.sockaddr* %0, i8* returned %1, i32 %2) {
%4 = load i32, i32* @INET6_ADDRSTRLEN
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%8 = load i32, i32* %7
%9 = tail call i32 @chitcp_get_addr(%struct.sockaddr* %0)
%10 = call i32 @inet_ntop(i32 %8, i32 %9, i8* %6, i32 %4)
%11 = call i32 @chitcp_get_addr_port(%struct.sockaddr* %0)
%12 = call i32 @chitcp_ntohs(i32 %11)
%13 = call i32 @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %6, i32 %12)
ret i8* %1
}