#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*/ UpdateCrc14443(unsigned char, unsigned short *);
void ComputeCrc14443(int CrcType, const unsigned char *Data, int Length,
                     unsigned char *TransmitFirst,
                     unsigned char *TransmitSecond) {
  unsigned char chBlock;
  unsigned short wCrc = CrcType;
  do {
    chBlock = *Data++;
    UpdateCrc14443(chBlock, &wCrc);
  } while (--Length);
  if (CrcType == 0xFFFF)
    wCrc = ~wCrc;
  *TransmitFirst = (unsigned char)(wCrc & 0xFF);
  *TransmitSecond = (unsigned char)((wCrc >> 8) & 0xFF);
  return;
}


x86 assembly (clang, -O0):
<ComputeCrc14443>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x4(%rbp),%eax
mov    %ax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x29(%rbp)
lea    -0x2c(%rbp),%rsi
movzbl -0x29(%rbp),%edi
call   1030 <UpdateCrc14443@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    1131 <ComputeCrc14443+0x21>
cmpl   $0xffff,-0x4(%rbp)
jne    117c <ComputeCrc14443+0x6c>
movzwl -0x2c(%rbp),%eax
xor    $0xffffffff,%eax
mov    %ax,-0x2c(%rbp)
movzwl -0x2c(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
movzwl -0x2c(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ComputeCrc14443>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,0x10(%rsp)
mov    %rcx,%r14
mov    %rsi,%r13
mov    %edi,%r15d
mov    %r15w,0xe(%rsp)
mov    %edx,%ebp
xor    %ebx,%ebx
lea    0xe(%rsp),%r12
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%r13,%rbx,1),%edi
mov    %r12,%rsi
call   1030 <UpdateCrc14443@plt>
add    $0x1,%rbx
cmp    %ebx,%ebp
jne    1140 <ComputeCrc14443+0x30>
xor    %eax,%eax
cmp    $0xffff,%r15d
sete   %al
neg    %eax
xor    0xe(%rsp),%ax
mov    %al,(%r14)
mov    0x10(%rsp),%rcx
mov    %ah,(%rcx)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @ComputeCrc14443(i32 %0, i8* %1, i32 %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8
%12 = alloca i16
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%13 = load i32, i32* %6
%14 = trunc i32 %13 to i16
store i16 %14, i16* %12
br label %15
15: ; preds = %21, %5
%16 = load i8*, i8** %7
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %7
%18 = load i8, i8* %16
store i8 %18, i8* %11
%19 = load i8, i8* %11
%20 = call i32 @UpdateCrc14443(i8 zeroext %19, i16* %12)
br label %21
21: ; preds = %15
%22 = load i32, i32* %8
%23 = add nsw i32 %22, -1
store i32 %23, i32* %8
%24 = icmp ne i32 %23, 0
br i1 %24, label %15, label %25
25: ; preds = %21
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, 65535
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i16, i16* %12
%30 = zext i16 %29 to i32
%31 = xor i32 %30, -1
%32 = trunc i32 %31 to i16
store i16 %32, i16* %12
br label %33
33: ; preds = %28, %25
%34 = load i16, i16* %12
%35 = zext i16 %34 to i32
%36 = and i32 %35, 255
%37 = trunc i32 %36 to i8
%38 = load i8*, i8** %9
store i8 %37, i8* %38
%39 = load i16, i16* %12
%40 = zext i16 %39 to i32
%41 = ashr i32 %40, 8
%42 = and i32 %41, 255
%43 = trunc i32 %42 to i8
%44 = load i8*, i8** %10
store i8 %43, i8* %44
ret void
}

LLVM IR (-O2):
define void @ComputeCrc14443(i32 %0, i8* nocapture %1, i32 %2, i8* nocapture writeonly %3, i8* nocapture writeonly %4) {
%6 = alloca i16
%7 = bitcast i16* %6 to i8*
%8 = trunc i32 %0 to i16
store i16 %8, i16* %6
br label %9
9: ; preds = %9, %5
%10 = phi i32 [ %2, %5 ], [ %15, %9 ]
%11 = phi i8* [ %1, %5 ], [ %12, %9 ]
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = load i8, i8* %11
%14 = call i32 @UpdateCrc14443(i8 zeroext %13, i16* %6)
%15 = add nsw i32 %10, -1
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %9
17: ; preds = %9
%18 = icmp eq i32 %0, 65535
%19 = load i16, i16* %6
%20 = sext i1 %18 to i16
%21 = xor i16 %19, %20
%22 = trunc i16 %21 to i8
store i8 %22, i8* %3
%23 = lshr i16 %21, 8
%24 = trunc i16 %23 to i8
store i8 %24, i8* %4
ret void
}