#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;
};
struct in6_addr {
  int dummy;
};

/* Variables and functions */
int AF_INET;
int AF_INET6;
int /*<<< orphan*/ inet_pton(int, char const *, void *);
int pton(int domain, void *buf, const char *ip) {
  if (domain == AF_INET) {
    inet_pton(AF_INET, ip, buf);
    return sizeof(struct in_addr);
  }
  if (domain == AF_INET6) {
    inet_pton(AF_INET6, ip, buf);
    return sizeof(struct in6_addr);
  }
  return -1;
}


x86 assembly (clang, -O0):
<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    0x2ebb(%rip),%rcx
cmp    (%rcx),%eax
jne    1157 <pton+0x47>
mov    0x2eac(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1030 <inet_pton@plt>
movl   $0x4,-0x4(%rbp)
jmp    1192 <pton+0x82>
mov    -0x8(%rbp),%eax
mov    0x2e7f(%rip),%rcx
cmp    (%rcx),%eax
jne    118b <pton+0x7b>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1030 <inet_pton@plt>
movl   $0x4,-0x4(%rbp)
jmp    1192 <pton+0x82>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pton>:
push   %rax
mov    %rsi,%rcx
mov    0x2ecd(%rip),%rax
cmp    %edi,(%rax)
je     1131 <pton+0x21>
mov    0x2eba(%rip),%rsi
mov    $0xffffffff,%eax
cmp    %edi,(%rsi)
je     1131 <pton+0x21>
pop    %rcx
ret
mov    %rdx,%rsi
mov    %rcx,%rdx
call   1030 <inet_pton@plt>
mov    $0x4,%eax
pop    %rcx
ret

LLVM IR (-O0):
@AF_INET = global i32 0
@AF_INET6 = global i32 0
define i32 @pton(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%8 = load i32, i32* %5
%9 = load i32, i32* @AF_INET
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %16
11: ; preds = %3
%12 = load i32, i32* @AF_INET
%13 = load i8*, i8** %7
%14 = load i8*, i8** %6
%15 = call i32 @inet_pton(i32 %12, i8* %13, i8* %14)
store i32 4, i32* %4
br label %26
16: ; preds = %3
%17 = load i32, i32* %5
%18 = load i32, i32* @AF_INET6
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i32, i32* @AF_INET6
%22 = load i8*, i8** %7
%23 = load i8*, i8** %6
%24 = call i32 @inet_pton(i32 %21, i8* %22, i8* %23)
store i32 4, i32* %4
br label %26
25: ; preds = %16
store i32 -1, i32* %4
br label %26
26: ; preds = %25, %20, %11
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
@AF_INET = global i32 0
@AF_INET6 = global i32 0
define i32 @pton(i32 %0, i8* %1, i8* %2) {
%4 = load i32, i32* @AF_INET
%5 = icmp eq i32 %4, %0
%6 = load i32, i32* @AF_INET6
%7 = icmp eq i32 %6, %0
%8 = select i1 %5, i1 true, i1 %7
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 @inet_pton(i32 %0, i8* %2, i8* %1)
br label %11
11: ; preds = %3, %9
%12 = phi i32 [ 4, %9 ], [ -1, %3 ]
ret i32 %12
}