#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 */
typedef int uint8_t;

/* Variables and functions */
int strlen(char *);
uint8_t _dns_cname_length(char *s) {
  uint8_t l;
  if (s == NULL)
    return 1;
  l = strlen(s);
  while ((s[l - 1] == '.') && (l > 1))
    l--;
  return l;
}


x86 assembly (clang, -O0):
<_dns_cname_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1133 <_dns_cname_length+0x23>
movl   $0x1,-0x4(%rbp)
jmp    118c <_dns_cname_length+0x7c>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x2e,%ecx
mov    %al,-0x15(%rbp)
jne    1168 <_dns_cname_length+0x58>
cmpl   $0x1,-0x14(%rbp)
setg   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1178 <_dns_cname_length+0x68>
jmp    1186 <_dns_cname_length+0x76>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    113f <_dns_cname_length+0x2f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_dns_cname_length>:
push   %rbx
test   %rdi,%rdi
je     1149 <_dns_cname_length+0x39>
mov    %rdi,%rbx
call   1030 <strlen@plt>
movslq %eax,%rcx
lea    0x1(%rcx),%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xffffffff,%eax
cmpb   $0x2e,-0x1(%rbx,%rcx,1)
jne    1147 <_dns_cname_length+0x37>
lea    -0x1(%rcx),%rdx
cmp    $0x1,%rcx
mov    %rdx,%rcx
jg     1130 <_dns_cname_length+0x20>
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @_dns_cname_length(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 1, i32* %2
br label %30
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %4
br label %11
11: ; preds = %25, %8
%12 = load i8*, i8** %3
%13 = load i32, i32* %4
%14 = sub nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %12, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 46
br i1 %19, label %20, label %23
20: ; preds = %11
%21 = load i32, i32* %4
%22 = icmp sgt i32 %21, 1
br label %23
23: ; preds = %20, %11
%24 = phi i1 [ false, %11 ], [ %22, %20 ]
br i1 %24, label %25, label %28
25: ; preds = %23
%26 = load i32, i32* %4
%27 = add nsw i32 %26, -1
store i32 %27, i32* %4
br label %11
28: ; preds = %23
%29 = load i32, i32* %4
store i32 %29, i32* %2
br label %30
30: ; preds = %28, %7
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
define i32 @_dns_cname_length(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %16, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = sext i32 %4 to i64
br label %6
6: ; preds = %6, %3
%7 = phi i64 [ %8, %6 ], [ %5, %3 ]
%8 = add nsw i64 %7, -1
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 46
%12 = icmp sgt i64 %7, 1
%13 = select i1 %11, i1 %12, i1 false
br i1 %13, label %6, label %14
14: ; preds = %6
%15 = trunc i64 %7 to i32
br label %16
16: ; preds = %14, %1
%17 = phi i32 [ 1, %1 ], [ %15, %14 ]
ret i32 %17
}