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

/* Variables and functions */
int NI_MAXHOST;
int NI_MAXSERV;
scalar_t__ getnameinfo(struct sockaddr *, int /*<<< orphan*/, char *, int,
                       char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void report_peer_connected(const struct sockaddr_in *sa, socklen_t salen) {
  char hostbuf[NI_MAXHOST];
  char portbuf[NI_MAXSERV];
  if (getnameinfo((struct sockaddr *)sa, salen, hostbuf, NI_MAXHOST, portbuf,
                  NI_MAXSERV, 0) == 0) {
    printf("peer (%s, %s) connected\n", hostbuf, portbuf);
  } else {
    printf("peer (unknonwn) connected\n");
  }
}


x86 assembly (clang, -O0):
<report_peer_connected>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x38(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x20(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%eax
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%r8
sub    %rcx,%r8
mov    %r8,-0x30(%rbp)
mov    %r8,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2e4a(%rip),%rax
mov    (%rax),%ecx
mov    0x2e51(%rip),%rax
mov    (%rax),%r9d
xor    %eax,%eax
sub    $0x10,%rsp
movl   $0x0,(%rsp)
call   1040 <getnameinfo@plt>
add    $0x10,%rsp
cmp    $0x0,%rax
jne    11d5 <report_peer_connected+0xb5>
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rsi
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e3 <report_peer_connected+0xc3>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<report_peer_connected>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    0x2e9a(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%r14
mov    %rcx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    0x2e8d(%rip),%rax
mov    (%rax),%r9d
mov    %rsp,%rbx
mov    %r9,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
sub    $0x8,%rsp
mov    %r14,%rdx
mov    %rbx,%r8
push   $0x0
call   1050 <getnameinfo@plt>
add    $0x10,%rsp
test   %rax,%rax
je     119a <report_peer_connected+0x6a>
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
jmp    11ae <report_peer_connected+0x7e>
lea    0xe5f(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@.str = [25 x i8] c"peer (%s, %s) connected\0A\00"
@.str.1 = [27 x i8] c"peer (unknonwn) connected\0A\00"
define void @report_peer_connected(%struct.sockaddr_in* %0, i32 %1) {
%3 = alloca %struct.sockaddr_in*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %3
store i32 %1, i32* %4
%8 = load i32, i32* @NI_MAXHOST
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i8, i64 %9
store i64 %9, i64* %6
%12 = load i32, i32* @NI_MAXSERV
%13 = zext i32 %12 to i64
%14 = alloca i8, i64 %13
store i64 %13, i64* %7
%15 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%16 = bitcast %struct.sockaddr_in* %15 to %struct.sockaddr*
%17 = load i32, i32* %4
%18 = load i32, i32* @NI_MAXHOST
%19 = load i32, i32* @NI_MAXSERV
%20 = call i64 @getnameinfo(%struct.sockaddr* %16, i32 %17, i8* %11, i32 %18, i8* %14, i32 %19, i32 0)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %14)
br label %26
24: ; preds = %2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %22
%27 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@.str = [25 x i8] c"peer (%s, %s) connected\0A\00"
@str = [26 x i8] c"peer (unknonwn) connected\00"
define void @report_peer_connected(%struct.sockaddr_in* %0, i32 %1) {
%3 = load i32, i32* @NI_MAXHOST
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = load i32, i32* @NI_MAXSERV
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = bitcast %struct.sockaddr_in* %0 to %struct.sockaddr*
%10 = call i64 @getnameinfo(%struct.sockaddr* %9, i32 %1, i8* %5, i32 %3, i8* %8, i32 %6, i32 0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %8)
br label %16
14: ; preds = %2
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %16
16: ; preds = %14, %12
ret void
}