#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 */
size_t strlen(char const *);
size_t has_end_anchor(char const *str) {
  size_t i, n;
  n = strlen(str);
  if (str[n - 1] != '$') {
    return 0;
  }
  for (i = 1; i < n; i++) {
    if (str[n - i - 1] != '\\') {
      break;
    }
  }
  return i & 1;
}


x86 assembly (clang, -O0):
<has_end_anchor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x24,%eax
je     114f <has_end_anchor+0x3f>
movq   $0x0,-0x8(%rbp)
jmp    11a9 <has_end_anchor+0x99>
movq   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    119d <has_end_anchor+0x8d>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
je     1187 <has_end_anchor+0x77>
jmp    119d <has_end_anchor+0x8d>
jmp    118c <has_end_anchor+0x7c>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1157 <has_end_anchor+0x47>
mov    -0x18(%rbp),%rax
and    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<has_end_anchor>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmpb   $0x24,-0x1(%rax,%rbx,1)
jne    115b <has_end_anchor+0x4b>
mov    %rax,%rcx
mov    $0x1,%eax
cmp    $0x2,%rcx
jb     1156 <has_end_anchor+0x46>
add    $0xfffffffffffffffe,%rbx
mov    $0x1,%eax
nopw   0x0(%rax,%rax,1)
cmpb   $0x5c,(%rbx,%rcx,1)
jne    1156 <has_end_anchor+0x46>
add    $0x1,%rax
add    $0xffffffffffffffff,%rbx
cmp    %rax,%rcx
jne    1140 <has_end_anchor+0x30>
mov    %rcx,%rax
and    $0x1,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i64 @has_end_anchor(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add i64 %2, -1
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 36
br i1 %6, label %7, label %22
7: ; preds = %1
%8 = icmp ugt i64 %2, 1
br i1 %8, label %9, label %19
9: ; preds = %7, %16
%10 = phi i64 [ %17, %16 ], [ 1, %7 ]
%11 = xor i64 %10, -1
%12 = add i64 %2, %11
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 92
br i1 %15, label %16, label %19
16: ; preds = %9
%17 = add nuw i64 %10, 1
%18 = icmp eq i64 %17, %2
br i1 %18, label %19, label %9
19: ; preds = %16, %9, %7
%20 = phi i64 [ 1, %7 ], [ %10, %9 ], [ %2, %16 ]
%21 = and i64 %20, 1
br label %22
22: ; preds = %1, %19
%23 = phi i64 [ %21, %19 ], [ 0, %1 ]
ret i64 %23
}