#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 /*<<< orphan*/ x;
typedef int uint64_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(int *, int, int, int /*<<< orphan*/ *);
int fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int read_data(FILE *ifp, FILE *ofp) {
  uint64_t x;
  for (;;) {
    if (fread(&x, sizeof(x), 1, ifp) != 1) {
      if (ferror(ifp)) {
        fprintf(stderr, "failed to read input\n");
        return 0;
      }
      break;
    }
    x = (((uint64_t)(x) << 56) | (((uint64_t)(x) << 40) & 0xff000000000000ULL) |
         (((uint64_t)(x) << 24) & 0xff0000000000ULL) |
         (((uint64_t)(x) << 8) & 0xff00000000ULL) |
         (((uint64_t)(x) >> 8) & 0xff000000ULL) |
         (((uint64_t)(x) >> 24) & 0xff0000ULL) |
         (((uint64_t)(x) >> 40) & 0xff00ULL) | ((uint64_t)(x) >> 56));
    if (fwrite(&x, sizeof(x), 1, ofp) != 1) {
      fprintf(stderr, "failed to write output\n");
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<read_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     11a9 <read_data+0x69>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11a4 <read_data+0x64>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12ad <read_data+0x16d>
jmp    12a6 <read_data+0x166>
mov    -0x1c(%rbp),%eax
mov    $0x38,%ecx
shl    %cl,%eax
cltq
mov    -0x1c(%rbp),%edx
mov    $0x28,%ecx
shl    %cl,%edx
mov    %edx,%ecx
movslq %ecx,%rcx
movabs $0xff000000000000,%rdx
and    %rdx,%rcx
or     %rcx,%rax
mov    -0x1c(%rbp),%ecx
shl    $0x18,%ecx
movslq %ecx,%rcx
movabs $0xff0000000000,%rdx
and    %rdx,%rcx
or     %rcx,%rax
mov    -0x1c(%rbp),%ecx
shl    $0x8,%ecx
movslq %ecx,%rcx
movabs $0xff00000000,%rdx
and    %rdx,%rcx
or     %rcx,%rax
mov    -0x1c(%rbp),%ecx
sar    $0x8,%ecx
movslq %ecx,%rcx
movabs $0xff000000,%rdx
and    %rdx,%rcx
or     %rcx,%rax
mov    -0x1c(%rbp),%ecx
sar    $0x18,%ecx
movslq %ecx,%rcx
and    $0xff0000,%rcx
or     %rcx,%rax
mov    -0x1c(%rbp),%edx
mov    $0x28,%ecx
sar    %cl,%edx
mov    %edx,%ecx
movslq %ecx,%rcx
and    $0xff00,%rcx
or     %rcx,%rax
mov    -0x1c(%rbp),%edx
mov    $0x38,%ecx
sar    %cl,%edx
mov    %edx,%ecx
movslq %ecx,%rcx
or     %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
cmp    $0x1,%eax
je     12a1 <read_data+0x161>
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
lea    0xd86(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12ad <read_data+0x16d>
jmp    1150 <read_data+0x10>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_data>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0x4(%rsp),%r12
lea    0xebc(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    1196 <read_data+0x56>
mov    %r12,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1060 <fwrite@plt>
cmp    $0x1,%eax
je     1160 <read_data+0x20>
jmp    11aa <read_data+0x6a>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     11bf <read_data+0x7f>
lea    0xe56(%rip),%r14
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
jmp    11c4 <read_data+0x84>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"failed to read input\0A\00"
@.str.1 = [24 x i8] c"failed to write output\0A\00"
define i32 @read_data(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
br label %7
7: ; preds = %64, %2
%8 = load i32*, i32** %4
%9 = call i32 @fread(i32* %6, i32 4, i32 1, i32* %8)
%10 = icmp ne i32 %9, 1
br i1 %10, label %11, label %19
11: ; preds = %7
%12 = load i32*, i32** %4
%13 = call i64 @ferror(i32* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %66
18: ; preds = %11
br label %65
19: ; preds = %7
%20 = load i32, i32* %6
%21 = shl i32 %20, 56
%22 = sext i32 %21 to i64
%23 = load i32, i32* %6
%24 = shl i32 %23, 40
%25 = sext i32 %24 to i64
%26 = and i64 %25, 71776119061217280
%27 = or i64 %22, %26
%28 = load i32, i32* %6
%29 = shl i32 %28, 24
%30 = sext i32 %29 to i64
%31 = and i64 %30, 280375465082880
%32 = or i64 %27, %31
%33 = load i32, i32* %6
%34 = shl i32 %33, 8
%35 = sext i32 %34 to i64
%36 = and i64 %35, 1095216660480
%37 = or i64 %32, %36
%38 = load i32, i32* %6
%39 = ashr i32 %38, 8
%40 = sext i32 %39 to i64
%41 = and i64 %40, 4278190080
%42 = or i64 %37, %41
%43 = load i32, i32* %6
%44 = ashr i32 %43, 24
%45 = sext i32 %44 to i64
%46 = and i64 %45, 16711680
%47 = or i64 %42, %46
%48 = load i32, i32* %6
%49 = ashr i32 %48, 40
%50 = sext i32 %49 to i64
%51 = and i64 %50, 65280
%52 = or i64 %47, %51
%53 = load i32, i32* %6
%54 = ashr i32 %53, 56
%55 = sext i32 %54 to i64
%56 = or i64 %52, %55
%57 = trunc i64 %56 to i32
store i32 %57, i32* %6
%58 = load i32*, i32** %5
%59 = call i32 @fwrite(i32* %6, i32 4, i32 1, i32* %58)
%60 = icmp ne i32 %59, 1
br i1 %60, label %61, label %64
61: ; preds = %19
%62 = load i32, i32* @stderr
%63 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %66
64: ; preds = %19
br label %7
65: ; preds = %18
store i32 1, i32* %3
br label %66
66: ; preds = %65, %61, %15
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"failed to read input\0A\00"
@.str.1 = [24 x i8] c"failed to write output\0A\00"
define i32 @read_data(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
br label %5
5: ; preds = %11, %2
%6 = call i32 @fread(i32* %3, i32 4, i32 1, i32* %0)
%7 = icmp eq i32 %6, 1
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = tail call i64 @ferror(i32* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %18, label %14
11: ; preds = %5
%12 = call i32 @fwrite(i32* %3, i32 4, i32 1, i32* %1)
%13 = icmp eq i32 %12, 1
br i1 %13, label %5, label %14
14: ; preds = %11, %8
%15 = phi i8* [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), %8 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), %11 ]
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* %15)
br label %18
18: ; preds = %14, %8
%19 = phi i32 [ 1, %8 ], [ 0, %14 ]
ret i32 %19
}