#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*/ u_char;

/* Variables and functions */
int /*<<< orphan*/ ENOSPC;
int /*<<< orphan*/ errno;
int snprintf(char *, size_t, char const *, int /*<<< orphan*/ const,
             int /*<<< orphan*/ const, int /*<<< orphan*/ const,
             int /*<<< orphan*/ const);
int /*<<< orphan*/ strlcpy(char *, char *, size_t);
const char *inet_ntop4(const u_char *src, char *dst, size_t size) {
  static const char fmt[] = "%u.%u.%u.%u";
  char tmp[sizeof "255.255.255.255"];
  int l;
  l = snprintf(tmp, size, fmt, src[0], src[1], src[2], src[3]);
  if (l <= 0 || (unsigned)l >= size) {
    errno = ENOSPC;
    return (NULL);
  }
  strlcpy(dst, tmp, size);
  return (dst);
}


x86 assembly (clang, -O0):
<inet_ntop4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%r8d
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r9d
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%eax
lea    0xea0(%rip),%rdx
mov    %eax,(%rsp)
call   1030 <snprintf@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jle    1182 <inet_ntop4+0x62>
mov    -0x34(%rbp),%eax
cmp    -0x20(%rbp),%rax
jb     11a1 <inet_ntop4+0x81>
mov    0x2e4f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e4e(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    11ba <inet_ntop4+0x9a>
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <strlcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet_ntop4>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    (%rdi),%ecx
mov    0x4(%rdi),%r8d
mov    0x8(%rdi),%r9d
mov    0xc(%rdi),%eax
mov    %eax,(%rsp)
lea    0xebc(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1030 <snprintf@plt>
test   %eax,%eax
jle    116e <inet_ntop4+0x4e>
mov    %eax,%eax
cmp    %rbx,%rax
jae    116e <inet_ntop4+0x4e>
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1040 <strlcpy@plt>
jmp    1183 <inet_ntop4+0x63>
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    0x2e62(%rip),%rcx
mov    %eax,(%rcx)
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@inet_ntop4.fmt = internal constant [12 x i8] c"%u.%u.%u.%u\00"
@ENOSPC = global i32 0
@errno = global i32 0
define i8* @inet_ntop4(i32* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [16 x i8]
%9 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%11 = load i64, i64* %7
%12 = load i32*, i32** %5
%13 = getelementptr inbounds i32, i32* %12, i64 0
%14 = load i32, i32* %13
%15 = load i32*, i32** %5
%16 = getelementptr inbounds i32, i32* %15, i64 1
%17 = load i32, i32* %16
%18 = load i32*, i32** %5
%19 = getelementptr inbounds i32, i32* %18, i64 2
%20 = load i32, i32* %19
%21 = load i32*, i32** %5
%22 = getelementptr inbounds i32, i32* %21, i64 3
%23 = load i32, i32* %22
%24 = call i32 @snprintf(i8* %10, i64 %11, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @inet_ntop4.fmt, i64 0, i64 0), i32 %14, i32 %17, i32 %20, i32 %23)
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = icmp sle i32 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %3
%28 = load i32, i32* %9
%29 = zext i32 %28 to i64
%30 = load i64, i64* %7
%31 = icmp uge i64 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %27, %3
%33 = load i32, i32* @ENOSPC
store i32 %33, i32* @errno
store i8* null, i8** %4
br label %40
34: ; preds = %27
%35 = load i8*, i8** %6
%36 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%37 = load i64, i64* %7
%38 = call i32 @strlcpy(i8* %35, i8* %36, i64 %37)
%39 = load i8*, i8** %6
store i8* %39, i8** %4
br label %40
40: ; preds = %34, %32
%41 = load i8*, i8** %4
ret i8* %41
}

LLVM IR (-O2):
@inet_ntop4.fmt = internal constant [12 x i8] c"%u.%u.%u.%u\00"
@ENOSPC = global i32 0
@errno = global i32 0
define i8* @inet_ntop4(i32* nocapture %0, i8* %1, i64 %2) {
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%6 = load i32, i32* %0
%7 = getelementptr inbounds i32, i32* %0, i64 1
%8 = load i32, i32* %7
%9 = getelementptr inbounds i32, i32* %0, i64 2
%10 = load i32, i32* %9
%11 = getelementptr inbounds i32, i32* %0, i64 3
%12 = load i32, i32* %11
%13 = call i32 @snprintf(i8* %5, i64 %2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @inet_ntop4.fmt, i64 0, i64 0), i32 %6, i32 %8, i32 %10, i32 %12)
%14 = icmp sgt i32 %13, 0
%15 = zext i32 %13 to i64
%16 = icmp ult i64 %15, %2
%17 = and i1 %14, %16
br i1 %17, label %20, label %18
18: ; preds = %3
%19 = load i32, i32* @ENOSPC
store i32 %19, i32* @errno
br label %22
20: ; preds = %3
%21 = call i32 @strlcpy(i8* %1, i8* %5, i64 %2)
br label %22
22: ; preds = %20, %18
%23 = phi i8* [ null, %18 ], [ %1, %20 ]
ret i8* %23
}