#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 TapByte(int /*<<< orphan*/ *, unsigned char const, unsigned char);
unsigned char TapStream(FILE *fp, const unsigned char *p, unsigned addr,
                        unsigned len, unsigned char chk) {
  while (len--) {
    chk = TapByte(fp, p[addr], chk);
    addr = (addr + 1) & 0xffff;
  }
  return chk;
}


x86 assembly (clang, -O0):
<TapStream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %r8b,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0x0,%eax
je     1170 <TapStream+0x60>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,1),%al
movzbl %al,%esi
movzbl -0x19(%rbp),%edx
call   1030 <TapByte@plt>
mov    %al,-0x19(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
and    $0xffff,%eax
mov    %eax,-0x14(%rbp)
jmp    112c <TapStream+0x1c>
movzbl -0x19(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TapStream>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8d,%eax
test   %ecx,%ecx
je     114d <TapStream+0x3d>
mov    %ecx,%ebx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
nopl   0x0(%rax,%rax,1)
mov    %ebp,%ecx
movzbl (%r14,%rcx,1),%esi
movzbl %al,%edx
mov    %r15,%rdi
call   1030 <TapByte@plt>
add    $0x1,%ebp
movzwl %bp,%ebp
add    $0xffffffff,%ebx
jne    1130 <TapStream+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @TapStream(i32* %0, i8* %1, i32 %2, i32 %3, i8 zeroext %4) {
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
store i32* %0, i32** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8 %4, i8* %10
br label %11
11: ; preds = %15, %5
%12 = load i32, i32* %9
%13 = add i32 %12, -1
store i32 %13, i32* %9
%14 = icmp ne i32 %12, 0
br i1 %14, label %15, label %27
15: ; preds = %11
%16 = load i32*, i32** %6
%17 = load i8*, i8** %7
%18 = load i32, i32* %8
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = load i8, i8* %10
%23 = call zeroext i8 @TapByte(i32* %16, i8 zeroext %21, i8 zeroext %22)
store i8 %23, i8* %10
%24 = load i32, i32* %8
%25 = add i32 %24, 1
%26 = and i32 %25, 65535
store i32 %26, i32* %8
br label %11
27: ; preds = %11
%28 = load i8, i8* %10
ret i8 %28
}

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