#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;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ serveraddr;
typedef int /*<<< orphan*/ clientaddr;
typedef int /*<<< orphan*/ abuf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int INET_ADDRSTRLEN;
int /*<<< orphan*/ getpeername(int, struct sockaddr *, int *);
int /*<<< orphan*/ getsockname(int, struct sockaddr *, int *);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/ *, char *,
                             int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, int);
void print_socket_info(int connsock) {
  struct sockaddr_in serveraddr, clientaddr;
  char abuf[INET_ADDRSTRLEN];
  int server_len = sizeof(serveraddr);
  int client_len = sizeof(clientaddr);
  getsockname(connsock, (struct sockaddr *)&serveraddr, &server_len);
  inet_ntop(AF_INET, &serveraddr.sin_addr, abuf, sizeof(abuf));
  printf("host at %s:%d\n", abuf, ntohs(serveraddr.sin_port));
  getpeername(connsock, (struct sockaddr *)&clientaddr, &client_len);
  inet_ntop(AF_INET, &clientaddr.sin_addr, abuf, sizeof(abuf));
  printf("remote at %s:%d\n", abuf, ntohs(clientaddr.sin_port));
}


x86 assembly (clang, -O0):
<print_socket_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e76(%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)
movl   $0x8,-0x2c(%rbp)
movl   $0x8,-0x30(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1070 <getsockname@plt>
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rax
mov    0x2e30(%rip),%rcx
mov    (%rcx),%edi
lea    -0x10(%rbp),%rsi
add    $0x4,%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x10(%rbp),%edi
call   1060 <ntohs@plt>
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
lea    0xe22(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1040 <getpeername@plt>
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rax
mov    0x2de6(%rip),%rcx
mov    (%rcx),%edi
lea    -0x18(%rbp),%rsi
add    $0x4,%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x18(%rbp),%edi
call   1060 <ntohs@plt>
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
lea    0xde7(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_socket_info>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r15d
mov    %rsp,%r12
mov    0x2e6a(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
movl   $0x8,-0x30(%rbp)
movl   $0x8,-0x2c(%rbp)
lea    -0x40(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1070 <getsockname@plt>
mov    0x2e41(%rip),%r13
mov    0x0(%r13),%edi
lea    -0x3c(%rbp),%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   1030 <inet_ntop@plt>
mov    -0x40(%rbp),%edi
call   1060 <ntohs@plt>
lea    0xe37(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <printf@plt>
lea    -0x38(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
mov    %r15d,%edi
call   1040 <getpeername@plt>
mov    0x0(%r13),%edi
lea    -0x34(%rbp),%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   1030 <inet_ntop@plt>
mov    -0x38(%rbp),%edi
call   1060 <ntohs@plt>
lea    0xe0a(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <printf@plt>
mov    %r12,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@INET_ADDRSTRLEN = global i32 0
@AF_INET = global i32 0
@.str = [15 x i8] c"host at %s:%d\0A\00"
@.str.1 = [17 x i8] c"remote at %s:%d\0A\00"
define void @print_socket_info(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %2
%9 = load i32, i32* @INET_ADDRSTRLEN
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %5
%12 = alloca i8, i64 %10
store i64 %10, i64* %6
store i32 8, i32* %7
store i32 8, i32* %8
%13 = load i32, i32* %2
%14 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%15 = call i32 @getsockname(i32 %13, %struct.sockaddr* %14, i32* %7)
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%18 = trunc i64 %10 to i32
%19 = call i32 @inet_ntop(i32 %16, i32* %17, i8* %12, i32 %18)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @ntohs(i32 %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %22)
%24 = load i32, i32* %2
%25 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%26 = call i32 @getpeername(i32 %24, %struct.sockaddr* %25, i32* %8)
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%29 = trunc i64 %10 to i32
%30 = call i32 @inet_ntop(i32 %27, i32* %28, i8* %12, i32 %29)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%32 = load i32, i32* %31
%33 = call i32 @ntohs(i32 %32)
%34 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %12, i32 %33)
%35 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@INET_ADDRSTRLEN = global i32 0
@AF_INET = global i32 0
@.str = [15 x i8] c"host at %s:%d\0A\00"
@.str.1 = [17 x i8] c"remote at %s:%d\0A\00"
define void @print_socket_info(i32 %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = bitcast %struct.sockaddr_in* %2 to i8*
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = load i32, i32* @INET_ADDRSTRLEN
%9 = zext i32 %8 to i64
%10 = tail call i8* @llvm.stacksave()
%11 = alloca i8, i64 %9
%12 = bitcast i32* %4 to i8*
store i32 8, i32* %4
%13 = bitcast i32* %5 to i8*
store i32 8, i32* %5
%14 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%15 = call i32 @getsockname(i32 %0, %struct.sockaddr* %14, i32* %4)
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
%18 = call i32 @inet_ntop(i32 %16, i32* %17, i8* %11, i32 %8)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @ntohs(i32 %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %21)
%23 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%24 = call i32 @getpeername(i32 %0, %struct.sockaddr* %23, i32* %5)
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%27 = call i32 @inet_ntop(i32 %25, i32* %26, i8* %11, i32 %8)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%29 = load i32, i32* %28
%30 = call i32 @ntohs(i32 %29)
%31 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 %30)
ret void
}