#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 */
scalar_t__ isdigit(char const);
scalar_t__ isspace(char const);
size_t strlen(char const *);
size_t cleanse_netbios_name(const char *name) {
  size_t length = strlen(name);
  if (length > 4 && name[length - 1] == '>') {
    if (isdigit(name[length - 2]) && isdigit(name[length - 3]) &&
        name[length - 4] == '<')
      length -= 4;
  }
  while (length && isspace(name[length - 1]))
    length--;
  return length;
}


x86 assembly (clang, -O0):
<cleanse_netbios_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x4,-0x10(%rbp)
jbe    11d5 <cleanse_netbios_name+0xa5>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3e,%eax
jne    11d5 <cleanse_netbios_name+0xa5>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x2,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11d0 <cleanse_netbios_name+0xa0>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x3,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11d0 <cleanse_netbios_name+0xa0>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x4,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3c,%eax
jne    11d0 <cleanse_netbios_name+0xa0>
mov    -0x10(%rbp),%rax
sub    $0x4,%rax
mov    %rax,-0x10(%rbp)
jmp    11d5 <cleanse_netbios_name+0xa5>
jmp    11da <cleanse_netbios_name+0xaa>
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
je     1209 <cleanse_netbios_name+0xd9>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1219 <cleanse_netbios_name+0xe9>
jmp    122a <cleanse_netbios_name+0xfa>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    11da <cleanse_netbios_name+0xaa>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cleanse_netbios_name>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %rax,%r15
cmp    $0x5,%rax
jb     1180 <cleanse_netbios_name+0x50>
cmpb   $0x3e,-0x1(%r15,%r14,1)
jne    1180 <cleanse_netbios_name+0x50>
movsbl -0x2(%r15,%r14,1),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1180 <cleanse_netbios_name+0x50>
movsbl -0x3(%r15,%r14,1),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1180 <cleanse_netbios_name+0x50>
lea    -0x4(%r15),%rax
cmpb   $0x3c,-0x4(%r14,%r15,1)
cmove  %rax,%r15
nopl   0x0(%rax)
mov    %r15,%rbx
sub    $0x1,%r15
jb     1199 <cleanse_netbios_name+0x69>
movsbl -0x1(%r14,%rbx,1),%edi
call   1050 <isspace@plt>
test   %rax,%rax
jne    1180 <cleanse_netbios_name+0x50>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @cleanse_netbios_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i64 @strlen(i8* %4)
store i64 %5, i64* %3
%6 = load i64, i64* %3
%7 = icmp ugt i64 %6, 4
br i1 %7, label %8, label %44
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = load i64, i64* %3
%11 = sub i64 %10, 1
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 62
br i1 %15, label %16, label %44
16: ; preds = %8
%17 = load i8*, i8** %2
%18 = load i64, i64* %3
%19 = sub i64 %18, 2
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = call i64 @isdigit(i8 signext %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %43
24: ; preds = %16
%25 = load i8*, i8** %2
%26 = load i64, i64* %3
%27 = sub i64 %26, 3
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = call i64 @isdigit(i8 signext %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %43
32: ; preds = %24
%33 = load i8*, i8** %2
%34 = load i64, i64* %3
%35 = sub i64 %34, 4
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 60
br i1 %39, label %40, label %43
40: ; preds = %32
%41 = load i64, i64* %3
%42 = sub i64 %41, 4
store i64 %42, i64* %3
br label %43
43: ; preds = %40, %32, %24, %16
br label %44
44: ; preds = %43, %8, %1
br label %45
45: ; preds = %58, %44
%46 = load i64, i64* %3
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %56
48: ; preds = %45
%49 = load i8*, i8** %2
%50 = load i64, i64* %3
%51 = sub i64 %50, 1
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i8, i8* %52
%54 = call i64 @isspace(i8 signext %53)
%55 = icmp ne i64 %54, 0
br label %56
56: ; preds = %48, %45
%57 = phi i1 [ false, %45 ], [ %55, %48 ]
br i1 %57, label %58, label %61
58: ; preds = %56
%59 = load i64, i64* %3
%60 = add i64 %59, -1
store i64 %60, i64* %3
br label %45
61: ; preds = %56
%62 = load i64, i64* %3
ret i64 %62
}

LLVM IR (-O2):
define i64 @cleanse_netbios_name(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = icmp ugt i64 %2, 4
br i1 %3, label %4, label %27
4: ; preds = %1
%5 = add i64 %2, -1
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 62
br i1 %8, label %9, label %27
9: ; preds = %4
%10 = add i64 %2, -2
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = tail call i64 @isdigit(i8 signext %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %27, label %15
15: ; preds = %9
%16 = add i64 %2, -3
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = tail call i64 @isdigit(i8 signext %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %15
%22 = add i64 %2, -4
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 60
%26 = select i1 %25, i64 %22, i64 %2
br label %27
27: ; preds = %21, %9, %15, %4, %1
%28 = phi i64 [ %26, %21 ], [ %2, %1 ], [ %2, %4 ], [ %2, %9 ], [ %2, %15 ]
br label %29
29: ; preds = %27, %32
%30 = phi i64 [ %33, %32 ], [ %28, %27 ]
%31 = icmp eq i64 %30, 0
br i1 %31, label %38, label %32
32: ; preds = %29
%33 = add i64 %30, -1
%34 = getelementptr inbounds i8, i8* %0, i64 %33
%35 = load i8, i8* %34
%36 = tail call i64 @isspace(i8 signext %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %29
38: ; preds = %29, %32
ret i64 %30
}