#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 */
long updc32(int, long);
int /*<<< orphan*/ xmchout(int);
int /*<<< orphan*/ zsendline(int);
void zsda32(char *buf, int length, int frameend) {
  static long crc;
  crc = 0xFFFFFFFFL;
  for (; --length >= 0; ++buf) {
    crc = updc32((0377 & *buf), crc);
    zsendline(*buf);
  }
  xmchout(030);
  xmchout(frameend);
  crc = updc32(frameend, crc);
  crc = ~crc;
  for (length = 4; --length >= 0;) {
    zsendline((int)crc);
    crc >>= 8;
  }
}


x86 assembly (clang, -O0):
<zsda32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    $0xffffffff,%eax
mov    %rax,0x2ef2(%rip)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jl     119d <zsda32+0x6d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
and    $0xff,%edi
mov    0x2ecc(%rip),%rsi
call   1040 <updc32@plt>
mov    %rax,0x2ec0(%rip)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1050 <zsendline@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    114e <zsda32+0x1e>
mov    $0x18,%edi
call   1030 <xmchout@plt>
mov    -0x10(%rbp),%edi
call   1030 <xmchout@plt>
mov    -0x10(%rbp),%edi
mov    0x2e87(%rip),%rsi
call   1040 <updc32@plt>
mov    %rax,0x2e7b(%rip)
mov    0x2e74(%rip),%rax
xor    $0xffffffffffffffff,%rax
mov    %rax,0x2e69(%rip)
movl   $0x4,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jl     1215 <zsda32+0xe5>
mov    0x2e49(%rip),%rax
mov    %eax,%edi
call   1050 <zsendline@plt>
mov    0x2e3b(%rip),%rax
sar    $0x8,%rax
mov    %rax,0x2e30(%rip)
jmp    11de <zsda32+0xae>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zsda32>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    $0xffffffff,%eax
mov    %rax,0x2efd(%rip)
test   %esi,%esi
jle    11aa <zsda32+0x7a>
mov    %esi,%ebp
mov    %rdi,%rbx
movzbl (%rdi),%edi
mov    $0xffffffff,%esi
call   1040 <updc32@plt>
mov    %rax,0x2ee0(%rip)
movsbl (%rbx),%edi
call   1050 <zsendline@plt>
cmp    $0x1,%ebp
je     11aa <zsda32+0x7a>
add    $0x1,%ebp
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x2eb9(%rip),%rsi
movzbl (%rbx),%edi
call   1040 <updc32@plt>
mov    %rax,0x2eaa(%rip)
movsbl (%rbx),%edi
call   1050 <zsendline@plt>
add    $0xffffffff,%ebp
add    $0x1,%rbx
cmp    $0x2,%ebp
jg     1180 <zsda32+0x50>
mov    $0x18,%edi
call   1030 <xmchout@plt>
mov    %r14d,%edi
call   1030 <xmchout@plt>
mov    0x2e7d(%rip),%rsi
mov    %r14d,%edi
call   1040 <updc32@plt>
not    %rax
mov    %rax,0x2e6b(%rip)
mov    %eax,%edi
call   1050 <zsendline@plt>
mov    0x2e5d(%rip),%rdi
sar    $0x8,%rdi
mov    %rdi,0x2e52(%rip)
call   1050 <zsendline@plt>
mov    0x2e46(%rip),%rdi
sar    $0x8,%rdi
mov    %rdi,0x2e3b(%rip)
call   1050 <zsendline@plt>
mov    0x2e2f(%rip),%rdi
sar    $0x8,%rdi
mov    %rdi,0x2e24(%rip)
call   1050 <zsendline@plt>
sarq   $0x8,0x2e17(%rip)
08
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@zsda32.crc = internal unnamed_addr global i64 0
define void @zsda32(i8* nocapture %0, i32 %1, i32 %2) {
store i64 4294967295, i64* @zsda32.crc
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %26
5: ; preds = %3
%6 = load i8, i8* %0
%7 = zext i8 %6 to i32
%8 = tail call i64 @updc32(i32 %7, i64 4294967295)
store i64 %8, i64* @zsda32.crc
%9 = load i8, i8* %0
%10 = sext i8 %9 to i32
%11 = tail call i32 @zsendline(i32 %10)
%12 = icmp eq i32 %1, 1
br i1 %12, label %26, label %13
13: ; preds = %5, %13
%14 = phi i32 [ %17, %13 ], [ %1, %5 ]
%15 = phi i8* [ %16, %13 ], [ %0, %5 ]
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = add nsw i32 %14, -1
%18 = load i64, i64* @zsda32.crc
%19 = load i8, i8* %16
%20 = zext i8 %19 to i32
%21 = tail call i64 @updc32(i32 %20, i64 %18)
store i64 %21, i64* @zsda32.crc
%22 = load i8, i8* %16
%23 = sext i8 %22 to i32
%24 = tail call i32 @zsendline(i32 %23)
%25 = icmp sgt i32 %14, 2
br i1 %25, label %13, label %26
26: ; preds = %13, %5, %3
%27 = tail call i32 @xmchout(i32 24)
%28 = tail call i32 @xmchout(i32 %2)
%29 = load i64, i64* @zsda32.crc
%30 = tail call i64 @updc32(i32 %2, i64 %29)
%31 = xor i64 %30, -1
store i64 %31, i64* @zsda32.crc
%32 = trunc i64 %31 to i32
%33 = tail call i32 @zsendline(i32 %32)
%34 = load i64, i64* @zsda32.crc
%35 = ashr i64 %34, 8
store i64 %35, i64* @zsda32.crc
%36 = trunc i64 %35 to i32
%37 = tail call i32 @zsendline(i32 %36)
%38 = load i64, i64* @zsda32.crc
%39 = ashr i64 %38, 8
store i64 %39, i64* @zsda32.crc
%40 = trunc i64 %39 to i32
%41 = tail call i32 @zsendline(i32 %40)
%42 = load i64, i64* @zsda32.crc
%43 = ashr i64 %42, 8
store i64 %43, i64* @zsda32.crc
%44 = trunc i64 %43 to i32
%45 = tail call i32 @zsendline(i32 %44)
%46 = load i64, i64* @zsda32.crc
%47 = ashr i64 %46, 8
store i64 %47, i64* @zsda32.crc
ret void
}