#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;
typedef size_t socklen_t;

/* Variables and functions */
int /*<<< orphan*/ ENOSPC;
int /*<<< orphan*/ errno;
scalar_t__ sprintf(char *, char const *, int /*<<< orphan*/ const,
                   int /*<<< orphan*/ const, int /*<<< orphan*/ const,
                   int /*<<< orphan*/ const);
int /*<<< orphan*/ strcpy(char *, char *);
const char *inet_ntop4(const u_char *src, char *dst, socklen_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),%edx
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%r9d
lea    0xea4(%rip),%rsi
call   1040 <sprintf@plt>
cmp    -0x20(%rbp),%rax
jbe    118a <inet_ntop4+0x6a>
mov    0x2e66(%rip),%rax
mov    (%rax),%ecx
mov    0x2e65(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    119f <inet_ntop4+0x7f>
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
mov    (%rdi),%edx
mov    0x4(%rdi),%ecx
mov    0x8(%rdi),%r8d
mov    0xc(%rdi),%r9d
lea    0xebf(%rip),%rsi
mov    %rsp,%rdi
call   1040 <sprintf@plt>
cmp    %r14,%rax
jbe    1164 <inet_ntop4+0x44>
mov    0x2e83(%rip),%rax
mov    (%rax),%eax
mov    0x2e82(%rip),%rcx
mov    %eax,(%rcx)
xor    %ebx,%ebx
jmp    116f <inet_ntop4+0x4f>
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(i32* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [16 x i8]
store i32* %0, i32** %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 i32*, i32** %5
%11 = getelementptr inbounds i32, i32* %10, i64 0
%12 = load i32, i32* %11
%13 = load i32*, i32** %5
%14 = getelementptr inbounds i32, i32* %13, i64 1
%15 = load i32, i32* %14
%16 = load i32*, i32** %5
%17 = getelementptr inbounds i32, i32* %16, i64 2
%18 = load i32, i32* %17
%19 = load i32*, i32** %5
%20 = getelementptr inbounds i32, i32* %19, i64 3
%21 = load i32, i32* %20
%22 = call i64 @sprintf(i8* %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @inet_ntop4.fmt, i64 0, i64 0), i32 %12, i32 %15, i32 %18, i32 %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(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 i64 @sprintf(i8* %5, 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 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
}