#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 uint8_t;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ putchar(int);
scalar_t__ read(int /*<<< orphan*/, int *, int);
int softcrc(int /*<<< orphan*/, int *, int);
int main(void) {
  uint8_t byte_array[1024];
  int byte_array_len = 0;
  uint8_t byte;
  while (read(STDIN_FILENO, &byte, 1) > 0) {
    byte_array[byte_array_len] = byte;
    byte_array_len++;
  }
  uint16_t crc = softcrc(0, byte_array, byte_array_len);
  uint8_t hi = crc >> 8;
  uint8_t lo = crc & 0xFF;
  putchar(hi);
  putchar(lo);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1014(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
lea    -0x1018(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jle    1198 <main+0x68>
mov    -0x1018(%rbp),%ecx
movslq -0x1014(%rbp),%rax
mov    %ecx,-0x1010(%rbp,%rax,4)
mov    -0x1014(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1014(%rbp)
jmp    114c <main+0x1c>
lea    -0x1010(%rbp),%rsi
mov    -0x1014(%rbp),%edx
xor    %edi,%edi
call   1040 <softcrc@plt>
mov    %eax,-0x101c(%rbp)
mov    -0x101c(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x1020(%rbp)
mov    -0x101c(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x1024(%rbp)
mov    -0x1020(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x1024(%rbp),%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1010,%rsp
mov    0x2e9d(%rip),%r15
mov    (%r15),%edi
lea    0xc(%rsp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
xor    %ebx,%ebx
test   %rax,%rax
jle    1191 <main+0x61>
lea    0xc(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0xc(%rsp),%eax
mov    %eax,0x10(%rsp,%rbx,4)
add    $0x1,%rbx
mov    (%r15),%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
test   %rax,%rax
jg     1170 <main+0x40>
lea    0x10(%rsp),%rsi
xor    %edi,%edi
mov    %ebx,%edx
call   1040 <softcrc@plt>
movzbl %al,%ebx
mov    %eax,%edi
sar    $0x8,%edi
call   1030 <putchar@plt>
mov    %ebx,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x1010,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %8
8: ; preds = %12, %0
%9 = load i32, i32* @STDIN_FILENO
%10 = call i64 @read(i32 %9, i32* %4, i32 1)
%11 = icmp sgt i64 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %8
%13 = load i32, i32* %4
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [1024 x i32], [1024 x i32]* %2, i64 0, i64 %15
store i32 %13, i32* %16
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %8
19: ; preds = %8
%20 = getelementptr inbounds [1024 x i32], [1024 x i32]* %2, i64 0, i64 0
%21 = load i32, i32* %3
%22 = call i32 @softcrc(i32 0, i32* %20, i32 %21)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = ashr i32 %23, 8
store i32 %24, i32* %6
%25 = load i32, i32* %5
%26 = and i32 %25, 255
store i32 %26, i32* %7
%27 = load i32, i32* %6
%28 = call i32 @putchar(i32 %27)
%29 = load i32, i32* %7
%30 = call i32 @putchar(i32 %29)
ret i32 0
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
define i32 @main() {
%1 = alloca [1024 x i32]
%2 = alloca i32
%3 = bitcast [1024 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = load i32, i32* @STDIN_FILENO
%6 = call i64 @read(i32 %5, i32* %2, i32 1)
%7 = icmp sgt i64 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %0, %8
%9 = phi i64 [ %12, %8 ], [ 0, %0 ]
%10 = load i32, i32* %2
%11 = getelementptr inbounds [1024 x i32], [1024 x i32]* %1, i64 0, i64 %9
store i32 %10, i32* %11
%12 = add nuw i64 %9, 1
%13 = load i32, i32* @STDIN_FILENO
%14 = call i64 @read(i32 %13, i32* %2, i32 1)
%15 = icmp sgt i64 %14, 0
br i1 %15, label %8, label %16
16: ; preds = %8
%17 = trunc i64 %12 to i32
br label %18
18: ; preds = %16, %0
%19 = phi i32 [ 0, %0 ], [ %17, %16 ]
%20 = getelementptr inbounds [1024 x i32], [1024 x i32]* %1, i64 0, i64 0
%21 = call i32 @softcrc(i32 0, i32* %20, i32 %19)
%22 = ashr i32 %21, 8
%23 = and i32 %21, 255
%24 = call i32 @putchar(i32 %22)
%25 = call i32 @putchar(i32 %23)
ret i32 0
}