#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 */
struct in_addr {
  int dummy;
};
typedef int /*<<< orphan*/ in_val;

/* Variables and functions */
int AF_INET;
int /*<<< orphan*/ EAFNOSUPPORT;
int /*<<< orphan*/ errno;
scalar_t__ inet_aton(char const *, struct in_addr *);
int /*<<< orphan*/ memcpy(void *, struct in_addr *, int);
int inet_pton_l(int family, const char *src, void *dst) {
  if (family == AF_INET) {
    struct in_addr in_val;
    if (inet_aton(src, &in_val)) {
      memcpy(dst, &in_val, sizeof(in_val));
      return 1;
    }
    return 0;
  }
  errno = EAFNOSUPPORT;
  return -1;
}


x86 assembly (clang, -O0):
<inet_pton_l>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2eab(%rip),%rcx
cmp    (%rcx),%eax
jne    1186 <inet_pton_l+0x66>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <inet_aton@plt>
cmp    $0x0,%rax
je     117a <inet_pton_l+0x5a>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
movl   $0x1,-0x4(%rbp)
jmp    119f <inet_pton_l+0x7f>
movl   $0x0,-0x4(%rbp)
jmp    119f <inet_pton_l+0x7f>
mov    0x2e43(%rip),%rax
mov    (%rax),%ecx
mov    0x2e42(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet_pton_l>:
push   %rbx
sub    $0x10,%rsp
mov    0x2ebc(%rip),%rax
cmp    %edi,(%rax)
jne    1161 <inet_pton_l+0x41>
mov    %rdx,%rbx
lea    0x8(%rsp),%rax
mov    %rsi,%rdi
mov    %rax,%rsi
call   1040 <inet_aton@plt>
test   %rax,%rax
je     117a <inet_pton_l+0x5a>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    $0x1,%eax
jmp    117c <inet_pton_l+0x5c>
mov    0x2e68(%rip),%rax
mov    (%rax),%eax
mov    0x2e67(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
jmp    117c <inet_pton_l+0x5c>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@AF_INET = global i32 0
@EAFNOSUPPORT = global i32 0
@errno = global i32 0
define i32 @inet_pton_l(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.in_addr
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i32, i32* %5
%10 = load i32, i32* @AF_INET
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %20
12: ; preds = %3
%13 = load i8*, i8** %6
%14 = call i64 @inet_aton(i8* %13, %struct.in_addr* %8)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i8*, i8** %7
%18 = call i32 @memcpy(i8* %17, %struct.in_addr* %8, i32 4)
store i32 1, i32* %4
br label %22
19: ; preds = %12
store i32 0, i32* %4
br label %22
20: ; preds = %3
%21 = load i32, i32* @EAFNOSUPPORT
store i32 %21, i32* @errno
store i32 -1, i32* %4
br label %22
22: ; preds = %20, %19, %16
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@AF_INET = global i32 0
@EAFNOSUPPORT = global i32 0
@errno = global i32 0
define i32 @inet_pton_l(i32 %0, i8* %1, i8* %2) {
%4 = alloca %struct.in_addr
%5 = load i32, i32* @AF_INET
%6 = icmp eq i32 %5, %0
br i1 %6, label %7, label %15
7: ; preds = %3
%8 = bitcast %struct.in_addr* %4 to i8*
%9 = call i64 @inet_aton(i8* %1, %struct.in_addr* %4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = call i32 @memcpy(i8* %2, %struct.in_addr* %4, i32 4)
br label %13
13: ; preds = %7, %11
%14 = phi i32 [ 1, %11 ], [ 0, %7 ]
br label %17
15: ; preds = %3
%16 = load i32, i32* @EAFNOSUPPORT
store i32 %16, i32* @errno
br label %17
17: ; preds = %15, %13
%18 = phi i32 [ %14, %13 ], [ -1, %15 ]
ret i32 %18
}