#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 */

/* Variables and functions */
int AF_INET;
int AF_INET6;
scalar_t__ inet_pton(int, char const *, unsigned int *);
scalar_t__ strchr(char const *, char);
int get_netaddr(const char *ip_str, unsigned int *ip) {
  if (strchr(ip_str, ':')) {
    if (inet_pton(AF_INET6, ip_str, ip) <= 0)
      return -1;
    return AF_INET6;
  }
  if (inet_pton(AF_INET, ip_str, ip) <= 0)
    return -1;
  return AF_INET;
}


x86 assembly (clang, -O0):
<get_netaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     1185 <get_netaddr+0x65>
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <inet_pton@plt>
cmp    $0x0,%rax
jg     1174 <get_netaddr+0x54>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bd <get_netaddr+0x9d>
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11bd <get_netaddr+0x9d>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <inet_pton@plt>
cmp    $0x0,%rax
jg     11b1 <get_netaddr+0x91>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bd <get_netaddr+0x9d>
mov    0x2e30(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_netaddr>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1143 <get_netaddr+0x23>
mov    0x2ea7(%rip),%r15
jmp    114a <get_netaddr+0x2a>
mov    0x2e96(%rip),%r15
mov    (%r15),%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <inet_pton@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jle    1168 <get_netaddr+0x48>
mov    (%r15),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@AF_INET6 = global i32 0
@AF_INET = global i32 0
define i32 @get_netaddr(i8* %0, i32* %1) {
%3 = tail call i64 @strchr(i8* %0, i8 signext 58)
%4 = icmp eq i64 %3, 0
%5 = select i1 %4, i32* @AF_INET, i32* @AF_INET6
%6 = load i32, i32* %5
%7 = tail call i64 @inet_pton(i32 %6, i8* %0, i32* %1)
%8 = icmp slt i64 %7, 1
%9 = load i32, i32* %5
%10 = select i1 %8, i32 -1, i32 %9
ret i32 %10
}