#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*/ err_sys(char *);
int /*<<< orphan*/ hamming(char, char *);
int read(int, char *, int);
scalar_t__ write(int, char *, int);
void hamming_stream(int fin, int fdout) {
  char buffin[1024];
  char buffout[2 * 1024];
  int n;
  while ((n = read(fin, buffin, 1024)) > 0) {
    for (int i = 0; i < n; ++i)
      hamming(buffin[i], buffout + 2 * i);
    if (write(fdout, buffout, 2 * n) < 0)
      err_sys("hamming : output failure");
  }
  if (n < 0)
    err_sys("hamming : input failure");
}


x86 assembly (clang, -O0):
<hamming_stream>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,-0xc14(%rbp)
cmp    $0x0,%eax
jle    1203 <hamming_stream+0xc3>
movl   $0x0,-0xc18(%rbp)
mov    -0xc18(%rbp),%eax
cmp    -0xc14(%rbp),%eax
jge    11d0 <hamming_stream+0x90>
movslq -0xc18(%rbp),%rax
mov    -0x410(%rbp,%rax,1),%al
lea    -0xc10(%rbp),%rsi
mov    -0xc18(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rsi
movsbl %al,%edi
call   1060 <hamming@plt>
mov    -0xc18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc18(%rbp)
jmp    117e <hamming_stream+0x3e>
mov    -0x8(%rbp),%edi
lea    -0xc10(%rbp),%rsi
mov    -0xc14(%rbp),%edx
shl    $0x1,%edx
call   1040 <write@plt>
cmp    $0x0,%rax
jge    11fe <hamming_stream+0xbe>
lea    0xe07(%rip),%rdi
call   1030 <err_sys@plt>
jmp    1151 <hamming_stream+0x11>
cmpl   $0x0,-0xc14(%rbp)
jge    121c <hamming_stream+0xdc>
lea    0xe02(%rip),%rdi
call   1030 <err_sys@plt>
add    $0xc20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hamming_stream>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc08,%rsp
mov    %esi,%r14d
mov    %edi,%r13d
mov    %rsp,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11dc <hamming_stream+0x9c>
lea    0x400(%rsp),%r15
jmp    1194 <hamming_stream+0x54>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13d,%edi
mov    %rsp,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11dc <hamming_stream+0x9c>
mov    %eax,%ebp
mov    %r15,%rbx
xor    %r12d,%r12d
nopl   0x0(%rax)
movsbl (%rsp,%r12,1),%edi
mov    %rbx,%rsi
call   1060 <hamming@plt>
add    $0x1,%r12
add    $0x2,%rbx
cmp    %r12,%rbp
jne    11a0 <hamming_stream+0x60>
add    %ebp,%ebp
mov    %r14d,%edi
mov    %r15,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
test   %rax,%rax
jns    1180 <hamming_stream+0x40>
lea    0xe2b(%rip),%rdi
call   1030 <err_sys@plt>
jmp    1180 <hamming_stream+0x40>
test   %eax,%eax
jns    11ec <hamming_stream+0xac>
lea    0xe32(%rip),%rdi
call   1030 <err_sys@plt>
add    $0xc08,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"hamming : output failure\00"
@.str.1 = [24 x i8] c"hamming : input failure\00"
define void @hamming_stream(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca [2048 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
br label %9
9: ; preds = %42, %2
%10 = load i32, i32* %3
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%12 = call i32 @read(i32 %10, i8* %11, i32 1024)
store i32 %12, i32* %7
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %43
14: ; preds = %9
store i32 0, i32* %8
br label %15
15: ; preds = %30, %14
%16 = load i32, i32* %8
%17 = load i32, i32* %7
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %33
19: ; preds = %15
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%25 = load i32, i32* %8
%26 = mul nsw i32 2, %25
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
%29 = call i32 @hamming(i8 signext %23, i8* %28)
br label %30
30: ; preds = %19
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %15
33: ; preds = %15
%34 = load i32, i32* %4
%35 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%36 = load i32, i32* %7
%37 = mul nsw i32 2, %36
%38 = call i64 @write(i32 %34, i8* %35, i32 %37)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %33
%41 = call i32 @err_sys(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %42
42: ; preds = %40, %33
br label %9
43: ; preds = %9
%44 = load i32, i32* %7
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 @err_sys(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %48
48: ; preds = %46, %43
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"hamming : output failure\00"
@.str.1 = [24 x i8] c"hamming : input failure\00"
define void @hamming_stream(i32 %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = alloca [2048 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%7 = call i32 @read(i32 %0, i8* %5, i32 1024)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %30
9: ; preds = %2, %27
%10 = phi i32 [ %28, %27 ], [ %7, %2 ]
%11 = zext i32 %10 to i64
br label %16
12: ; preds = %16
%13 = shl nsw i32 %10, 1
%14 = call i64 @write(i32 %1, i8* %6, i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %25, label %27
16: ; preds = %9, %16
%17 = phi i64 [ 0, %9 ], [ %23, %16 ]
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = shl nuw nsw i64 %17, 1
%21 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %20
%22 = call i32 @hamming(i8 signext %19, i8* %21)
%23 = add nuw nsw i64 %17, 1
%24 = icmp eq i64 %23, %11
br i1 %24, label %12, label %16
25: ; preds = %12
%26 = call i32 @err_sys(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %25, %12
%28 = call i32 @read(i32 %0, i8* %5, i32 1024)
%29 = icmp sgt i32 %28, 0
br i1 %29, label %9, label %30
30: ; preds = %27, %2
%31 = phi i32 [ %7, %2 ], [ %28, %27 ]
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @err_sys(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %33, %30
ret void
}