#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*/ printf(char *, int, unsigned char, unsigned char);
void check_pattern(unsigned char *buf, unsigned char pattern, int len) {
  int i;
  for (i = 0; i < len; i++) {
    if (buf[i] != pattern) {
      printf("(%d)RX = %x Pattern = %x\n", i, buf[i], pattern);
    }
  }
}


x86 assembly (clang, -O0):
<check_pattern>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1184 <check_pattern+0x74>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
movzbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
je     1171 <check_pattern+0x61>
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
lea    0xe9b(%rip),%rdi
movzbl %al,%edx
movzbl -0x9(%rbp),%ecx
call   1030 <printf@plt>
jmp    1176 <check_pattern+0x66>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112c <check_pattern+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_pattern>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    1165 <check_pattern+0x55>
mov    %esi,%r13d
mov    %rdi,%r14
mov    %edx,%ebp
xor    %ebx,%ebx
movzbl %r13b,%r15d
lea    0xecc(%rip),%r12
jmp    1149 <check_pattern+0x39>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     1165 <check_pattern+0x55>
movzbl (%r14,%rbx,1),%eax
cmp    %r13b,%al
je     1140 <check_pattern+0x30>
movzbl %al,%edx
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r15d,%ecx
call   1030 <printf@plt>
jmp    1140 <check_pattern+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"(%d)RX = %x Pattern = %x\0A\00"
define void @check_pattern(i8* %0, i8 zeroext %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8 %1, i8* %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %32, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %6
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %35
12: ; preds = %8
%13 = load i8*, i8** %4
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = load i8, i8* %5
%20 = zext i8 %19 to i32
%21 = icmp ne i32 %18, %20
br i1 %21, label %22, label %31
22: ; preds = %12
%23 = load i32, i32* %7
%24 = load i8*, i8** %4
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = load i8, i8* %5
%30 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %23, i8 zeroext %28, i8 zeroext %29)
br label %31
31: ; preds = %22, %12
br label %32
32: ; preds = %31
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %8
35: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"(%d)RX = %x Pattern = %x\0A\00"
define void @check_pattern(i8* nocapture %0, i8 zeroext %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %18
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %15
%8 = phi i64 [ 0, %5 ], [ %16, %15 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, %1
br i1 %11, label %15, label %12
12: ; preds = %7
%13 = trunc i64 %8 to i32
%14 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %13, i8 zeroext %10, i8 zeroext %1)
br label %15
15: ; preds = %7, %12
%16 = add nuw nsw i64 %8, 1
%17 = icmp eq i64 %16, %6
br i1 %17, label %18, label %7
18: ; preds = %15, %3
ret void
}