#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 */
scalar_t__ testbit(char *, size_t, int);
int where_the_bit_differ(char *str1, size_t l1, char *str2, size_t l2) {
  int p = 0, bitloc;
  while (str1[p] == str2[p])
    p++;
  bitloc = p * 8;
  while (testbit(str1, l1, bitloc) == testbit(str2, l2, bitloc))
    bitloc++;
  return bitloc;
}


x86 assembly (clang, -O0):
<where_the_bit_differ>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
movslq -0x24(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    115d <where_the_bit_differ+0x4d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112f <where_the_bit_differ+0x1f>
mov    -0x24(%rbp),%eax
shl    $0x3,%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1030 <testbit@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1030 <testbit@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
jne    11a8 <where_the_bit_differ+0x98>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1166 <where_the_bit_differ+0x56>
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<where_the_bit_differ>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r13
mov    $0xfffffff7,%ebp
xor    %eax,%eax
xchg   %ax,%ax
movzbl 0x0(%r13,%rax,1),%ecx
lea    0x1(%rax),%rdx
add    $0x8,%ebp
cmp    (%r12,%rax,1),%cl
mov    %rdx,%rax
je     1130 <where_the_bit_differ+0x20>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %r13,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <testbit@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <testbit@plt>
cmp    %rax,%rbx
je     1150 <where_the_bit_differ+0x40>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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