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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ getpeername(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_ip_port(int sfd) {
  socklen_t len;
  struct sockaddr_storage addr;
  char ipstr[INET6_ADDRSTRLEN];
  int port;
  len = sizeof addr;
  getpeername(sfd, (struct sockaddr *)&addr, &len);
  struct sockaddr_in *s = (struct sockaddr_in *)&addr;
  port = ntohs(s->sin_port);
  inet_ntop(AF_INET, &s->sin_addr, ipstr, sizeof ipstr);
  printf("%s:%d\n", ipstr, port);
}


x86 assembly (clang, -O0):
<print_ip_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e96(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%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,-0x20(%rbp)
movl   $0x4,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x8(%rbp),%rdx
call   1040 <getpeername@plt>
lea    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%edi
call   1060 <ntohs@plt>
mov    -0x38(%rbp),%rdx
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
mov    %ecx,-0x24(%rbp)
mov    0x2e26(%rip),%rcx
mov    (%rcx),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x38(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xe2b(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_ip_port>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsp,%r13
mov    0x2e8d(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
movl   $0x4,-0x34(%rbp)
lea    -0x30(%rbp),%r15
lea    -0x34(%rbp),%rdx
mov    %r15,%rsi
call   1040 <getpeername@plt>
mov    -0x2c(%rbp),%edi
call   1060 <ntohs@plt>
mov    %eax,%r12d
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   1030 <inet_ntop@plt>
lea    0xe4e(%rip),%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1050 <printf@plt>
mov    %r13,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_INET = global i32 0
@.str = [7 x i8] c"%s:%d\0A\00"
define void @print_ip_port(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_storage
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca %struct.sockaddr_in*
store i32 %0, i32* %2
%9 = load i32, i32* @INET6_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 4, i32* %3
%13 = load i32, i32* %2
%14 = bitcast %struct.sockaddr_storage* %4 to %struct.sockaddr*
%15 = call i32 @getpeername(i32 %13, %struct.sockaddr* %14, i32* %3)
%16 = bitcast %struct.sockaddr_storage* %4 to %struct.sockaddr_in*
store %struct.sockaddr_in* %16, %struct.sockaddr_in** %8
%17 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 1
%19 = load i32, i32* %18
%20 = call i32 @ntohs(i32 %19)
store i32 %20, i32* %7
%21 = load i32, i32* @AF_INET
%22 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %22, i32 0, i32 0
%24 = trunc i64 %10 to i32
%25 = call i32 @inet_ntop(i32 %21, i32* %23, i8* %12, i32 %24)
%26 = load i32, i32* %7
%27 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %26)
%28 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_INET = global i32 0
@.str = [7 x i8] c"%s:%d\0A\00"
define void @print_ip_port(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_storage
%4 = bitcast i32* %2 to i8*
%5 = bitcast %struct.sockaddr_storage* %3 to i8*
%6 = load i32, i32* @INET6_ADDRSTRLEN
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
store i32 4, i32* %2
%10 = bitcast %struct.sockaddr_storage* %3 to %struct.sockaddr*
%11 = call i32 @getpeername(i32 %0, %struct.sockaddr* %10, i32* %2)
%12 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %3, i64 1, i32 0
%13 = load i32, i32* %12
%14 = call i32 @ntohs(i32 %13)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %3, i64 0, i32 0
%17 = call i32 @inet_ntop(i32 %15, i32* %16, i8* %9, i32 %6)
%18 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %9, i32 %14)
ret void
}