#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 *, void *);
scalar_t__ strchr(char const *, char);
int addr_parse_raw(void *dest, const char *src) {
  int af;
  af = strchr(src, ':') ? AF_INET6 : AF_INET;
  if (inet_pton(af, src, dest) <= 0)
    return -1;
  return af;
}


x86 assembly (clang, -O0):
<addr_parse_raw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     1159 <addr_parse_raw+0x39>
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    1165 <addr_parse_raw+0x45>
mov    0x2e88(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <inet_pton@plt>
cmp    $0x0,%rax
jg     1191 <addr_parse_raw+0x71>
movl   $0xffffffff,-0x4(%rbp)
jmp    1197 <addr_parse_raw+0x77>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addr_parse_raw>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1145 <addr_parse_raw+0x25>
mov    0x2ea5(%rip),%rax
jmp    114c <addr_parse_raw+0x2c>
mov    0x2e94(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <inet_pton@plt>
test   %rax,%rax
mov    $0xffffffff,%eax
cmovg  %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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