#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 */
unsigned char const readb(void volatile *);
int check_signature(volatile void *io_addr, const unsigned char *signature,
                    int length) {
  int retval = 0;
  do {
    if (readb(io_addr) != *signature)
      goto out;
    io_addr++;
    signature++;
    length--;
  } while (length);
  retval = 1;
out:
  return retval;
}


x86 assembly (clang, -O0):
<check_signature>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <readb@plt>
movzbl %al,%eax
mov    -0x10(%rbp),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
je     114a <check_signature+0x3a>
jmp    117c <check_signature+0x6c>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    112a <check_signature+0x1a>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_signature>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r13
mov    %edx,%r12d
xor    %r14d,%r14d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
lea    (%rbx,%r13,1),%rdi
call   1030 <readb@plt>
cmp    (%r15,%rbx,1),%al
jne    114e <check_signature+0x3e>
add    $0x1,%rbx
cmp    %ebx,%r12d
jne    1130 <check_signature+0x20>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @check_signature(i8* %0, i8* %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 = %24, %3
%9 = load i8*, i8** %4
%10 = call zeroext i8 @readb(i8* %9)
%11 = zext i8 %10 to i32
%12 = load i8*, i8** %5
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = icmp ne i32 %11, %14
br i1 %15, label %16, label %17
16: ; preds = %8
br label %28
17: ; preds = %8
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %4
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %5
%22 = load i32, i32* %6
%23 = add nsw i32 %22, -1
store i32 %23, i32* %6
br label %24
24: ; preds = %17
%25 = load i32, i32* %6
%26 = icmp ne i32 %25, 0
br i1 %26, label %8, label %27
27: ; preds = %24
store i32 1, i32* %7
br label %28
28: ; preds = %27, %16
%29 = load i32, i32* %7
ret i32 %29
}

LLVM IR (-O2):
define i32 @check_signature(i8* %0, i8* nocapture %1, i32 %2) {
br label %4
4: ; preds = %11, %3
%5 = phi i8* [ %0, %3 ], [ %12, %11 ]
%6 = phi i8* [ %1, %3 ], [ %13, %11 ]
%7 = phi i32 [ %2, %3 ], [ %14, %11 ]
%8 = tail call zeroext i8 @readb(i8* %5)
%9 = load i8, i8* %6
%10 = icmp eq i8 %8, %9
br i1 %10, label %11, label %16
11: ; preds = %4
%12 = getelementptr inbounds i8, i8* %5, i64 1
%13 = getelementptr inbounds i8, i8* %6, i64 1
%14 = add nsw i32 %7, -1
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %4
16: ; preds = %11, %4
%17 = phi i32 [ 0, %4 ], [ 1, %11 ]
ret i32 %17
}