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

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


x86 assembly (clang, -O0):
<inet_ntop4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%dl
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x10(%rbp),%rax
mov    0x2(%rax),%r8b
mov    -0x10(%rbp),%rax
lea    0xea8(%rip),%rsi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl 0x3(%rax),%r9d
call   1040 <sprintf@plt>
cmp    -0x20(%rbp),%rax
jbe    1195 <inet_ntop4+0x75>
mov    0x2e5b(%rip),%rax
mov    (%rax),%ecx
mov    0x2e5a(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    11aa <inet_ntop4+0x8a>
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet_ntop4>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
movzbl (%rdi),%edx
movzbl 0x1(%rdi),%ecx
movzbl 0x2(%rdi),%r8d
movzbl 0x3(%rdi),%r9d
lea    0xebb(%rip),%rsi
mov    %rsp,%rdi
call   1040 <sprintf@plt>
cmp    %r14,%rax
jbe    1168 <inet_ntop4+0x48>
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
mov    0x2e7e(%rip),%rcx
mov    %eax,(%rcx)
xor    %ebx,%ebx
jmp    1173 <inet_ntop4+0x53>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rax
add    $0x18,%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(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [16 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%10 = load i8*, i8** %5
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = load i8, i8* %14
%16 = load i8*, i8** %5
%17 = getelementptr inbounds i8, i8* %16, i64 2
%18 = load i8, i8* %17
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 3
%21 = load i8, i8* %20
%22 = call i64 @sprintf(i8* %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @inet_ntop4.fmt, i64 0, i64 0), i8 zeroext %12, i8 zeroext %15, i8 zeroext %18, i8 zeroext %21)
%23 = load i64, i64* %7
%24 = icmp ugt i64 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %3
%26 = load i32, i32* @ENOSPC
store i32 %26, i32* @errno
store i8* null, i8** %4
br label %32
27: ; preds = %3
%28 = load i8*, i8** %6
%29 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%30 = call i32 @strcpy(i8* %28, i8* %29)
%31 = load i8*, i8** %6
store i8* %31, i8** %4
br label %32
32: ; preds = %27, %25
%33 = load i8*, i8** %4
ret i8* %33
}

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(i8* 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 i8, i8* %0
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = load i8, i8* %7
%9 = getelementptr inbounds i8, i8* %0, i64 2
%10 = load i8, i8* %9
%11 = getelementptr inbounds i8, i8* %0, i64 3
%12 = load i8, i8* %11
%13 = call i64 @sprintf(i8* %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @inet_ntop4.fmt, i64 0, i64 0), i8 zeroext %6, i8 zeroext %8, i8 zeroext %10, i8 zeroext %12)
%14 = icmp ugt i64 %13, %2
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = load i32, i32* @ENOSPC
store i32 %16, i32* @errno
br label %19
17: ; preds = %3
%18 = call i32 @strcpy(i8* %1, i8* %5)
br label %19
19: ; preds = %17, %15
%20 = phi i8* [ null, %15 ], [ %1, %17 ]
ret i8* %20
}