#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 O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_RDWR;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int source_fd = -1;
  int dest_fd = -1;
  char inbuff[8];
  if (argc < 2) {
    printf("Usage: %s input_file output_file\n", argv[0]);
  }
  source_fd = open(argv[1], O_RDONLY);
  dest_fd = open(argv[2], (O_RDWR | O_CREAT),
                 (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH));
  if ((source_fd < 0) || (dest_fd < 0)) {
    printf("unable to open input or output file\n");
  }
  while (read(source_fd, inbuff, 8) == 8) {
    int i = 0;
    char outbuff = 0;
    for (i = 0; i < 8; i++) {
      outbuff |= ((inbuff[i] & 0x01) << i);
    }
    write(dest_fd, &outbuff, 1);
  }
  close(source_fd);
  close(dest_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1193 <main+0x43>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
mov    0x2e32(%rip),%rax
or     (%rax),%esi
mov    0x2de1(%rip),%rax
mov    (%rax),%edx
mov    0x2df8(%rip),%rax
or     (%rax),%edx
mov    0x2ddf(%rip),%rax
or     (%rax),%edx
mov    0x2dce(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     120a <main+0xba>
cmpl   $0x0,-0x18(%rbp)
jge    1218 <main+0xc8>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    121d <main+0xcd>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1060 <read@plt>
cmp    $0x8,%eax
jne    1293 <main+0x143>
movl   $0x0,-0x24(%rbp)
movb   $0x0,-0x25(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x8,-0x24(%rbp)
jge    127d <main+0x12d>
movslq -0x24(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%eax
and    $0x1,%eax
mov    -0x24(%rbp),%ecx
shl    %cl,%eax
mov    %eax,%ecx
movsbl -0x25(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x25(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1249 <main+0xf9>
mov    -0x18(%rbp),%edi
lea    -0x25(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    121d <main+0xcd>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
cmp    $0x1,%edi
jg     1184 <main+0x24>
mov    0x0(%rbp),%rsi
lea    0xe83(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbp),%rdi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1080 <open@plt>
mov    0x2e41(%rip),%rcx
mov    0x2e52(%rip),%rdx
mov    (%rdx),%esi
or     (%rcx),%esi
mov    0x2dff(%rip),%rcx
mov    0x2e18(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    %eax,%ebx
mov    0x2dfb(%rip),%rax
or     (%rax),%edx
mov    0x10(%rbp),%rdi
mov    0x2de6(%rip),%rax
or     (%rax),%edx
xor    %eax,%eax
call   1080 <open@plt>
mov    %eax,%ebp
mov    %ebx,%eax
or     %ebp,%eax
jns    11ef <main+0x8f>
lea    0xe38(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1070 <read@plt>
cmp    $0x8,%eax
jne    12a6 <main+0x146>
lea    0xf(%rsp),%r14
lea    0x10(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl 0x10(%rsp),%eax
movzbl 0x11(%rsp),%ecx
and    $0x1,%al
add    %cl,%cl
and    $0x2,%cl
or     %al,%cl
movzbl 0x12(%rsp),%eax
shl    $0x2,%al
and    $0x4,%al
or     %cl,%al
movzbl 0x13(%rsp),%ecx
shl    $0x3,%cl
and    $0x8,%cl
or     %al,%cl
movzbl 0x14(%rsp),%eax
shl    $0x4,%al
and    $0x10,%al
or     %cl,%al
movzbl 0x15(%rsp),%ecx
shl    $0x5,%cl
and    $0x20,%cl
or     %al,%cl
movzbl 0x16(%rsp),%eax
shl    $0x6,%al
and    $0x40,%al
or     %cl,%al
movzbl 0x17(%rsp),%ecx
shl    $0x7,%cl
or     %al,%cl
mov    %cl,0xf(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x8,%edx
call   1070 <read@plt>
cmp    $0x8,%eax
je     1220 <main+0xc0>
mov    %ebx,%edi
call   1060 <close@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Usage: %s input_file output_file\0A\00"
@O_RDONLY = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [37 x i8] c"unable to open input or output file\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [8 x i8]
%9 = alloca i32
%10 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i32 -1, i32* %7
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %13, %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i32, i32* @O_RDONLY
%23 = call i32 (i8*, i32, ...) @open(i8* %21, i32 %22)
store i32 %23, i32* %6
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_RDWR
%28 = load i32, i32* @O_CREAT
%29 = or i32 %27, %28
%30 = load i32, i32* @S_IRUSR
%31 = load i32, i32* @S_IWUSR
%32 = or i32 %30, %31
%33 = load i32, i32* @S_IRGRP
%34 = or i32 %32, %33
%35 = load i32, i32* @S_IROTH
%36 = or i32 %34, %35
%37 = call i32 (i8*, i32, ...) @open(i8* %26, i32 %29, i32 %36)
store i32 %37, i32* %7
%38 = load i32, i32* %6
%39 = icmp slt i32 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %18
%41 = load i32, i32* %7
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %40, %18
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %45
45: ; preds = %43, %40
br label %46
46: ; preds = %71, %45
%47 = load i32, i32* %6
%48 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%49 = call i32 @read(i32 %47, i8* %48, i32 8)
%50 = icmp eq i32 %49, 8
br i1 %50, label %51, label %74
51: ; preds = %46
store i32 0, i32* %9
store i8 0, i8* %10
store i32 0, i32* %9
br label %52
52: ; preds = %68, %51
%53 = load i32, i32* %9
%54 = icmp slt i32 %53, 8
br i1 %54, label %55, label %71
55: ; preds = %52
%56 = load i32, i32* %9
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 %57
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = and i32 %60, 1
%62 = load i32, i32* %9
%63 = shl i32 %61, %62
%64 = load i8, i8* %10
%65 = sext i8 %64 to i32
%66 = or i32 %65, %63
%67 = trunc i32 %66 to i8
store i8 %67, i8* %10
br label %68
68: ; preds = %55
%69 = load i32, i32* %9
%70 = add nsw i32 %69, 1
store i32 %70, i32* %9
br label %52
71: ; preds = %52
%72 = load i32, i32* %7
%73 = call i32 @write(i32 %72, i8* %10, i32 1)
br label %46
74: ; preds = %46
%75 = load i32, i32* %6
%76 = call i32 @close(i32 %75)
%77 = load i32, i32* %7
%78 = call i32 @close(i32 %77)
ret i32 0
}

LLVM IR (-O2):
@.str = [34 x i8] c"Usage: %s input_file output_file\0A\00"
@O_RDONLY = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@str = [36 x i8] c"unable to open input or output file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [8 x i8]
%4 = alloca i8
%5 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %7, %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 (i8*, i32, ...) @open(i8* %12, i32 %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDWR
%18 = load i32, i32* @O_CREAT
%19 = or i32 %18, %17
%20 = load i32, i32* @S_IRUSR
%21 = load i32, i32* @S_IWUSR
%22 = or i32 %21, %20
%23 = load i32, i32* @S_IRGRP
%24 = or i32 %22, %23
%25 = load i32, i32* @S_IROTH
%26 = or i32 %24, %25
%27 = tail call i32 (i8*, i32, ...) @open(i8* %16, i32 %19, i32 %26)
%28 = or i32 %27, %14
%29 = icmp sgt i32 %28, -1
br i1 %29, label %32, label %30
30: ; preds = %10
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %32
32: ; preds = %10, %30
%33 = call i32 @read(i32 %14, i8* %5, i32 8)
%34 = icmp eq i32 %33, 8
br i1 %34, label %35, label %76
35: ; preds = %32
%36 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 1
%37 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 2
%38 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 3
%39 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 4
%40 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 5
%41 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 6
%42 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 7
br label %43
43: ; preds = %35, %43
%44 = load i8, i8* %5
%45 = and i8 %44, 1
%46 = load i8, i8* %36
%47 = shl i8 %46, 1
%48 = and i8 %47, 2
%49 = or i8 %45, %48
%50 = load i8, i8* %37
%51 = shl i8 %50, 2
%52 = and i8 %51, 4
%53 = or i8 %49, %52
%54 = load i8, i8* %38
%55 = shl i8 %54, 3
%56 = and i8 %55, 8
%57 = or i8 %53, %56
%58 = load i8, i8* %39
%59 = shl i8 %58, 4
%60 = and i8 %59, 16
%61 = or i8 %57, %60
%62 = load i8, i8* %40
%63 = shl i8 %62, 5
%64 = and i8 %63, 32
%65 = or i8 %61, %64
%66 = load i8, i8* %41
%67 = shl i8 %66, 6
%68 = and i8 %67, 64
%69 = or i8 %65, %68
%70 = load i8, i8* %42
%71 = shl i8 %70, 7
%72 = or i8 %69, %71
store i8 %72, i8* %4
%73 = call i32 @write(i32 %27, i8* %4, i32 1)
%74 = call i32 @read(i32 %14, i8* %5, i32 8)
%75 = icmp eq i32 %74, 8
br i1 %75, label %43, label %76
76: ; preds = %43, %32
%77 = tail call i32 @close(i32 %14)
%78 = tail call i32 @close(i32 %27)
ret i32 0
}