#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 /*<<< orphan*/ free(char *);
char *mp_strdup(char const *);
size_t strlen(char *);
char *strsep(char **, char *);
size_t strspn(char *, char *);
int is_hostname(const char *address) {
  char *a, *addr, *part;
  a = addr = mp_strdup(address);
  while ((part = strsep(&addr, "."))) {
    size_t len;
    len = strlen(part);
    if (len == 0) {
      free(a);
      return (0);
    }
    if (strspn(part, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                     "abcdefghijklmnopqrstuvwxyz"
                     "0123456789-_") != len) {
      free(a);
      return (0);
    }
  }
  free(a);
  return (1);
}


x86 assembly (clang, -O0):
<is_hostname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <mp_strdup@plt>
mov    %rax,-0x20(%rbp)
mov    %rax,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1070 <strsep@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11ec <is_hostname+0x9c>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11b8 <is_hostname+0x68>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    11fc <is_hostname+0xac>
mov    -0x28(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1060 <strspn@plt>
cmp    -0x30(%rbp),%rax
je     11e7 <is_hostname+0x97>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    11fc <is_hostname+0xac>
jmp    116d <is_hostname+0x1d>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_hostname>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
call   1040 <mp_strdup@plt>
mov    %rax,0x8(%rsp)
mov    %rax,0x10(%rsp)
lea    0xe8c(%rip),%r15
lea    0x10(%rsp),%r13
lea    0xe82(%rip),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r15,%rsi
call   1070 <strsep@plt>
test   %rax,%rax
je     11c5 <is_hostname+0x75>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
je     11ca <is_hostname+0x7a>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <strspn@plt>
cmp    %r14,%rax
je     1190 <is_hostname+0x40>
jmp    11ca <is_hostname+0x7a>
mov    $0x1,%ebp
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [65 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_\00"
define i32 @is_hostname(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i8* @mp_strdup(i8* %8)
store i8* %9, i8** %5
store i8* %9, i8** %4
br label %10
10: ; preds = %29, %1
%11 = call i8* @strsep(i8** %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %30
13: ; preds = %10
%14 = load i8*, i8** %6
%15 = call i64 @strlen(i8* %14)
store i64 %15, i64* %7
%16 = load i64, i64* %7
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i8*, i8** %4
%20 = call i32 @free(i8* %19)
store i32 0, i32* %2
br label %33
21: ; preds = %13
%22 = load i8*, i8** %6
%23 = call i64 @strspn(i8* %22, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0))
%24 = load i64, i64* %7
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i8*, i8** %4
%28 = call i32 @free(i8* %27)
store i32 0, i32* %2
br label %33
29: ; preds = %21
br label %10
30: ; preds = %10
%31 = load i8*, i8** %4
%32 = call i32 @free(i8* %31)
store i32 1, i32* %2
br label %33
33: ; preds = %30, %26, %18
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [65 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_\00"
define i32 @is_hostname(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call i8* @mp_strdup(i8* %0)
store i8* %4, i8** %2
br label %5
5: ; preds = %11, %1
%6 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %14, label %8
8: ; preds = %5
%9 = call i64 @strlen(i8* %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = call i64 @strspn(i8* %6, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, %9
br i1 %13, label %5, label %14
14: ; preds = %5, %11, %8
%15 = phi i32 [ 0, %8 ], [ 0, %11 ], [ 1, %5 ]
%16 = call i32 @free(i8* %4)
ret i32 %15
}