#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;

/* Variables and functions */
int ntohs(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int read(int /*<<< orphan*/, unsigned char *, int);
void main() {
  unsigned char input[1004];
  uint16_t i = 0;
  uint16_t len = 0;
  uint16_t len_net = 0;
  len = read(0, input, 1004 + 1);
  if (len < 1) {
    perror("read(): ");
  } else if (len == 1004 + 1) {
    printf("File to big");
  }
  len_net = *((uint16_t *)input);
  len = ntohs(len_net);
  for (i = 2 * 8; i < len + 2 * 8; i++) {
    if (input[i / 8] & (1 << (i % 8)))
      printf("1");
    else
      printf("0");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x3f4(%rbp)
movl   $0x0,-0x3f8(%rbp)
movl   $0x0,-0x3fc(%rbp)
lea    -0x3f0(%rbp),%rsi
xor    %edi,%edi
mov    $0x3ed,%edx
call   1040 <read@plt>
mov    %eax,-0x3f8(%rbp)
cmpl   $0x1,-0x3f8(%rbp)
jge    11a0 <main+0x60>
lea    0xe6a(%rip),%rdi
call   1060 <perror@plt>
jmp    11c1 <main+0x81>
cmpl   $0x3ed,-0x3f8(%rbp)
jne    11bc <main+0x7c>
lea    0xe52(%rip),%rdi
call   1030 <printf@plt>
jmp    11c1 <main+0x81>
mov    -0x3f0(%rbp),%eax
mov    %eax,-0x3fc(%rbp)
mov    -0x3fc(%rbp),%edi
call   1050 <ntohs@plt>
mov    %eax,-0x3f8(%rbp)
movl   $0x10,-0x3f4(%rbp)
mov    -0x3f4(%rbp),%eax
mov    -0x3f8(%rbp),%ecx
add    $0x10,%ecx
cmp    %ecx,%eax
jge    127d <main+0x13d>
mov    -0x3f4(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cltq
movzbl -0x3f0(%rbp,%rax,1),%eax
ff
mov    %eax,-0x400(%rbp)
mov    -0x3f4(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    -0x400(%rbp),%eax
mov    %edx,%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1258 <main+0x118>
lea    0xdc7(%rip),%rdi
call   1030 <printf@plt>
jmp    1264 <main+0x124>
lea    0xdb8(%rip),%rdi
call   1030 <printf@plt>
jmp    1269 <main+0x129>
mov    -0x3f4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3f4(%rbp)
jmp    11e8 <main+0xa8>
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x3f8,%rsp
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x3ed,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11f0 <main+0xa0>
cmp    $0x3ed,%eax
jne    1184 <main+0x34>
lea    0xe8a(%rip),%rdi
call   1040 <printf@plt>
mov    (%rsp),%edi
call   1060 <ntohs@plt>
test   %eax,%eax
jle    11e5 <main+0x95>
mov    %eax,%r14d
add    $0xf,%r14d
cmp    $0x11,%r14d
mov    $0x10,%ebx
cmovl  %ebx,%r14d
neg    %r14d
nopw   0x0(%rax,%rax,1)
mov    %ebx,%eax
shr    $0x3,%rax
movzbl (%rsp,%rax,1),%eax
mov    %ebx,%ecx
and    $0x7,%cl
movzbl %cl,%ecx
bt     %ecx,%eax
mov    $0x31,%edi
adc    $0xffffffff,%edi
call   1030 <putchar@plt>
lea    (%r14,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
jne    11b0 <main+0x60>
add    $0x3f8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe09(%rip),%rdi
call   1070 <perror@plt>
jmp    1184 <main+0x34>

LLVM IR (-O0):
@.str = [9 x i8] c"read(): \00"
@.str.1 = [12 x i8] c"File to big\00"
@.str.2 = [2 x i8] c"1\00"
@.str.3 = [2 x i8] c"0\00"
define void @main() {
%1 = alloca [1004 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
%5 = getelementptr inbounds [1004 x i8], [1004 x i8]* %1, i64 0, i64 0
%6 = call i32 @read(i32 0, i8* %5, i32 1005)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %17
11: ; preds = %0
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 1005
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
br label %17
17: ; preds = %16, %9
%18 = getelementptr inbounds [1004 x i8], [1004 x i8]* %1, i64 0, i64 0
%19 = bitcast i8* %18 to i32*
%20 = load i32, i32* %19
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = call i32 @ntohs(i32 %21)
store i32 %22, i32* %3
store i32 16, i32* %2
br label %23
23: ; preds = %45, %17
%24 = load i32, i32* %2
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 16
%27 = icmp slt i32 %24, %26
br i1 %27, label %28, label %48
28: ; preds = %23
%29 = load i32, i32* %2
%30 = sdiv i32 %29, 8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [1004 x i8], [1004 x i8]* %1, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = load i32, i32* %2
%36 = srem i32 %35, 8
%37 = shl i32 1, %36
%38 = and i32 %34, %37
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %28
%41 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %44
42: ; preds = %28
%43 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %44
44: ; preds = %42, %40
br label %45
45: ; preds = %44
%46 = load i32, i32* %2
%47 = add nsw i32 %46, 1
store i32 %47, i32* %2
br label %23
48: ; preds = %23
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() {
%1 = alloca [1004 x i8]
%2 = getelementptr inbounds [1004 x i8], [1004 x i8]* %1, i64 0, i64 0
%3 = call i32 @read(i32 0, i8* %2, i32 1005)
%4 = icmp slt i32 %3, 1
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %11
7: ; preds = %0
%8 = icmp eq i32 %3, 1005
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %7, %9, %5
%12 = bitcast [1004 x i8]* %1 to i32*
%13 = load i32, i32* %12
%14 = tail call i32 @ntohs(i32 %13)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %34
16: ; preds = %11
%17 = add nuw i32 %14, 15
%18 = call i32 @llvm.smax.i32(i32 %17, i32 16)
br label %19
19: ; preds = %16, %19
%20 = phi i32 [ %32, %19 ], [ 16, %16 ]
%21 = lshr i32 %20, 3
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds [1004 x i8], [1004 x i8]* %1, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = and i32 %20, 7
%27 = shl nuw nsw i32 1, %26
%28 = and i32 %27, %25
%29 = icmp eq i32 %28, 0
%30 = select i1 %29, i32 48, i32 49
%31 = tail call i32 @putchar(i32 %30)
%32 = add nuw i32 %20, 1
%33 = icmp eq i32 %20, %18
br i1 %33, label %34, label %19
34: ; preds = %19, %11
ret void
}