#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 *);
scalar_t__ strncmp(char *, char *, int);
int garland(char *word) {
  int i;
  for (i = strlen(word) - 1; i >= 0; i--) {
    if (0 == strncmp(word, word + (strlen(word) - i), i))
      return i;
  }
}


x86 assembly (clang, -O0):
<garland>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11a2 <garland+0x82>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdi
sub    -0x14(%rbp),%eax
cltq
add    %rax,%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    118f <garland+0x6f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a2 <garland+0x82>
jmp    1194 <garland+0x74>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    113b <garland+0x1b>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<garland>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%ebp
add    $0xffffffff,%eax
cltq
mov    %r14,%rbx
sub    %rax,%rbx
nopl   0x0(%rax)
mov    %ebp,%eax
lea    -0x1(%rax),%ebp
test   %eax,%eax
jle    116a <garland+0x4a>
mov    %r14,%rdi
call   1040 <strlen@plt>
movslq %eax,%rsi
add    %rbx,%rsi
mov    %r14,%rdi
mov    %ebp,%edx
call   1030 <strncmp@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1140 <garland+0x20>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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