#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 in_addr_t;

/* Variables and functions */
int AF_INET;
int /*<<< orphan*/ EAFNOSUPPORT;
int /*<<< orphan*/ errno;
int inet_addr(char const *);
int /*<<< orphan*/ memcpy(void *, int *, int);
int inet_pton(int af, const char *src, void *dst) {
  in_addr_t addr;
  if (af != AF_INET) {
    errno = EAFNOSUPPORT;
    return -1;
  }
  if ((addr = inet_addr(src)) == -1)
    return 0;
  memcpy(dst, &addr, sizeof addr);
  return 1;
}


x86 assembly (clang, -O0):
<inet_pton>:
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
je     1163 <inet_pton+0x43>
mov    0x2e84(%rip),%rax
mov    (%rax),%ecx
mov    0x2e83(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    119d <inet_pton+0x7d>
mov    -0x10(%rbp),%rdi
call   1030 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1184 <inet_pton+0x64>
movl   $0x0,-0x4(%rbp)
jmp    119d <inet_pton+0x7d>
mov    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet_pton>:
push   %rbx
sub    $0x10,%rsp
mov    0x2ebc(%rip),%rax
cmp    %edi,(%rax)
jne    115d <inet_pton+0x3d>
mov    %rdx,%rbx
mov    %rsi,%rdi
call   1030 <inet_addr@plt>
mov    %eax,0xc(%rsp)
cmp    $0xffffffff,%eax
je     1176 <inet_pton+0x56>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    $0x1,%eax
jmp    1178 <inet_pton+0x58>
mov    0x2e6c(%rip),%rax
mov    (%rax),%eax
mov    0x2e6b(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
jmp    1178 <inet_pton+0x58>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@AF_INET = global i32 0
@EAFNOSUPPORT = global i32 0
@errno = global i32 0
define i32 @inet_pton(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
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 ne i32 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = load i32, i32* @EAFNOSUPPORT
store i32 %13, i32* @errno
store i32 -1, i32* %4
br label %22
14: ; preds = %3
%15 = load i8*, i8** %6
%16 = call i32 @inet_addr(i8* %15)
store i32 %16, i32* %8
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 0, i32* %4
br label %22
19: ; preds = %14
%20 = load i8*, i8** %7
%21 = call i32 @memcpy(i8* %20, i32* %8, i32 4)
store i32 1, i32* %4
br label %22
22: ; preds = %19, %18, %12
%23 = load i32, i32* %4
ret i32 %23
}

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