#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 u_char;
typedef int /*<<< orphan*/ tmp;

/* Variables and functions */
int /*<<< orphan*/ ENOSPC;
int /*<<< orphan*/ errno;
int snprintf(char *, int, char *, int const, int const, int const, int const);
int /*<<< orphan*/ strlcpy(char *, char *, size_t);
const char *inet_ntop4(const u_char *src, char *dst, size_t size) {
  char tmp[sizeof "255.255.255.255"];
  int l;
  l = snprintf(tmp, sizeof(tmp), "%u.%u.%u.%u", src[0], src[1], src[2], src[3]);
  if (l <= 0 || 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    -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
mov    $0x10,%esi
lea    0xe9f(%rip),%rdx
mov    %eax,(%rsp)
call   1030 <snprintf@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jle    1184 <inet_ntop4+0x64>
movslq -0x34(%rbp),%rax
cmp    -0x20(%rbp),%rax
jb     11a3 <inet_ntop4+0x83>
mov    0x2e4d(%rip),%rax
mov    (%rax),%ecx
mov    0x2e4c(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    11bc <inet_ntop4+0x9c>
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,%r14
mov    %rsi,%rbx
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    $0x10,%esi
call   1030 <snprintf@plt>
test   %eax,%eax
jle    1170 <inet_ntop4+0x50>
cltq
cmp    %r14,%rax
jae    1170 <inet_ntop4+0x50>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <strlcpy@plt>
jmp    1184 <inet_ntop4+0x64>
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    0x2e60(%rip),%rcx
mov    %eax,(%rcx)
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [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 i32*, i32** %5
%12 = getelementptr inbounds i32, i32* %11, i64 0
%13 = load i32, i32* %12
%14 = load i32*, i32** %5
%15 = getelementptr inbounds i32, i32* %14, i64 1
%16 = load i32, i32* %15
%17 = load i32*, i32** %5
%18 = getelementptr inbounds i32, i32* %17, i64 2
%19 = load i32, i32* %18
%20 = load i32*, i32** %5
%21 = getelementptr inbounds i32, i32* %20, i64 3
%22 = load i32, i32* %21
%23 = call i32 @snprintf(i8* %10, i32 16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %16, i32 %19, i32 %22)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = icmp sle i32 %24, 0
br i1 %25, label %31, label %26
26: ; preds = %3
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = load i64, i64* %7
%30 = icmp uge i64 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %26, %3
%32 = load i32, i32* @ENOSPC
store i32 %32, i32* @errno
store i8* null, i8** %4
br label %39
33: ; preds = %26
%34 = load i8*, i8** %6
%35 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%36 = load i64, i64* %7
%37 = call i32 @strlcpy(i8* %34, i8* %35, i64 %36)
%38 = load i8*, i8** %6
store i8* %38, i8** %4
br label %39
39: ; preds = %33, %31
%40 = load i8*, i8** %4
ret i8* %40
}

LLVM IR (-O2):
@.str = [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, i32 16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %8, i32 %10, i32 %12)
%14 = icmp sgt i32 %13, 0
%15 = sext 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
}