#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*/ uint32_t;
typedef int /*<<< orphan*/ uint16_t;
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/ *, char *,
                             int /*<<< orphan*/);
int /*<<< orphan*/ ntohs(int /*<<< orphan*/);
int sio_dgram_peer_address(struct sockaddr_in *name, char *address,
                           uint32_t len, uint16_t *port) {
  if (address && !inet_ntop(AF_INET, &name->sin_addr, address, len))
    return -1;
  if (port)
    *port = ntohs(name->sin_port);
  return 0;
}


x86 assembly (clang, -O0):
<sio_dgram_peer_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1174 <sio_dgram_peer_address+0x54>
mov    0x2e9f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
add    $0x4,%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1030 <inet_ntop@plt>
cmp    $0x0,%eax
jne    1174 <sio_dgram_peer_address+0x54>
movl   $0xffffffff,-0x4(%rbp)
jmp    1199 <sio_dgram_peer_address+0x79>
cmpq   $0x0,-0x28(%rbp)
je     1192 <sio_dgram_peer_address+0x72>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1040 <ntohs@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sio_dgram_peer_address>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdi,%rbx
test   %rsi,%rsi
je     114a <sio_dgram_peer_address+0x2a>
mov    %edx,%ecx
mov    %rsi,%rdx
mov    0x2ead(%rip),%rax
mov    (%rax),%edi
lea    0x4(%rbx),%rsi
call   1030 <inet_ntop@plt>
test   %eax,%eax
je     115d <sio_dgram_peer_address+0x3d>
xor    %ebp,%ebp
test   %r14,%r14
je     1162 <sio_dgram_peer_address+0x42>
mov    (%rbx),%edi
call   1040 <ntohs@plt>
mov    %eax,(%r14)
jmp    1162 <sio_dgram_peer_address+0x42>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
@AF_INET = global i32 0
define i32 @sio_dgram_peer_address(%struct.sockaddr_in* %0, i8* %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca %struct.sockaddr_in*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%10 = load i8*, i8** %7
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %21
12: ; preds = %4
%13 = load i32, i32* @AF_INET
%14 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 1
%16 = load i8*, i8** %7
%17 = load i32, i32* %8
%18 = call i32 @inet_ntop(i32 %13, i32* %15, i8* %16, i32 %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %12
store i32 -1, i32* %5
br label %31
21: ; preds = %12, %4
%22 = load i32*, i32** %9
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %25, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i32 @ntohs(i32 %27)
%29 = load i32*, i32** %9
store i32 %28, i32* %29
br label %30
30: ; preds = %24, %21
store i32 0, i32* %5
br label %31
31: ; preds = %30, %20
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32 }
@AF_INET = global i32 0
define i32 @sio_dgram_peer_address(%struct.sockaddr_in* %0, i8* %1, i32 %2, i32* writeonly %3) {
%5 = icmp eq i8* %1, null
br i1 %5, label %11, label %6
6: ; preds = %4
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 1
%9 = tail call i32 @inet_ntop(i32 %7, i32* %8, i8* %1, i32 %2)
%10 = icmp eq i32 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %6, %4
%12 = icmp eq i32* %3, null
br i1 %12, label %17, label %13
13: ; preds = %11
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 0
%15 = load i32, i32* %14
%16 = tail call i32 @ntohs(i32 %15)
store i32 %16, i32* %3
br label %17
17: ; preds = %11, %13, %6
%18 = phi i32 [ -1, %6 ], [ 0, %13 ], [ 0, %11 ]
ret i32 %18
}