#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_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/ *, char *,
                             int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
char *ip2str(struct sockaddr_in *addr) {
  static char buf[24];
  inet_ntop(AF_INET, &addr->sin_addr, buf, 16);
  sprintf(buf, "%s:%u", buf, ntohs(addr->sin_port));
  return buf;
}


x86 assembly (clang, -O0):
<ip2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
add    $0x4,%rsi
lea    0x2efc(%rip),%rdx
mov    $0x10,%ecx
call   1030 <inet_ntop@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1040 <ntohs@plt>
mov    %eax,%ecx
lea    0x2ede(%rip),%rdx
lea    0xe87(%rip),%rsi
mov    %rdx,%rdi
call   1050 <sprintf@plt>
lea    0x2ec8(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip2str>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2eaa(%rip),%rax
mov    (%rax),%edi
lea    0x4(%rbx),%rsi
lea    0x2f05(%rip),%r14
mov    %r14,%rdx
mov    $0x10,%ecx
call   1030 <inet_ntop@plt>
mov    (%rbx),%edi
call   1040 <ntohs@plt>
lea    0xe9a(%rip),%rsi
mov    %r14,%rdi
mov    %r14,%rdx
mov    %eax,%ecx
call   1050 <sprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
@ip2str.buf = internal global [24 x i8] zeroinitializer
@AF_INET = global i32 0
@.str = [6 x i8] c"%s:%u\00"
define i8* @ip2str(%struct.sockaddr_in* %0) {
%2 = alloca %struct.sockaddr_in*
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %2
%3 = load i32, i32* @AF_INET
%4 = load %struct.sockaddr_in*, %struct.sockaddr_in** %2
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%6 = call i32 @inet_ntop(i32 %3, i32* %5, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @ip2str.buf, i64 0, i64 0), i32 16)
%7 = load %struct.sockaddr_in*, %struct.sockaddr_in** %2
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%9 = load i32, i32* %8
%10 = call i32 @ntohs(i32 %9)
%11 = call i32 @sprintf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @ip2str.buf, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @ip2str.buf, i64 0, i64 0), i32 %10)
ret i8* getelementptr inbounds ([24 x i8], [24 x i8]* @ip2str.buf, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32 }
@ip2str.buf = internal global [24 x i8] zeroinitializer
@AF_INET = global i32 0
@.str = [6 x i8] c"%s:%u\00"
define i8* @ip2str(%struct.sockaddr_in* %0) {
%2 = load i32, i32* @AF_INET
%3 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 1
%4 = tail call i32 @inet_ntop(i32 %2, i32* %3, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @ip2str.buf, i64 0, i64 0), i32 16)
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 0
%6 = load i32, i32* %5
%7 = tail call i32 @ntohs(i32 %6)
%8 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @ip2str.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @ip2str.buf, i64 0, i64 0), i32 %7)
ret i8* getelementptr inbounds ([24 x i8], [24 x i8]* @ip2str.buf, i64 0, i64 0)
}