#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*/ temp;
typedef scalar_t__ socklen_t;

/* Variables and functions */
int AF_INET;
int /*<<< orphan*/ EAFNOSUPPORT;
int /*<<< orphan*/ ENOSPC;
int INET_ADDRSTRLEN;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ snprintf(char *, int, char *, int const, int const,
                            int const, int const);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
const char *inet_ntop_l(int family, const void *src, char *dst, socklen_t len) {
  const u_char *p = (const u_char *)src;
  if (family == AF_INET) {
    char temp[INET_ADDRSTRLEN];
    snprintf(temp, sizeof(temp), "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
    if (strlen(temp) >= len) {
      errno = ENOSPC;
      return NULL;
    }
    strcpy(dst, temp);
    return dst;
  }
  errno = EAFNOSUPPORT;
  return NULL;
}


x86 assembly (clang, -O0):
<inet_ntop_l>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e8f(%rip),%rcx
cmp    (%rcx),%eax
jne    1224 <inet_ntop_l+0xf4>
mov    0x2e68(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x50(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x40(%rbp)
mov    %eax,%esi
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%r8d
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%r9d
mov    -0x30(%rbp),%rax
mov    0xc(%rax),%eax
lea    0xe4d(%rip),%rdx
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1050 <snprintf@plt>
mov    -0x50(%rbp),%rdi
add    $0x10,%rsp
call   1040 <strlen@plt>
cmp    -0x28(%rbp),%rax
jl     11fc <inet_ntop_l+0xcc>
mov    0x2deb(%rip),%rax
mov    (%rax),%ecx
mov    0x2df2(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    1218 <inet_ntop_l+0xe8>
mov    -0x50(%rbp),%rsi
mov    -0x20(%rbp),%rdi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
jmp    123e <inet_ntop_l+0x10e>
mov    0x2d95(%rip),%rax
mov    (%rax),%ecx
mov    0x2da4(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet_ntop_l>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2ea6(%rip),%rax
cmp    %edi,(%rax)
jne    11af <inet_ntop_l+0x7f>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsp,%r12
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
mov    (%rsi),%ecx
mov    0x4(%rsi),%r8d
mov    0x8(%rsi),%r9d
mov    0xc(%rsi),%r10d
sub    $0x8,%rsp
lea    0xe7b(%rip),%rdx
mov    %rbx,%rdi
mov    %eax,%esi
push   %r10
call   1050 <snprintf@plt>
add    $0x10,%rsp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %r14,%rax
jge    11c6 <inet_ntop_l+0x96>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
jmp    11db <inet_ntop_l+0xab>
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
mov    0x2e19(%rip),%rcx
mov    %eax,(%rcx)
xor    %r15d,%r15d
jmp    11de <inet_ntop_l+0xae>
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
mov    0x2e02(%rip),%rcx
mov    %eax,(%rcx)
xor    %r15d,%r15d
mov    %r12,%rsp
mov    %r15,%rax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@AF_INET = global i32 0
@INET_ADDRSTRLEN = global i32 0
@.str = [12 x i8] c"%d.%d.%d.%d\00"
@ENOSPC = global i32 0
@errno = global i32 0
@EAFNOSUPPORT = global i32 0
define i8* @inet_ntop_l(i32 %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%14 = load i8*, i8** %7
%15 = bitcast i8* %14 to i32*
store i32* %15, i32** %10
%16 = load i32, i32* %6
%17 = load i32, i32* @AF_INET
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %49
19: ; preds = %4
%20 = load i32, i32* @INET_ADDRSTRLEN
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %11
%23 = alloca i8, i64 %21
store i64 %21, i64* %12
%24 = trunc i64 %21 to i32
%25 = load i32*, i32** %10
%26 = getelementptr inbounds i32, i32* %25, i64 0
%27 = load i32, i32* %26
%28 = load i32*, i32** %10
%29 = getelementptr inbounds i32, i32* %28, i64 1
%30 = load i32, i32* %29
%31 = load i32*, i32** %10
%32 = getelementptr inbounds i32, i32* %31, i64 2
%33 = load i32, i32* %32
%34 = load i32*, i32** %10
%35 = getelementptr inbounds i32, i32* %34, i64 3
%36 = load i32, i32* %35
%37 = call i32 @snprintf(i8* %23, i32 %24, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %27, i32 %30, i32 %33, i32 %36)
%38 = call i64 @strlen(i8* %23)
%39 = load i64, i64* %9
%40 = icmp sge i64 %38, %39
br i1 %40, label %41, label %43
41: ; preds = %19
%42 = load i32, i32* @ENOSPC
store i32 %42, i32* @errno
store i8* null, i8** %5
store i32 1, i32* %13
br label %47
43: ; preds = %19
%44 = load i8*, i8** %8
%45 = call i32 @strcpy(i8* %44, i8* %23)
%46 = load i8*, i8** %8
store i8* %46, i8** %5
store i32 1, i32* %13
br label %47
47: ; preds = %43, %41
%48 = load i8*, i8** %11
br label %51
49: ; preds = %4
%50 = load i32, i32* @EAFNOSUPPORT
store i32 %50, i32* @errno
store i8* null, i8** %5
br label %51
51: ; preds = %49, %47
%52 = load i8*, i8** %5
ret i8* %52
}

LLVM IR (-O2):
@AF_INET = global i32 0
@INET_ADDRSTRLEN = global i32 0
@.str = [12 x i8] c"%d.%d.%d.%d\00"
@ENOSPC = global i32 0
@errno = global i32 0
@EAFNOSUPPORT = global i32 0
define i8* @inet_ntop_l(i32 %0, i8* nocapture %1, i8* %2, i64 %3) {
%5 = load i32, i32* @AF_INET
%6 = icmp eq i32 %5, %0
br i1 %6, label %7, label %32
7: ; preds = %4
%8 = bitcast i8* %1 to i32*
%9 = load i32, i32* @INET_ADDRSTRLEN
%10 = zext i32 %9 to i64
%11 = tail call i8* @llvm.stacksave()
%12 = alloca i8, i64 %10
%13 = load i32, i32* %8
%14 = getelementptr inbounds i8, i8* %1, i64 4
%15 = bitcast i8* %14 to i32*
%16 = load i32, i32* %15
%17 = getelementptr inbounds i8, i8* %1, i64 8
%18 = bitcast i8* %17 to i32*
%19 = load i32, i32* %18
%20 = getelementptr inbounds i8, i8* %1, i64 12
%21 = bitcast i8* %20 to i32*
%22 = load i32, i32* %21
%23 = call i32 @snprintf(i8* %12, i32 %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %16, i32 %19, i32 %22)
%24 = call i64 @strlen(i8* %12)
%25 = icmp slt i64 %24, %3
br i1 %25, label %28, label %26
26: ; preds = %7
%27 = load i32, i32* @ENOSPC
store i32 %27, i32* @errno
br label %30
28: ; preds = %7
%29 = call i32 @strcpy(i8* %2, i8* %12)
br label %30
30: ; preds = %28, %26
%31 = phi i8* [ null, %26 ], [ %2, %28 ]
br label %34
32: ; preds = %4
%33 = load i32, i32* @EAFNOSUPPORT
store i32 %33, i32* @errno
br label %34
34: ; preds = %32, %30
%35 = phi i8* [ %31, %30 ], [ null, %32 ]
ret i8* %35
}