#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;
int AF_UNSPEC;
char *strchr(char const *, int);
int sfip_str_to_fam(const char *str) {
  const char *s;
  if (!str)
    return 0;
  ;
  s = strchr(str, (int)':');
  if (s && strchr(s + 1, (int)':'))
    return AF_INET6;
  if (strchr(str, (int)'.'))
    return AF_INET;
  return AF_UNSPEC;
}


x86 assembly (clang, -O0):
<sfip_str_to_fam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1133 <sfip_str_to_fam+0x23>
movl   $0x0,-0x4(%rbp)
jmp    11b2 <sfip_str_to_fam+0xa2>
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     117d <sfip_str_to_fam+0x6d>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     117d <sfip_str_to_fam+0x6d>
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11b2 <sfip_str_to_fam+0xa2>
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     11a6 <sfip_str_to_fam+0x96>
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11b2 <sfip_str_to_fam+0xa2>
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sfip_str_to_fam>:
push   %rbx
test   %rdi,%rdi
je     1147 <sfip_str_to_fam+0x37>
mov    %rdi,%rbx
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     114b <sfip_str_to_fam+0x3b>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     114b <sfip_str_to_fam+0x3b>
mov    0x2e93(%rip),%rax
jmp    116d <sfip_str_to_fam+0x5d>
xor    %eax,%eax
pop    %rbx
ret
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1166 <sfip_str_to_fam+0x56>
mov    0x2e84(%rip),%rax
jmp    116d <sfip_str_to_fam+0x5d>
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@AF_INET6 = global i32 0
@AF_INET = global i32 0
@AF_UNSPEC = global i32 0
define i32 @sfip_str_to_fam(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %19, label %3
3: ; preds = %1
%4 = tail call i8* @strchr(i8* %0, i32 58)
%5 = icmp eq i8* %4, null
br i1 %5, label %12, label %6
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %4, i64 1
%8 = tail call i8* @strchr(i8* %7, i32 58)
%9 = icmp eq i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = load i32, i32* @AF_INET6
br label %19
12: ; preds = %6, %3
%13 = tail call i8* @strchr(i8* %0, i32 46)
%14 = icmp eq i8* %13, null
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = load i32, i32* @AF_INET
br label %19
17: ; preds = %12
%18 = load i32, i32* @AF_UNSPEC
br label %19
19: ; preds = %1, %17, %15, %10
%20 = phi i32 [ %11, %10 ], [ %16, %15 ], [ %18, %17 ], [ 0, %1 ]
ret i32 %20
}