#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
unsigned char fgetc(int /*<<< orphan*/ *);
bool block_correct(FILE *fp, unsigned char *expected_block, int num_bytes) {
  int i;
  unsigned char checksum = 0;
  int lo_byte = fgetc(fp);
  int hi_byte = fgetc(fp);
  if (num_bytes != (lo_byte + (hi_byte << 8)) - 1)
    return false;
  for (i = 0; i < num_bytes; i++) {
    if (fgetc(fp) != expected_block[i]) {
      return false;
    }
    checksum ^= expected_block[i];
  }
  if (fgetc(fp) != checksum)
    return false;
  return true;
}


x86 assembly (clang, -O0):
<block_correct>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movb   $0x0,-0x21(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
movzbl %al,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x28(%rbp),%ecx
mov    -0x2c(%rbp),%edx
shl    $0x8,%edx
add    %edx,%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     116a <block_correct+0x5a>
movl   $0x0,-0x4(%rbp)
jmp    11f7 <block_correct+0xe7>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11cc <block_correct+0xbc>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
movzbl %al,%eax
mov    -0x18(%rbp),%rcx
movslq -0x20(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     11a9 <block_correct+0x99>
movl   $0x0,-0x4(%rbp)
jmp    11f7 <block_correct+0xe7>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%ecx
movzbl -0x21(%rbp),%eax
xor    %ecx,%eax
mov    %al,-0x21(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1171 <block_correct+0x61>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
movzbl %al,%eax
movzbl -0x21(%rbp),%ecx
cmp    %ecx,%eax
je     11f0 <block_correct+0xe0>
movl   $0x0,-0x4(%rbp)
jmp    11f7 <block_correct+0xe7>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<block_correct>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r12
call   1030 <fgetc@plt>
movzbl %al,%ebx
mov    %r12,%rdi
call   1030 <fgetc@plt>
movzbl %al,%eax
shl    $0x8,%eax
add    %ebx,%eax
add    $0xffffffff,%eax
xor    %r15d,%r15d
cmp    %ebp,%eax
jne    1194 <block_correct+0x84>
test   %ebp,%ebp
jle    117e <block_correct+0x6e>
mov    %ebp,%r13d
xor    %r15d,%r15d
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
call   1030 <fgetc@plt>
cmp    (%r14,%rbx,1),%al
jne    1194 <block_correct+0x84>
movzbl %al,%eax
xor    %eax,%ebp
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1160 <block_correct+0x50>
jmp    1180 <block_correct+0x70>
xor    %ebp,%ebp
mov    %r12,%rdi
call   1030 <fgetc@plt>
movzbl %al,%eax
xor    %r15d,%r15d
cmp    %eax,%ebp
sete   %r15b
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @block_correct(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8 0, i8* %9
%12 = load i32*, i32** %5
%13 = call zeroext i8 @fgetc(i32* %12)
%14 = zext i8 %13 to i32
store i32 %14, i32* %10
%15 = load i32*, i32** %5
%16 = call zeroext i8 @fgetc(i32* %15)
%17 = zext i8 %16 to i32
store i32 %17, i32* %11
%18 = load i32, i32* %7
%19 = load i32, i32* %10
%20 = load i32, i32* %11
%21 = shl i32 %20, 8
%22 = add nsw i32 %19, %21
%23 = sub nsw i32 %22, 1
%24 = icmp ne i32 %18, %23
br i1 %24, label %25, label %26
25: ; preds = %3
store i32 0, i32* %4
br label %66
26: ; preds = %3
store i32 0, i32* %8
br label %27
27: ; preds = %54, %26
%28 = load i32, i32* %8
%29 = load i32, i32* %7
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %57
31: ; preds = %27
%32 = load i32*, i32** %5
%33 = call zeroext i8 @fgetc(i32* %32)
%34 = zext i8 %33 to i32
%35 = load i8*, i8** %6
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = icmp ne i32 %34, %40
br i1 %41, label %42, label %43
42: ; preds = %31
store i32 0, i32* %4
br label %66
43: ; preds = %31
%44 = load i8*, i8** %6
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = load i8, i8* %9
%51 = zext i8 %50 to i32
%52 = xor i32 %51, %49
%53 = trunc i32 %52 to i8
store i8 %53, i8* %9
br label %54
54: ; preds = %43
%55 = load i32, i32* %8
%56 = add nsw i32 %55, 1
store i32 %56, i32* %8
br label %27
57: ; preds = %27
%58 = load i32*, i32** %5
%59 = call zeroext i8 @fgetc(i32* %58)
%60 = zext i8 %59 to i32
%61 = load i8, i8* %9
%62 = zext i8 %61 to i32
%63 = icmp ne i32 %60, %62
br i1 %63, label %64, label %65
64: ; preds = %57
store i32 0, i32* %4
br label %66
65: ; preds = %57
store i32 1, i32* %4
br label %66
66: ; preds = %65, %64, %42, %25
%67 = load i32, i32* %4
ret i32 %67
}

LLVM IR (-O2):
define i32 @block_correct(i32* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = tail call zeroext i8 @fgetc(i32* %0)
%5 = zext i8 %4 to i32
%6 = tail call zeroext i8 @fgetc(i32* %0)
%7 = zext i8 %6 to i32
%8 = shl nuw nsw i32 %7, 8
%9 = add nsw i32 %5, -1
%10 = add nsw i32 %9, %8
%11 = icmp eq i32 %10, %2
br i1 %11, label %12, label %34
12: ; preds = %3
%13 = icmp sgt i32 %2, 0
br i1 %13, label %14, label %28
14: ; preds = %12
%15 = zext i32 %2 to i64
br label %16
16: ; preds = %14, %23
%17 = phi i64 [ 0, %14 ], [ %26, %23 ]
%18 = phi i32 [ 0, %14 ], [ %25, %23 ]
%19 = tail call zeroext i8 @fgetc(i32* %0)
%20 = getelementptr inbounds i8, i8* %1, i64 %17
%21 = load i8, i8* %20
%22 = icmp eq i8 %19, %21
br i1 %22, label %23, label %34
23: ; preds = %16
%24 = zext i8 %19 to i32
%25 = xor i32 %18, %24
%26 = add nuw nsw i64 %17, 1
%27 = icmp eq i64 %26, %15
br i1 %27, label %28, label %16
28: ; preds = %23, %12
%29 = phi i32 [ 0, %12 ], [ %25, %23 ]
%30 = tail call zeroext i8 @fgetc(i32* %0)
%31 = zext i8 %30 to i32
%32 = icmp eq i32 %29, %31
%33 = zext i1 %32 to i32
br label %34
34: ; preds = %16, %28, %3
%35 = phi i32 [ 0, %3 ], [ %33, %28 ], [ 0, %16 ]
ret i32 %35
}