#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 */
struct device {
  int dummy;
};

/* Variables and functions */
int dev_get_block_size(struct device *);
int similar_blk(struct device *dev, const char *b1, const char *b2,
                int tolerance_byte) {
  const int block_size = dev_get_block_size(dev);
  int i;
  for (i = 0; i < block_size; i++) {
    if (*b1 != *b2) {
      tolerance_byte--;
      if (tolerance_byte <= 0)
        return false;
    }
    b1++;
    b2++;
  }
  return true;
}


x86 assembly (clang, -O0):
<similar_blk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <dev_get_block_size@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11a6 <similar_blk+0x96>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    -0x20(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1180 <similar_blk+0x70>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jg     117b <similar_blk+0x6b>
movl   $0x0,-0x4(%rbp)
jmp    11ad <similar_blk+0x9d>
jmp    1180 <similar_blk+0x70>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    113a <similar_blk+0x2a>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<similar_blk>:
push   %r15
push   %r14
push   %rbx
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %rsi,%r15
call   1030 <dev_get_block_size@plt>
mov    %eax,%ecx
mov    $0x1,%eax
test   %ecx,%ecx
jle    115f <similar_blk+0x4f>
mov    %ecx,%esi
xor    %edx,%edx
jmp    1148 <similar_blk+0x38>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rdx
cmp    %edx,%esi
je     115f <similar_blk+0x4f>
movzbl (%r15,%rdx,1),%ecx
cmp    (%r14,%rdx,1),%cl
je     1140 <similar_blk+0x30>
cmp    $0x2,%ebx
jl     115d <similar_blk+0x4d>
add    $0xffffffff,%ebx
jmp    1140 <similar_blk+0x30>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.device = type { i32 }
define i32 @similar_blk(%struct.device* %0, i8* nocapture %1, i8* nocapture %2, i32 %3) {
%5 = tail call i32 @dev_get_block_size(%struct.device* %0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %24
7: ; preds = %4, %18
%8 = phi i32 [ %22, %18 ], [ 0, %4 ]
%9 = phi i32 [ %19, %18 ], [ %3, %4 ]
%10 = phi i8* [ %21, %18 ], [ %2, %4 ]
%11 = phi i8* [ %20, %18 ], [ %1, %4 ]
%12 = load i8, i8* %11
%13 = load i8, i8* %10
%14 = icmp eq i8 %12, %13
br i1 %14, label %18, label %15
15: ; preds = %7
%16 = add nsw i32 %9, -1
%17 = icmp slt i32 %9, 2
br i1 %17, label %24, label %18
18: ; preds = %15, %7
%19 = phi i32 [ %16, %15 ], [ %9, %7 ]
%20 = getelementptr inbounds i8, i8* %11, i64 1
%21 = getelementptr inbounds i8, i8* %10, i64 1
%22 = add nuw nsw i32 %8, 1
%23 = icmp eq i32 %22, %5
br i1 %23, label %24, label %7
24: ; preds = %15, %18, %4
%25 = phi i32 [ 1, %4 ], [ 1, %18 ], [ 0, %15 ]
ret i32 %25
}