#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 identify(int socket) {
  char ipstr[INET6_ADDRSTRLEN];
  socklen_t len;
  struct sockaddr_in *s;
  int port;
  struct sockaddr_storage addr;
  len = sizeof addr;
  getpeername(socket, (struct sockaddr *)&addr, &len);
  s = (struct sockaddr_in *)&addr;
  port = ntohs(s->sin_port);
  inet_ntop(AF_INET, &s->sin_addr, ipstr, sizeof ipstr);
  printf("identify: received new request from %s port %d\n", ipstr, port);
  return;
}


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

x86 assembly (clang, -O2):
<identify>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2e92(%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,-0x2c(%rbp)
lea    -0x28(%rbp),%r15
lea    -0x2c(%rbp),%rdx
mov    %r15,%rsi
call   1040 <getpeername@plt>
mov    -0x24(%rbp),%edi
call   1060 <ntohs@plt>
mov    %eax,%r12d
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   1030 <inet_ntop@plt>
lea    0xe53(%rip),%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1050 <printf@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_INET = global i32 0
@.str = [48 x i8] c"identify: received new request from %s port %d\0A\00"
define void @identify(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca %struct.sockaddr_in*
%7 = alloca i32
%8 = alloca %struct.sockaddr_storage
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** %3
%12 = alloca i8, i64 %10
store i64 %10, i64* %4
store i32 4, i32* %5
%13 = load i32, i32* %2
%14 = bitcast %struct.sockaddr_storage* %8 to %struct.sockaddr*
%15 = call i32 @getpeername(i32 %13, %struct.sockaddr* %14, i32* %5)
%16 = bitcast %struct.sockaddr_storage* %8 to %struct.sockaddr_in*
store %struct.sockaddr_in* %16, %struct.sockaddr_in** %6
%17 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%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** %6
%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 ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %26)
%28 = load i8*, i8** %3
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 = [48 x i8] c"identify: received new request from %s port %d\0A\00"
define void @identify(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_storage
%4 = load i32, i32* @INET6_ADDRSTRLEN
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = bitcast i32* %2 to i8*
%8 = bitcast %struct.sockaddr_storage* %3 to i8*
store i32 4, i32* %2
%9 = bitcast %struct.sockaddr_storage* %3 to %struct.sockaddr*
%10 = call i32 @getpeername(i32 %0, %struct.sockaddr* %9, i32* %2)
%11 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %3, i64 1, i32 0
%12 = load i32, i32* %11
%13 = call i32 @ntohs(i32 %12)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %3, i64 0, i32 0
%16 = call i32 @inet_ntop(i32 %14, i32* %15, i8* %6, i32 %4)
%17 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %6, i32 %13)
ret void
}