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

/* Variables and functions */
int htons(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int read(int /*<<< orphan*/, unsigned char *, int);
int /*<<< orphan*/ write(int, ...);
void main(int argc, char **argv) {
  unsigned char input[502 * 8 + 1];
  unsigned char output[502];
  uint16_t i = 0;
  uint16_t len = 0;
  uint16_t len_net = 0;
  for (i = 0; i < 502; i++) {
    output[i] = 0;
  }
  len = read(0, input, 502 * 8 + 1);
  if (len < 1) {
    perror("read(): ");
  } else if (len == 502 * 8 + 1) {
    printf("File to big");
  }
  for (i = 0; i < len; i++) {
    if (input[i] == '1')
      output[i / 8] |= 1 << (i % 8);
  }
  len_net = htons(len);
  if (argc == 1)
    write(1, &len_net, sizeof(len_net));
  write(1, output, (len % 8) ? len / 8 + 1 : len / 8);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x11f0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x11d4(%rbp)
movl   $0x0,-0x11d8(%rbp)
movl   $0x0,-0x11dc(%rbp)
movl   $0x0,-0x11d4(%rbp)
cmpl   $0x1f6,-0x11d4(%rbp)
jge    11bd <main+0x6d>
movslq -0x11d4(%rbp),%rax
movb   $0x0,-0x11d0(%rbp,%rax,1)
mov    -0x11d4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x11d4(%rbp)
jmp    118a <main+0x3a>
lea    -0xfd0(%rbp),%rsi
xor    %edi,%edi
mov    $0xfb1,%edx
call   1060 <read@plt>
mov    %eax,-0x11d8(%rbp)
cmpl   $0x1,-0x11d8(%rbp)
jge    11f4 <main+0xa4>
lea    0xe16(%rip),%rdi
call   1070 <perror@plt>
jmp    1215 <main+0xc5>
cmpl   $0xfb1,-0x11d8(%rbp)
jne    1210 <main+0xc0>
lea    0xdfe(%rip),%rdi
call   1050 <printf@plt>
jmp    1215 <main+0xc5>
movl   $0x0,-0x11d4(%rbp)
mov    -0x11d4(%rbp),%eax
cmp    -0x11d8(%rbp),%eax
jge    12a6 <main+0x156>
movslq -0x11d4(%rbp),%rax
movzbl -0xfd0(%rbp,%rax,1),%eax
ff
cmp    $0x31,%eax
jne    128d <main+0x13d>
mov    -0x11d4(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x11e0(%rbp)
mov    -0x11d4(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    -0x11e0(%rbp),%edx
cltq
movzbl -0x11d0(%rbp,%rax,1),%ecx
ff
or     %edx,%ecx
mov    %cl,-0x11d0(%rbp,%rax,1)
jmp    1292 <main+0x142>
mov    -0x11d4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x11d4(%rbp)
jmp    121f <main+0xcf>
mov    -0x11d8(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x11dc(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    12d9 <main+0x189>
mov    $0x1,%edi
lea    -0x11dc(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <write@plt>
lea    -0x11d0(%rbp),%rax
mov    %rax,-0x11e8(%rbp)
mov    -0x11d8(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     131a <main+0x1ca>
mov    -0x11d8(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x11ec(%rbp)
jmp    132e <main+0x1de>
mov    -0x11d8(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x11ec(%rbp)
mov    -0x11e8(%rbp),%rsi
mov    -0x11ec(%rbp),%edx
mov    $0x1,%edi
mov    $0x0,%al
call   1030 <write@plt>
add    $0x11f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x11c8,%rsp
mov    %edi,%ebp
lea    0x10(%rsp),%rdi
mov    $0x1f6,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    0x210(%rsp),%rsi
xor    %edi,%edi
mov    $0xfb1,%edx
call   1070 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1234 <main+0xd4>
cmp    $0xfb1,%ebx
jne    11ae <main+0x4e>
lea    0xe60(%rip),%rdi
call   1050 <printf@plt>
mov    %ebx,%edi
cmp    $0x1,%ebx
jne    11dd <main+0x7d>
xor    %eax,%eax
test   $0x1,%dil
je     1240 <main+0xe0>
cmpb   $0x31,0x210(%rsp,%rax,1)
31
jne    1240 <main+0xe0>
mov    %eax,%ecx
and    $0x7,%cl
mov    $0x1,%dl
shl    %cl,%dl
shr    $0x3,%eax
or     %dl,0x10(%rsp,%rax,1)
jmp    1240 <main+0xe0>
mov    %edi,%esi
and    $0xfffffffe,%esi
xor    %eax,%eax
jmp    11f9 <main+0x99>
cs nopw 0x0(%rax,%rax,1)
add    $0x2,%rax
cmp    %rax,%rsi
je     11b7 <main+0x57>
cmpb   $0x31,0x210(%rsp,%rax,1)
jne    1215 <main+0xb5>
mov    %eax,%ecx
and    $0x6,%cl
mov    $0x1,%dl
shl    %cl,%dl
mov    %eax,%ecx
shr    $0x3,%ecx
or     %dl,0x10(%rsp,%rcx,1)
cmpb   $0x31,0x211(%rsp,%rax,1)
31
jne    11f0 <main+0x90>
lea    0x1(%rax),%ecx
and    $0x7,%cl
mov    $0x1,%dl
shl    %cl,%dl
mov    %eax,%ecx
shr    $0x3,%ecx
or     %dl,0x10(%rsp,%rcx,1)
jmp    11f0 <main+0x90>
lea    0xdc5(%rip),%rdi
call   1080 <perror@plt>
mov    %ebx,%edi
call   1040 <htons@plt>
mov    %eax,0xc(%rsp)
cmp    $0x1,%ebp
jne    1266 <main+0x106>
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
mov    $0x1,%edi
xor    %eax,%eax
call   1030 <write@plt>
mov    %ebx,%eax
and    $0x7,%eax
lea    0x7(%rbx),%edx
test   %ebx,%ebx
cmovns %ebx,%edx
sar    $0x3,%edx
cmp    $0x1,%eax
sbb    $0xffffffff,%edx
lea    0x10(%rsp),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1030 <write@plt>
add    $0x11c8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"read(): \00"
@.str.1 = [12 x i8] c"File to big\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [4017 x i8]
%6 = alloca [502 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %7
br label %10
10: ; preds = %17, %2
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 502
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [502 x i8], [502 x i8]* %6, i64 0, i64 %15
store i8 0, i8* %16
br label %17
17: ; preds = %13
%18 = load i32, i32* %7
%19 = add nsw i32 %18, 1
store i32 %19, i32* %7
br label %10
20: ; preds = %10
%21 = getelementptr inbounds [4017 x i8], [4017 x i8]* %5, i64 0, i64 0
%22 = call i32 @read(i32 0, i8* %21, i32 4017)
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = icmp slt i32 %23, 1
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %33
27: ; preds = %20
%28 = load i32, i32* %8
%29 = icmp eq i32 %28, 4017
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %27
br label %33
33: ; preds = %32, %25
store i32 0, i32* %7
br label %34
34: ; preds = %58, %33
%35 = load i32, i32* %7
%36 = load i32, i32* %8
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %61
38: ; preds = %34
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [4017 x i8], [4017 x i8]* %5, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = icmp eq i32 %43, 49
br i1 %44, label %45, label %57
45: ; preds = %38
%46 = load i32, i32* %7
%47 = srem i32 %46, 8
%48 = shl i32 1, %47
%49 = load i32, i32* %7
%50 = sdiv i32 %49, 8
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [502 x i8], [502 x i8]* %6, i64 0, i64 %51
%53 = load i8, i8* %52
%54 = zext 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 = %45, %38
br label %58
58: ; preds = %57
%59 = load i32, i32* %7
%60 = add nsw i32 %59, 1
store i32 %60, i32* %7
br label %34
61: ; preds = %34
%62 = load i32, i32* %8
%63 = call i32 @htons(i32 %62)
store i32 %63, i32* %9
%64 = load i32, i32* %3
%65 = icmp eq i32 %64, 1
br i1 %65, label %66, label %68
66: ; preds = %61
%67 = call i32 (i32, ...) @write(i32 1, i32* %9, i64 4)
br label %68
68: ; preds = %66, %61
%69 = getelementptr inbounds [502 x i8], [502 x i8]* %6, i64 0, i64 0
%70 = load i32, i32* %8
%71 = srem i32 %70, 8
%72 = icmp ne i32 %71, 0
br i1 %72, label %73, label %77
73: ; preds = %68
%74 = load i32, i32* %8
%75 = sdiv i32 %74, 8
%76 = add nsw i32 %75, 1
br label %80
77: ; preds = %68
%78 = load i32, i32* %8
%79 = sdiv i32 %78, 8
br label %80
80: ; preds = %77, %73
%81 = phi i32 [ %76, %73 ], [ %79, %77 ]
%82 = call i32 (i32, ...) @write(i32 1, i8* %69, i32 %81)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"read(): \00"
@.str.1 = [12 x i8] c"File to big\00"
define void @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4017 x i8]
%4 = alloca [502 x i8]
%5 = getelementptr inbounds [502 x i8], [502 x i8]* %4, i64 0, i64 0
%6 = alloca i32
%7 = getelementptr inbounds [4017 x i8], [4017 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [502 x i8], [502 x i8]* %4, i64 0, i64 0
%9 = bitcast i32* %6 to i8*
%10 = call i32 @read(i32 0, i8* %7, i32 4017)
%11 = icmp slt i32 %10, 1
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = icmp eq i32 %10, 4017
br i1 %13, label %14, label %18
14: ; preds = %12
%15 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %18
16: ; preds = %2
%17 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %73
18: ; preds = %12, %14
%19 = zext i32 %10 to i64
%20 = and i64 %19, 1
%21 = icmp eq i32 %10, 1
br i1 %21, label %57, label %22
22: ; preds = %18
%23 = and i64 %19, 4294967294
br label %24
24: ; preds = %53, %22
%25 = phi i64 [ 0, %22 ], [ %54, %53 ]
%26 = phi i64 [ 0, %22 ], [ %55, %53 ]
%27 = getelementptr inbounds [4017 x i8], [4017 x i8]* %3, i64 0, i64 %25
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 49
br i1 %29, label %30, label %39
30: ; preds = %24
%31 = trunc i64 %25 to i8
%32 = and i8 %31, 6
%33 = shl nuw i8 1, %32
%34 = lshr i64 %25, 3
%35 = and i64 %34, 536870911
%36 = getelementptr inbounds [502 x i8], [502 x i8]* %4, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = or i8 %37, %33
store i8 %38, i8* %36
br label %39
39: ; preds = %24, %30
%40 = or i64 %25, 1
%41 = getelementptr inbounds [4017 x i8], [4017 x i8]* %3, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 49
br i1 %43, label %44, label %53
44: ; preds = %39
%45 = trunc i64 %40 to i8
%46 = and i8 %45, 7
%47 = shl nuw i8 1, %46
%48 = lshr i64 %25, 3
%49 = and i64 %48, 536870911
%50 = getelementptr inbounds [502 x i8], [502 x i8]* %4, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = or i8 %51, %47
store i8 %52, i8* %50
br label %53
53: ; preds = %44, %39
%54 = add nuw nsw i64 %25, 2
%55 = add i64 %26, 2
%56 = icmp eq i64 %55, %23
br i1 %56, label %57, label %24
57: ; preds = %53, %18
%58 = phi i64 [ 0, %18 ], [ %54, %53 ]
%59 = icmp eq i64 %20, 0
br i1 %59, label %73, label %60
60: ; preds = %57
%61 = getelementptr inbounds [4017 x i8], [4017 x i8]* %3, i64 0, i64 %58
%62 = load i8, i8* %61
%63 = icmp eq i8 %62, 49
br i1 %63, label %64, label %73
64: ; preds = %60
%65 = trunc i64 %58 to i8
%66 = and i8 %65, 7
%67 = shl nuw i8 1, %66
%68 = lshr i64 %58, 3
%69 = and i64 %68, 536870911
%70 = getelementptr inbounds [502 x i8], [502 x i8]* %4, i64 0, i64 %69
%71 = load i8, i8* %70
%72 = or i8 %71, %67
store i8 %72, i8* %70
br label %73
73: ; preds = %57, %64, %60, %16
%74 = tail call i32 @htons(i32 %10)
store i32 %74, i32* %6
%75 = icmp eq i32 %0, 1
br i1 %75, label %76, label %78
76: ; preds = %73
%77 = call i32 (i32, ...) @write(i32 1, i32* %6, i64 4)
br label %78
78: ; preds = %76, %73
%79 = and i32 %10, 7
%80 = icmp ne i32 %79, 0
%81 = sdiv i32 %10, 8
%82 = zext i1 %80 to i32
%83 = add nsw i32 %81, %82
%84 = call i32 (i32, ...) @write(i32 1, i8* %8, i32 %83)
ret void
}