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


x86 assembly (clang, -O0):
<rc4_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1226 <rc4_file+0xd6>
cmpl   $0x200,-0x10(%rbp)
jle    11b6 <rc4_file+0x66>
movl   $0x200,-0x14(%rbp)
jmp    11bc <rc4_file+0x6c>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <read@plt>
lea    -0x220(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    $0x200,%edx
call   1070 <rk_rc4@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x200,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1193 <rc4_file+0x43>
jmp    122b <rc4_file+0xdb>
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0x0,%eax
je     126b <rc4_file+0x11b>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x200,%edx
call   1030 <write@plt>
jmp    122b <rc4_file+0xdb>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rc4_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %edx,%ebx
mov    %esi,%r15d
mov    %edi,%r13d
mov    0x2e78(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %eax,%ebp
mov    0x2e56(%rip),%rax
mov    (%rax),%edx
mov    %r13d,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
test   %ebp,%ebp
je     11fb <rc4_file+0xab>
lea    0x210(%rsp),%r12
mov    %r13d,0xc(%rsp)
nop
cmp    $0x200,%ebp
mov    $0x200,%r14d
cmovl  %ebp,%r14d
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    0xc(%rsp),%edi
mov    %r12,%rsi
mov    %r14d,%edx
call   1060 <read@plt>
mov    %r12,%rdi
lea    0x10(%rsp),%r13
mov    %r13,%rsi
mov    $0x200,%edx
call   1070 <rk_rc4@plt>
mov    %r15d,%edi
mov    %r13,%rsi
mov    $0x200,%edx
call   1030 <write@plt>
add    $0xffffffff,%ebx
sub    %r14d,%ebp
jne    11a0 <rc4_file+0x50>
test   %ebx,%ebx
je     1234 <rc4_file+0xe4>
lea    0x10(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x200,%edx
call   1030 <write@plt>
add    $0xffffffff,%ebx
jne    1210 <rc4_file+0xc0>
xor    %eax,%eax
add    $0x418,%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 @rc4_file(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [512 x i8]
%11 = alloca [512 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%12 = load i32, i32* %4
%13 = load i32, i32* @SEEK_END
%14 = call i32 @lseek(i32 %12, i32 0, i32 %13)
store i32 %14, i32* %7
%15 = load i32, i32* %4
%16 = load i32, i32* @SEEK_SET
%17 = call i32 @lseek(i32 %15, i32 0, i32 %16)
%18 = load i32, i32* %6
store i32 %18, i32* %9
br label %19
19: ; preds = %28, %3
%20 = load i32, i32* %7
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %46
22: ; preds = %19
%23 = load i32, i32* %7
%24 = icmp sgt i32 %23, 512
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 512, i32* %8
br label %28
26: ; preds = %22
%27 = load i32, i32* %7
store i32 %27, i32* %8
br label %28
28: ; preds = %26, %25
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%30 = call i32 @memset(i8* %29, i32 0, i32 512)
%31 = load i32, i32* %4
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%33 = load i32, i32* %8
%34 = call i32 @read(i32 %31, i8* %32, i32 %33)
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%36 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%37 = call i32 @rk_rc4(i8* %35, i8* %36, i32 512)
%38 = load i32, i32* %5
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%40 = call i32 @write(i32 %38, i8* %39, i32 512)
%41 = load i32, i32* %8
%42 = load i32, i32* %7
%43 = sub nsw i32 %42, %41
store i32 %43, i32* %7
%44 = load i32, i32* %9
%45 = add nsw i32 %44, -1
store i32 %45, i32* %9
br label %19
46: ; preds = %19
br label %47
47: ; preds = %51, %46
%48 = load i32, i32* %9
%49 = add nsw i32 %48, -1
store i32 %49, i32* %9
%50 = icmp ne i32 %48, 0
br i1 %50, label %51, label %57
51: ; preds = %47
%52 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%53 = call i32 @memset(i8* %52, i32 0, i32 512)
%54 = load i32, i32* %5
%55 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%56 = call i32 @write(i32 %54, i8* %55, i32 512)
br label %47
57: ; preds = %47
ret i32 0
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @rc4_file(i32 %0, i32 %1, i32 %2) {
%4 = alloca [512 x i8]
%5 = alloca [512 x i8]
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%8 = load i32, i32* @SEEK_END
%9 = tail call i32 @lseek(i32 %0, i32 0, i32 %8)
%10 = load i32, i32* @SEEK_SET
%11 = tail call i32 @lseek(i32 %0, i32 0, i32 %10)
%12 = icmp eq i32 %9, 0
br i1 %12, label %13, label %16
13: ; preds = %16, %3
%14 = phi i32 [ %2, %3 ], [ %26, %16 ]
%15 = icmp eq i32 %14, 0
br i1 %15, label %34, label %28
16: ; preds = %3, %16
%17 = phi i32 [ %26, %16 ], [ %2, %3 ]
%18 = phi i32 [ %25, %16 ], [ %9, %3 ]
%19 = icmp slt i32 %18, 512
%20 = select i1 %19, i32 %18, i32 512
%21 = call i32 @memset(i8* %6, i32 0, i32 512)
%22 = call i32 @read(i32 %0, i8* %6, i32 %20)
%23 = call i32 @rk_rc4(i8* %6, i8* %7, i32 512)
%24 = call i32 @write(i32 %1, i8* %7, i32 512)
%25 = sub nsw i32 %18, %20
%26 = add nsw i32 %17, -1
%27 = icmp eq i32 %25, 0
br i1 %27, label %13, label %16
28: ; preds = %13, %28
%29 = phi i32 [ %30, %28 ], [ %14, %13 ]
%30 = add nsw i32 %29, -1
%31 = call i32 @memset(i8* %7, i32 0, i32 512)
%32 = call i32 @write(i32 %1, i8* %7, i32 512)
%33 = icmp eq i32 %30, 0
br i1 %33, label %34, label %28
34: ; preds = %28, %13
ret i32 0
}