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

/* Variables and functions */
int /*<<< orphan*/ crc16ccitt_xmodem(char *, int);
uint16_t crc16_one_datline(char *buf, int line) {
  char datbuf[512 / 4] = {0};
  int i;
  for (i = 0; i < 512; i++) {
    datbuf[i / 4] <<= 2;
    datbuf[i / 4] |= (((buf[i] >> line) & 0x10)) ? 0x2 : 0x0;
    datbuf[i / 4] |= ((buf[i] >> line) & 0x1);
  }
  return crc16ccitt_xmodem(datbuf, sizeof(datbuf));
}


x86 assembly (clang, -O0):
<crc16_one_datline>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1030 <memset@plt>
movl   $0x0,-0x94(%rbp)
cmpl   $0x200,-0x94(%rbp)
jge    122a <crc16_one_datline+0x10a>
mov    -0x94(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cltq
movsbl -0x90(%rbp,%rax,1),%ecx
ff
shl    $0x2,%ecx
mov    %cl,-0x90(%rbp,%rax,1)
mov    -0x8(%rbp),%rax
movslq -0x94(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
mov    -0xc(%rbp),%ecx
sar    %cl,%edx
and    $0x10,%edx
xor    %eax,%eax
mov    $0x2,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x9c(%rbp)
mov    -0x94(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    -0x9c(%rbp),%edx
cltq
movsbl -0x90(%rbp,%rax,1),%ecx
ff
or     %edx,%ecx
mov    %cl,-0x90(%rbp,%rax,1)
mov    -0x8(%rbp),%rax
movslq -0x94(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0xc(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
mov    %eax,-0x98(%rbp)
mov    -0x94(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    -0x98(%rbp),%edx
cltq
movsbl -0x90(%rbp,%rax,1),%ecx
ff
or     %edx,%ecx
mov    %cl,-0x90(%rbp,%rax,1)
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    114f <crc16_one_datline+0x2f>
lea    -0x90(%rbp),%rdi
mov    $0x80,%esi
call   1040 <crc16ccitt_xmodem@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crc16_one_datline>:
sub    $0x88,%rsp
mov    %esi,%ecx
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,%r9d
shr    $0x2,%r9d
movzbl (%rsp,%r9,1),%r8d
movsbl (%rdi,%rax,1),%esi
mov    %esi,%edx
sar    %cl,%edx
shl    $0x2,%r8b
shr    %cl,%esi
shr    $0x3,%dl
and    $0x2,%dl
and    $0x1,%sil
or     %r8b,%sil
or     %dl,%sil
mov    %sil,(%rsp,%r9,1)
add    $0x1,%rax
cmp    $0x200,%rax
jne    1150 <crc16_one_datline+0x40>
mov    %rsp,%rdi
mov    $0x80,%esi
call   1030 <crc16ccitt_xmodem@plt>
add    $0x88,%rsp
ret

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

LLVM IR (-O2):
define i32 @crc16_one_datline(i8* nocapture %0, i32 %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %2, %5
%6 = phi i64 [ 0, %2 ], [ %24, %5 ]
%7 = lshr i64 %6, 2
%8 = and i64 %7, 1073741823
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %8
%10 = load i8, i8* %9
%11 = shl i8 %10, 2
%12 = getelementptr inbounds i8, i8* %0, i64 %6
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = ashr i32 %14, %1
%16 = trunc i32 %15 to i8
%17 = lshr i8 %16, 3
%18 = and i8 %17, 2
%19 = lshr i32 %14, %1
%20 = trunc i32 %19 to i8
%21 = and i8 %20, 1
%22 = or i8 %21, %11
%23 = or i8 %22, %18
store i8 %23, i8* %9
%24 = add nuw nsw i64 %6, 1
%25 = icmp eq i64 %24, 512
br i1 %25, label %26, label %5
26: ; preds = %5
%27 = call i32 @crc16ccitt_xmodem(i8* %4, i32 128)
ret i32 %27
}