#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*/ tmp;
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
  int /*<<< orphan*/ sin_port;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/ *, char *,
                             int);
int /*<<< orphan*/ ntohs(int /*<<< orphan*/);
size_t scnprintf(char *, size_t, char *, int /*<<< orphan*/,
                 int /*<<< orphan*/);
size_t af_inet__scnprintf(struct sockaddr *sa, char *bf, size_t size) {
  struct sockaddr_in *sin = (struct sockaddr_in *)sa;
  char tmp[16];
  return scnprintf(
      bf, size, ", port: %d, addr: %s", ntohs(sin->sin_port),
      inet_ntop(sin->sin_family, &sin->sin_addr, tmp, sizeof(tmp)));
}


x86 assembly (clang, -O0):
<af_inet__scnprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%edi
call   1040 <ntohs@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x20(%rbp),%rsi
lea    -0x30(%rbp),%rdx
mov    $0x10,%ecx
call   1030 <inet_ntop@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x34(%rbp),%ecx
mov    %eax,%r8d
lea    0xe67(%rip),%rdx
call   1050 <scnprintf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<af_inet__scnprintf>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    0x8(%rdi),%edi
call   1040 <ntohs@plt>
mov    %eax,%ebp
mov    0x4(%rbx),%edi
mov    %rsp,%rdx
mov    %rbx,%rsi
mov    $0x10,%ecx
call   1030 <inet_ntop@plt>
lea    0xe99(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebp,%ecx
mov    %eax,%r8d
call   1050 <scnprintf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i32, i32, i32 }
@.str = [21 x i8] c", port: %d, addr: %s\00"
define i64 @af_inet__scnprintf(%struct.sockaddr* %0, i8* %1, i64 %2) {
%4 = alloca %struct.sockaddr*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca %struct.sockaddr_in*
%8 = alloca [16 x i8]
store %struct.sockaddr* %0, %struct.sockaddr** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load %struct.sockaddr*, %struct.sockaddr** %4
%10 = bitcast %struct.sockaddr* %9 to %struct.sockaddr_in*
store %struct.sockaddr_in* %10, %struct.sockaddr_in** %7
%11 = load i8*, i8** %5
%12 = load i64, i64* %6
%13 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 2
%15 = load i32, i32* %14
%16 = call i32 @ntohs(i32 %15)
%17 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 1
%19 = load i32, i32* %18
%20 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %20, i32 0, i32 0
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%23 = call i32 @inet_ntop(i32 %19, i32* %21, i8* %22, i32 16)
%24 = call i64 @scnprintf(i8* %11, i64 %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %23)
ret i64 %24
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c", port: %d, addr: %s\00"
define i64 @af_inet__scnprintf(%struct.sockaddr* %0, i8* %1, i64 %2) {
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%6 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 2, i32 0
%7 = load i32, i32* %6
%8 = tail call i32 @ntohs(i32 %7)
%9 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 1, i32 0
%10 = load i32, i32* %9
%11 = getelementptr %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%12 = call i32 @inet_ntop(i32 %10, i32* %11, i8* %5, i32 16)
%13 = call i64 @scnprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %12)
ret i64 %13
}