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

/* 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) {
  u_long result;
  if (af == AF_INET) {
    result = inet_addr(src);
    if (result == -1)
      return 0;
    else {
      memcpy(dst, &result, 4);
      return 1;
    }
  } else {
    errno = EAFNOSUPPORT;
    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
jne    1185 <inet_pton+0x65>
mov    -0x10(%rbp),%rdi
call   1030 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1167 <inet_pton+0x47>
movl   $0x0,-0x4(%rbp)
jmp    119e <inet_pton+0x7e>
mov    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
movl   $0x1,-0x4(%rbp)
jmp    119e <inet_pton+0x7e>
mov    0x2e44(%rip),%rax
mov    (%rax),%ecx
mov    0x2e43(%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>:
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 eq i32 %9, %10
br i1 %11, label %12, label %21
12: ; preds = %3
%13 = load i8*, i8** %6
%14 = call i32 @inet_addr(i8* %13)
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %12
store i32 0, i32* %4
br label %23
18: ; preds = %12
%19 = load i8*, i8** %7
%20 = call i32 @memcpy(i8* %19, i32* %8, i32 4)
store i32 1, i32* %4
br label %23
21: ; preds = %3
%22 = load i32, i32* @EAFNOSUPPORT
store i32 %22, i32* @errno
store i32 -1, i32* %4
br label %23
23: ; preds = %21, %18, %17
%24 = load i32, i32* %4
ret i32 %24
}

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 %8, label %13
8: ; preds = %3
%9 = tail call i32 @inet_addr(i8* %1)
store i32 %9, i32* %4
%10 = icmp eq i32 %9, -1
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = call i32 @memcpy(i8* %2, i32* %4, i32 4)
br label %15
13: ; preds = %3
%14 = load i32, i32* @EAFNOSUPPORT
store i32 %14, i32* @errno
br label %15
15: ; preds = %8, %13, %11
%16 = phi i32 [ 1, %11 ], [ -1, %13 ], [ 0, %8 ]
ret i32 %16
}