#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 /*<<< orphan*/ assert(char const *);
int overlap_len(const char *former, const char *latter, size_t former_len,
                size_t latter_len) {
  int candidate = (((former_len) < (latter_len)) ? (former_len) : (latter_len));
  int pos = 0;
  assert(former);
  assert(latter);
  for (; candidate > 0; candidate--) {
    for (; pos < candidate; pos++) {
      if (former[former_len - candidate + pos] != latter[pos]) {
        break;
      }
    }
    if (pos == candidate) {
      return candidate;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<overlap_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1143 <overlap_len+0x33>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    114b <overlap_len+0x3b>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1030 <assert@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    11f6 <overlap_len+0xe6>
jmp    117a <overlap_len+0x6a>
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    11cc <overlap_len+0xbc>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
sub    %rdx,%rcx
movslq -0x30(%rbp),%rdx
add    %rdx,%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
movslq -0x30(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     11b9 <overlap_len+0xa9>
jmp    11cc <overlap_len+0xbc>
jmp    11be <overlap_len+0xae>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    117a <overlap_len+0x6a>
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jne    11e3 <overlap_len+0xd3>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11fd <overlap_len+0xed>
jmp    11e8 <overlap_len+0xd8>
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    116b <overlap_len+0x5b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<overlap_len>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
cmp    %rcx,%rdx
cmovb  %rdx,%r12
call   1030 <assert@plt>
mov    %r14,%rdi
call   1030 <assert@plt>
test   %r12d,%r12d
jle    119a <overlap_len+0x8a>
movslq %r12d,%rax
sub    %rax,%r15
add    %r15,%rbx
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
movslq %ecx,%rdx
cmp    %rdx,%rax
jle    1182 <overlap_len+0x72>
nopl   0x0(%rax,%rax,1)
movzbl (%rbx,%rdx,1),%ecx
cmp    (%r14,%rdx,1),%cl
jne    1180 <overlap_len+0x70>
add    $0x1,%rdx
cmp    %rax,%rdx
jl     1160 <overlap_len+0x50>
mov    %eax,%ecx
jmp    1182 <overlap_len+0x72>
nopw   0x0(%rax,%rax,1)
mov    %edx,%ecx
mov    %ecx,%edx
cmp    %rdx,%rax
je     119c <overlap_len+0x8c>
lea    -0x1(%rax),%rdx
add    $0x1,%rbx
cmp    $0x1,%rax
mov    %rdx,%rax
jg     1150 <overlap_len+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @overlap_len(i8* %0, i8* %1, i64 %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i64 %3, i64* %9
%12 = load i64, i64* %8
%13 = load i64, i64* %9
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = load i64, i64* %8
br label %19
17: ; preds = %4
%18 = load i64, i64* %9
br label %19
19: ; preds = %17, %15
%20 = phi i64 [ %16, %15 ], [ %18, %17 ]
%21 = trunc i64 %20 to i32
store i32 %21, i32* %10
store i32 0, i32* %11
%22 = load i8*, i8** %6
%23 = call i32 @assert(i8* %22)
%24 = load i8*, i8** %7
%25 = call i32 @assert(i8* %24)
br label %26
26: ; preds = %65, %19
%27 = load i32, i32* %10
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %68
29: ; preds = %26
br label %30
30: ; preds = %55, %29
%31 = load i32, i32* %11
%32 = load i32, i32* %10
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %58
34: ; preds = %30
%35 = load i8*, i8** %6
%36 = load i64, i64* %8
%37 = load i32, i32* %10
%38 = sext i32 %37 to i64
%39 = sub i64 %36, %38
%40 = load i32, i32* %11
%41 = sext i32 %40 to i64
%42 = add i64 %39, %41
%43 = getelementptr inbounds i8, i8* %35, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = load i8*, i8** %7
%47 = load i32, i32* %11
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp ne i32 %45, %51
br i1 %52, label %53, label %54
53: ; preds = %34
br label %58
54: ; preds = %34
br label %55
55: ; preds = %54
%56 = load i32, i32* %11
%57 = add nsw i32 %56, 1
store i32 %57, i32* %11
br label %30
58: ; preds = %53, %30
%59 = load i32, i32* %11
%60 = load i32, i32* %10
%61 = icmp eq i32 %59, %60
br i1 %61, label %62, label %64
62: ; preds = %58
%63 = load i32, i32* %10
store i32 %63, i32* %5
br label %69
64: ; preds = %58
br label %65
65: ; preds = %64
%66 = load i32, i32* %10
%67 = add nsw i32 %66, -1
store i32 %67, i32* %10
br label %26
68: ; preds = %26
store i32 0, i32* %5
br label %69
69: ; preds = %68, %62
%70 = load i32, i32* %5
ret i32 %70
}

LLVM IR (-O2):
define i32 @overlap_len(i8* %0, i8* %1, i64 %2, i64 %3) {
%5 = icmp ult i64 %2, %3
%6 = select i1 %5, i64 %2, i64 %3
%7 = trunc i64 %6 to i32
%8 = tail call i32 @assert(i8* %0)
%9 = tail call i32 @assert(i8* %1)
%10 = icmp sgt i32 %7, 0
br i1 %10, label %11, label %43
11: ; preds = %4
%12 = shl i64 %6, 32
%13 = ashr exact i64 %12, 32
br label %14
14: ; preds = %11, %38
%15 = phi i64 [ %13, %11 ], [ %39, %38 ]
%16 = phi i32 [ 0, %11 ], [ %35, %38 ]
%17 = sub i64 %2, %15
%18 = sext i32 %16 to i64
%19 = icmp sgt i64 %15, %18
%20 = trunc i64 %15 to i32
br i1 %19, label %21, label %34
21: ; preds = %14, %29
%22 = phi i64 [ %30, %29 ], [ %18, %14 ]
%23 = add i64 %17, %22
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = load i8, i8* %24
%26 = getelementptr inbounds i8, i8* %1, i64 %22
%27 = load i8, i8* %26
%28 = icmp eq i8 %25, %27
br i1 %28, label %29, label %32
29: ; preds = %21
%30 = add nsw i64 %22, 1
%31 = icmp slt i64 %30, %15
br i1 %31, label %21, label %34
32: ; preds = %21
%33 = trunc i64 %22 to i32
br label %34
34: ; preds = %29, %32, %14
%35 = phi i32 [ %16, %14 ], [ %33, %32 ], [ %20, %29 ]
%36 = zext i32 %35 to i64
%37 = icmp eq i64 %15, %36
br i1 %37, label %41, label %38
38: ; preds = %34
%39 = add nsw i64 %15, -1
%40 = icmp sgt i64 %15, 1
br i1 %40, label %14, label %43
41: ; preds = %34
%42 = trunc i64 %15 to i32
br label %43
43: ; preds = %41, %38, %4
%44 = phi i32 [ 0, %4 ], [ %42, %41 ], [ 0, %38 ]
ret i32 %44
}