#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;
int ip_type(const char *ip) {
  int where;
  where = 0;
  while (ip[where] != '\0') {
    if (ip[where] == '.')
      return AF_INET;
    else if (ip[where] == ':')
      return AF_INET6;
    where++;
  }
  return AF_UNSPEC;
}


x86 assembly (clang, -O0):
<ip_type>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1183 <ip_type+0x83>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    114a <ip_type+0x4a>
mov    0x2ea8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    118f <ip_type+0x8f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
jne    1170 <ip_type+0x70>
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    118f <ip_type+0x8f>
jmp    1175 <ip_type+0x75>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    110f <ip_type+0xf>
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip_type>:
movzbl (%rdi),%eax
test   %al,%al
je     1115 <ip_type+0x15>
cmp    $0x2e,%al
je     111f <ip_type+0x1f>
cmp    $0x3a,%al
je     1129 <ip_type+0x29>
add    $0x1,%rdi
jmp    1100 <ip_type>
mov    0x2ec4(%rip),%rax
mov    (%rax),%eax
ret
mov    0x2ec2(%rip),%rax
mov    (%rax),%eax
ret
mov    0x2ea8(%rip),%rax
mov    (%rax),%eax
ret

LLVM IR (-O0):
@AF_INET = global i32 0
@AF_INET6 = global i32 0
@AF_UNSPEC = global i32 0
define i32 @ip_type(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
br label %5
5: ; preds = %34, %1
%6 = load i8*, i8** %3
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %37
13: ; preds = %5
%14 = load i8*, i8** %3
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 46
br i1 %20, label %21, label %23
21: ; preds = %13
%22 = load i32, i32* @AF_INET
store i32 %22, i32* %2
br label %39
23: ; preds = %13
%24 = load i8*, i8** %3
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 58
br i1 %30, label %31, label %33
31: ; preds = %23
%32 = load i32, i32* @AF_INET6
store i32 %32, i32* %2
br label %39
33: ; preds = %23
br label %34
34: ; preds = %33
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %5
37: ; preds = %5
%38 = load i32, i32* @AF_UNSPEC
store i32 %38, i32* %2
br label %39
39: ; preds = %37, %31, %21
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@AF_INET = global i32 0
@AF_INET6 = global i32 0
@AF_UNSPEC = global i32 0
define i32 @ip_type(i8* nocapture %0) {
br label %2
2: ; preds = %6, %1
%3 = phi i64 [ %7, %6 ], [ 0, %1 ]
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = load i8, i8* %4
switch i8 %5, label %6 [
i8 0, label %10
i8 46, label %8
i8 58, label %9
]
6: ; preds = %2
%7 = add nuw i64 %3, 1
br label %2
8: ; preds = %2
br label %10
9: ; preds = %2
br label %10
10: ; preds = %2, %9, %8
%11 = phi i32* [ @AF_INET, %8 ], [ @AF_INET6, %9 ], [ @AF_UNSPEC, %2 ]
%12 = load i32, i32* %11
ret i32 %12
}