#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;
struct in_addr {
  int /*<<< orphan*/ s_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ *inet_ntop(int /*<<< orphan*/, struct in_addr *, char *,
                              size_t);
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int /*<<< orphan*/);
int sock_addr_ntop(char *str, size_t len, uint32_t ip) {
  struct in_addr ia;
  ia.s_addr = ip;
  if (NULL == inet_ntop(AF_INET, &ia, str, len)) {
    printf("inet_ntop: %s\n", strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<sock_addr_ntop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e98(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%rsi
call   1030 <inet_ntop@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    119a <sock_addr_ntop+0x6a>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rsi
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a1 <sock_addr_ntop+0x71>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_addr_ntop>:
push   %rax
mov    %rsi,%rcx
mov    %rdi,%rax
mov    %edx,(%rsp)
mov    0x2ea7(%rip),%rdx
mov    (%rdx),%edi
mov    %rsp,%rsi
mov    %rax,%rdx
call   1030 <inet_ntop@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     115a <sock_addr_ntop+0x2a>
pop    %rcx
ret
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe91(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@AF_INET = global i32 0
@.str = [15 x i8] c"inet_ntop: %s\0A\00"
@errno = global i32 0
define i32 @sock_addr_ntop(i8* %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca %struct.in_addr
store i8* %0, i8** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
%9 = load i32, i32* %7
%10 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %8, i32 0, i32 0
store i32 %9, i32* %10
%11 = load i32, i32* @AF_INET
%12 = load i8*, i8** %5
%13 = load i64, i64* %6
%14 = call i32* @inet_ntop(i32 %11, %struct.in_addr* %8, i8* %12, i64 %13)
%15 = icmp eq i32* null, %14
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 -1, i32* %4
br label %21
20: ; preds = %3
store i32 0, i32* %4
br label %21
21: ; preds = %20, %16
%22 = load i32, i32* %4
ret i32 %22
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@AF_INET = global i32 0
@.str = [15 x i8] c"inet_ntop: %s\0A\00"
@errno = global i32 0
define i32 @sock_addr_ntop(i8* %0, i64 %1, i32 %2) {
%4 = alloca %struct.in_addr
%5 = bitcast %struct.in_addr* %4 to i8*
%6 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i64 0, i32 0
store i32 %2, i32* %6
%7 = load i32, i32* @AF_INET
%8 = call i32* @inet_ntop(i32 %7, %struct.in_addr* %4, i8* %0, i64 %1)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %3, %10
%15 = phi i32 [ -1, %10 ], [ 0, %3 ]
ret i32 %15
}