#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 off_t;

/* Variables and functions */
int strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
off_t s_string_r(char *input, char *m) {
  off_t i, m_l = strlen(m), i_l = strlen(input);
  for (i = i_l - 1 - m_l; i >= 0; i--) {
    if (!strncmp(&input[i], m, m_l)) {
      return i;
    }
  }
  return (off_t)-1;
}


x86 assembly (clang, -O0):
<s_string_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     119c <s_string_r+0x7c>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1189 <s_string_r+0x69>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a3 <s_string_r+0x83>
jmp    118e <s_string_r+0x6e>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1154 <s_string_r+0x34>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<s_string_r>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r12d,%eax
not    %eax
add    %ebp,%eax
mov    $0xffffffff,%r15d
js     1182 <s_string_r+0x62>
mov    %eax,%eax
sub    %r12d,%ebp
add    %rax,%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1030 <strncmp@plt>
add    $0xffffffff,%ebp
test   %eax,%eax
je     117f <s_string_r+0x5f>
add    $0xffffffffffffffff,%rbx
test   %ebp,%ebp
jg     1160 <s_string_r+0x40>
jmp    1182 <s_string_r+0x62>
mov    %ebp,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @s_string_r(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %7
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = sub nsw i32 %13, 1
%15 = load i32, i32* %7
%16 = sub nsw i32 %14, %15
store i32 %16, i32* %6
br label %17
17: ; preds = %32, %2
%18 = load i32, i32* %6
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %35
20: ; preds = %17
%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** %5
%26 = load i32, i32* %7
%27 = call i32 @strncmp(i8* %24, i8* %25, i32 %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %20
%30 = load i32, i32* %6
store i32 %30, i32* %3
br label %36
31: ; preds = %20
br label %32
32: ; preds = %31
%33 = load i32, i32* %6
%34 = add nsw i32 %33, -1
store i32 %34, i32* %6
br label %17
35: ; preds = %17
store i32 -1, i32* %3
br label %36
36: ; preds = %35, %29
%37 = load i32, i32* %3
ret i32 %37
}

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