#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(int);
int overlap(int k1, int k2, int nkmer) {
  assert(k1 >= 0);
  assert(k2 >= 0);
  int kmer_mask = nkmer - 1;
  int overlap = 0;
  do {
    kmer_mask >>= 2;
    k1 &= kmer_mask;
    k2 >>= 2;
    overlap += 1;
  } while (k1 != k2);
  return overlap;
}


x86 assembly (clang, -O0):
<overlap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x0,-0x8(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x2,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
and    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x2,%eax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    1153 <overlap+0x43>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<overlap>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
not    %edi
shr    $0x1f,%edi
call   1030 <assert@plt>
mov    %ebp,%edi
not    %edi
shr    $0x1f,%edi
call   1030 <assert@plt>
add    $0xffffffff,%r14d
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
sar    $0x2,%r14d
and    %r14d,%ebx
sar    $0x2,%ebp
add    $0x1,%eax
cmp    %ebp,%ebx
jne    1140 <overlap+0x30>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @overlap(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %4
%10 = icmp sge i32 %9, 0
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i32, i32* %5
%14 = icmp sge i32 %13, 0
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i32, i32* %6
%18 = sub nsw i32 %17, 1
store i32 %18, i32* %7
store i32 0, i32* %8
br label %19
19: ; preds = %29, %3
%20 = load i32, i32* %7
%21 = ashr i32 %20, 2
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = load i32, i32* %4
%24 = and i32 %23, %22
store i32 %24, i32* %4
%25 = load i32, i32* %5
%26 = ashr i32 %25, 2
store i32 %26, i32* %5
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
store i32 %28, i32* %8
br label %29
29: ; preds = %19
%30 = load i32, i32* %4
%31 = load i32, i32* %5
%32 = icmp ne i32 %30, %31
br i1 %32, label %19, label %33
33: ; preds = %29
%34 = load i32, i32* %8
ret i32 %34
}

LLVM IR (-O2):
define i32 @overlap(i32 %0, i32 %1, i32 %2) {
%4 = xor i32 %0, -1
%5 = lshr i32 %4, 31
%6 = tail call i32 @assert(i32 %5)
%7 = xor i32 %1, -1
%8 = lshr i32 %7, 31
%9 = tail call i32 @assert(i32 %8)
%10 = add nsw i32 %2, -1
br label %11
11: ; preds = %11, %3
%12 = phi i32 [ %1, %3 ], [ %18, %11 ]
%13 = phi i32 [ %0, %3 ], [ %17, %11 ]
%14 = phi i32 [ %10, %3 ], [ %16, %11 ]
%15 = phi i32 [ 0, %3 ], [ %19, %11 ]
%16 = ashr i32 %14, 2
%17 = and i32 %16, %13
%18 = ashr i32 %12, 2
%19 = add nuw nsw i32 %15, 1
%20 = icmp eq i32 %17, %18
br i1 %20, label %21, label %11
21: ; preds = %11
ret i32 %19
}