#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ decode_page(char *, char *, int);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int decode_file(int fdin, int fdout) {
  int rlen, wlen;
  char bu[0x200], buo[0x200];
  rlen = lseek(fdin, 0, SEEK_END);
  lseek(fdin, 0, SEEK_SET);
  while (rlen) {
    if (rlen > 0x200)
      wlen = 0x200;
    else
      wlen = rlen;
    read(fdin, bu, wlen);
    decode_page(bu, buo, wlen);
    write(fdout, buo, wlen);
    rlen -= wlen;
  }
}


x86 assembly (clang, -O0):
<decode_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e8d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
cmpl   $0x0,-0x10(%rbp)
je     11ed <decode_file+0xad>
cmpl   $0x200,-0x10(%rbp)
jle    119d <decode_file+0x5d>
movl   $0x200,-0x14(%rbp)
jmp    11a3 <decode_file+0x63>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <read@plt>
lea    -0x220(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <decode_page@plt>
mov    -0xc(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
jmp    117a <decode_file+0x3a>
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %esi,%r14d
mov    %edi,%r15d
mov    0x2e8a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %eax,%ebx
mov    0x2e68(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
test   %ebx,%ebx
je     11c9 <decode_file+0x89>
lea    0x200(%rsp),%r12
mov    %rsp,%r13
nopl   0x0(%rax,%rax,1)
cmp    $0x200,%ebx
mov    $0x200,%ebp
cmovl  %ebx,%ebp
mov    %r15d,%edi
mov    %r12,%rsi
mov    %ebp,%edx
call   1050 <read@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
call   1060 <decode_page@plt>
mov    %r14d,%edi
mov    %r13,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
sub    %ebp,%ebx
jne    1190 <decode_file+0x50>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @decode_file(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [512 x i8]
%9 = alloca [512 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
%10 = load i32, i32* %4
%11 = load i32, i32* @SEEK_END
%12 = call i32 @lseek(i32 %10, i32 0, i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %4
%14 = load i32, i32* @SEEK_SET
%15 = call i32 @lseek(i32 %13, i32 0, i32 %14)
br label %16
16: ; preds = %25, %2
%17 = load i32, i32* %6
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %41
19: ; preds = %16
%20 = load i32, i32* %6
%21 = icmp sgt i32 %20, 512
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 512, i32* %7
br label %25
23: ; preds = %19
%24 = load i32, i32* %6
store i32 %24, i32* %7
br label %25
25: ; preds = %23, %22
%26 = load i32, i32* %4
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%28 = load i32, i32* %7
%29 = call i32 @read(i32 %26, i8* %27, i32 %28)
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%32 = load i32, i32* %7
%33 = call i32 @decode_page(i8* %30, i8* %31, i32 %32)
%34 = load i32, i32* %5
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%36 = load i32, i32* %7
%37 = call i32 @write(i32 %34, i8* %35, i32 %36)
%38 = load i32, i32* %7
%39 = load i32, i32* %6
%40 = sub nsw i32 %39, %38
store i32 %40, i32* %6
br label %16
41: ; preds = %16
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @decode_file(i32 %0, i32 %1) {
%3 = alloca [512 x i8]
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @SEEK_END
%8 = tail call i32 @lseek(i32 %0, i32 0, i32 %7)
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @lseek(i32 %0, i32 0, i32 %9)
%11 = icmp eq i32 %8, 0
br i1 %11, label %21, label %12
12: ; preds = %2, %12
%13 = phi i32 [ %19, %12 ], [ %8, %2 ]
%14 = icmp slt i32 %13, 512
%15 = select i1 %14, i32 %13, i32 512
%16 = call i32 @read(i32 %0, i8* %5, i32 %15)
%17 = call i32 @decode_page(i8* %5, i8* %6, i32 %15)
%18 = call i32 @write(i32 %1, i8* %6, i32 %15)
%19 = sub nsw i32 %13, %15
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %12
21: ; preds = %12, %2
ret i32 undef
}