#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 *);
int match_backwards(const char *string, const char *pattern) {
  int i, j;
  for (i = strlen(string), j = strlen(pattern); i >= 0 && j >= 0; i--, j--)
    if (string[i] != pattern[j])
      break;
  if (j == -1)
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<match_backwards>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x21(%rbp)
jl     1151 <match_backwards+0x41>
cmpl   $0x0,-0x20(%rbp)
setge  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1161 <match_backwards+0x51>
jmp    11a2 <match_backwards+0x92>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
movslq -0x20(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     1186 <match_backwards+0x76>
jmp    11a2 <match_backwards+0x92>
jmp    118b <match_backwards+0x7b>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    1138 <match_backwards+0x28>
cmpl   $0xffffffff,-0x20(%rbp)
jne    11b8 <match_backwards+0xa8>
movl   $0x1,-0x4(%rbp)
jmp    11bf <match_backwards+0xaf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match_backwards>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %ebp,%ebp
js     1160 <match_backwards+0x50>
test   %eax,%eax
js     1160 <match_backwards+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%ecx
movzbl (%rbx,%rcx,1),%ecx
mov    %eax,%edx
cmp    (%r14,%rdx,1),%cl
jne    1160 <match_backwards+0x50>
lea    -0x1(%rax),%ecx
test   %ebp,%ebp
jle    1162 <match_backwards+0x52>
add    $0xffffffff,%ebp
test   %eax,%eax
mov    %ecx,%eax
jg     1140 <match_backwards+0x30>
jmp    1162 <match_backwards+0x52>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
sete   %al
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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