#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 strlen(char const *);
char tolower(char const);
int validate_host_name(const char *host) {
  const int length = strlen(host);
  int i = 0;
  if (length > 0xff) {
    return 0;
  }
  for (i = 0; i < length; i++) {
    char c = tolower(host[i]);
    if (c != '.' && c != '-' && (c < 'a' || c > 'z')) {
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<validate_host_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0xff,-0x14(%rbp)
jle    1158 <validate_host_name+0x38>
movl   $0x0,-0x4(%rbp)
jmp    11d9 <validate_host_name+0xb9>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d2 <validate_host_name+0xb2>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x2e,%eax
je     11bf <validate_host_name+0x9f>
movsbl -0x19(%rbp),%eax
cmp    $0x2d,%eax
je     11bf <validate_host_name+0x9f>
movsbl -0x19(%rbp),%eax
cmp    $0x61,%eax
jl     11b3 <validate_host_name+0x93>
movsbl -0x19(%rbp),%eax
cmp    $0x7a,%eax
jle    11bf <validate_host_name+0x9f>
movl   $0x0,-0x4(%rbp)
jmp    11d9 <validate_host_name+0xb9>
jmp    11c4 <validate_host_name+0xa4>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115f <validate_host_name+0x3f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_host_name>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
xor    %r14d,%r14d
cmp    $0xff,%eax
jg     1173 <validate_host_name+0x53>
mov    $0x1,%r14d
test   %eax,%eax
jle    1173 <validate_host_name+0x53>
mov    %eax,%r15d
xor    %ebp,%ebp
jmp    1159 <validate_host_name+0x39>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%r15
je     1173 <validate_host_name+0x53>
movsbl (%rbx,%rbp,1),%edi
call   1040 <tolower@plt>
lea    -0x2f(%rax),%ecx
cmp    $0xfd,%cl
ja     1150 <validate_host_name+0x30>
add    $0x85,%al
cmp    $0xe5,%al
ja     1150 <validate_host_name+0x30>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @validate_host_name(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %4
store i32 0, i32* %5
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 255
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 0, i32* %2
br label %45
12: ; preds = %1
store i32 0, i32* %5
br label %13
13: ; preds = %41, %12
%14 = load i32, i32* %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %44
17: ; preds = %13
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = call signext i8 @tolower(i8 signext %22)
store i8 %23, i8* %6
%24 = load i8, i8* %6
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 46
br i1 %26, label %27, label %40
27: ; preds = %17
%28 = load i8, i8* %6
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 45
br i1 %30, label %31, label %40
31: ; preds = %27
%32 = load i8, i8* %6
%33 = sext i8 %32 to i32
%34 = icmp slt i32 %33, 97
br i1 %34, label %39, label %35
35: ; preds = %31
%36 = load i8, i8* %6
%37 = sext i8 %36 to i32
%38 = icmp sgt i32 %37, 122
br i1 %38, label %39, label %40
39: ; preds = %35, %31
store i32 0, i32* %2
br label %45
40: ; preds = %35, %27, %17
br label %41
41: ; preds = %40
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %13
44: ; preds = %13
store i32 1, i32* %2
br label %45
45: ; preds = %44, %39, %11
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
define i32 @validate_host_name(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 255
br i1 %3, label %21, label %4
4: ; preds = %1
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %21
6: ; preds = %4
%7 = zext i32 %2 to i64
br label %10
8: ; preds = %10
%9 = icmp eq i64 %20, %7
br i1 %9, label %21, label %10
10: ; preds = %6, %8
%11 = phi i64 [ 0, %6 ], [ %20, %8 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = tail call signext i8 @tolower(i8 signext %13)
%15 = add i8 %14, -47
%16 = icmp ult i8 %15, -2
%17 = add i8 %14, -123
%18 = icmp ult i8 %17, -26
%19 = and i1 %16, %18
%20 = add nuw nsw i64 %11, 1
br i1 %19, label %21, label %8
21: ; preds = %10, %8, %4, %1
%22 = phi i32 [ 0, %1 ], [ 1, %4 ], [ 0, %10 ], [ 1, %8 ]
ret i32 %22
}