#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 s_addr;
};

/* Variables and functions */
int AF_INET;
int /*<<< orphan*/ EAFNOSUPPORT;
int /*<<< orphan*/ errno;
int inet_addr(char const *);
int /*<<< orphan*/ memcpy(void *, struct in_addr *, int);
int inet_pton(int family, const char *str, void *addr) {
  struct in_addr tmpaddr;
  if (family != AF_INET) {
    errno = EAFNOSUPPORT;
    return (-1);
  }
  if ((tmpaddr.s_addr = inet_addr(str)) == -1)
    return (0);
  memcpy(addr, &tmpaddr, sizeof(struct in_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,-0x20(%rbp)
cmp    $0xffffffff,%eax
jne    1184 <inet_pton+0x64>
movl   $0x0,-0x4(%rbp)
jmp    119d <inet_pton+0x7d>
mov    -0x18(%rbp),%rdi
lea    -0x20(%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,0x8(%rsp)
cmp    $0xffffffff,%eax
je     1176 <inet_pton+0x56>
lea    0x8(%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):
%struct.in_addr = type { i32 }
@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 %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 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 %23
14: ; preds = %3
%15 = load i8*, i8** %6
%16 = call i32 @inet_addr(i8* %15)
%17 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %8, i32 0, i32 0
store i32 %16, i32* %17
%18 = icmp eq i32 %16, -1
br i1 %18, label %19, label %20
19: ; preds = %14
store i32 0, i32* %4
br label %23
20: ; preds = %14
%21 = load i8*, i8** %7
%22 = call i32 @memcpy(i8* %21, %struct.in_addr* %8, i32 4)
store i32 1, i32* %4
br label %23
23: ; preds = %20, %19, %12
%24 = load i32, i32* %4
ret i32 %24
}

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(i32 %0, i8* %1, i8* %2) {
%4 = alloca %struct.in_addr
%5 = bitcast %struct.in_addr* %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 %16
10: ; preds = %3
%11 = tail call i32 @inet_addr(i8* %1)
%12 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i64 0, i32 0
store i32 %11, i32* %12
%13 = icmp eq i32 %11, -1
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = call i32 @memcpy(i8* %2, %struct.in_addr* %4, i32 4)
br label %16
16: ; preds = %10, %14, %8
%17 = phi i32 [ -1, %8 ], [ 1, %14 ], [ 0, %10 ]
ret i32 %17
}