#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int lif2rom(char *f1, char *f2) {
  FILE *src;
  FILE *dest;
  unsigned char bufo[8];
  unsigned char bufi[5];
  int i, n;
  unsigned char c;
  src = fopen(f1, "rb");
  if (src == NULL)
    return (-1);
  dest = fopen(f2, "wb");
  if (dest == NULL)
    return (-1);
  i = 0;
  do {
    if (fread(bufi, 1, 5, src) != 5)
      break;
    c = bufi[0];
    bufo[0] = (c >> 0) & 3;
    bufo[1] = bufi[4];
    bufo[2] = (c >> 2) & 3;
    bufo[3] = bufi[3];
    bufo[4] = (c >> 4) & 3;
    bufo[5] = bufi[2];
    bufo[6] = (c >> 6) & 3;
    bufo[7] = bufi[1];
    fwrite(bufo, 1, 8, dest);
    i += 4;
    if (i == 4096)
      break;
  } while (1);
  fclose(dest);
  fclose(src);
  return (i);
}


x86 assembly (clang, -O0):
<lif2rom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117b <lif2rom+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1282 <lif2rom+0x142>
mov    -0x18(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a6 <lif2rom+0x66>
movl   $0xffffffff,-0x4(%rbp)
jmp    1282 <lif2rom+0x142>
movl   $0x0,-0x3c(%rbp)
lea    -0x35(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x5,%edx
call   1030 <fread@plt>
cmp    $0x5,%eax
je     11d2 <lif2rom+0x92>
jmp    126a <lif2rom+0x12a>
mov    -0x35(%rbp),%al
mov    %al,-0x41(%rbp)
movzbl -0x41(%rbp),%eax
sar    $0x0,%eax
and    $0x3,%eax
mov    %al,-0x30(%rbp)
mov    -0x31(%rbp),%al
mov    %al,-0x2f(%rbp)
movzbl -0x41(%rbp),%eax
sar    $0x2,%eax
and    $0x3,%eax
mov    %al,-0x2e(%rbp)
mov    -0x32(%rbp),%al
mov    %al,-0x2d(%rbp)
movzbl -0x41(%rbp),%eax
sar    $0x4,%eax
and    $0x3,%eax
mov    %al,-0x2c(%rbp)
mov    -0x33(%rbp),%al
mov    %al,-0x2b(%rbp)
movzbl -0x41(%rbp),%eax
sar    $0x6,%eax
and    $0x3,%eax
mov    %al,-0x2a(%rbp)
mov    -0x34(%rbp),%al
mov    %al,-0x29(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x8,%edx
call   1060 <fwrite@plt>
mov    -0x3c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x1000,-0x3c(%rbp)
jne    1256 <lif2rom+0x116>
jmp    126a <lif2rom+0x12a>
jmp    125b <lif2rom+0x11b>
mov    $0x1,%al
test   $0x1,%al
jne    11ad <lif2rom+0x6d>
jmp    126a <lif2rom+0x12a>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lif2rom>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     1244 <lif2rom+0x104>
mov    %rax,%r14
lea    0xe8f(%rip),%rsi
mov    %r15,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     1244 <lif2rom+0x104>
mov    %rax,%r15
xor    %ebx,%ebx
lea    0x3(%rsp),%r12
lea    0x8(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x5,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
cmp    $0x5,%eax
jne    1234 <lif2rom+0xf4>
movzbl 0x3(%rsp),%eax
movzbl 0x4(%rsp),%ecx
mov    %eax,%edx
and    $0x3,%dl
mov    %dl,0x8(%rsp)
movzbl 0x7(%rsp),%edx
mov    %dl,0x9(%rsp)
mov    %eax,%edx
shr    $0x2,%dl
and    $0x3,%dl
mov    %dl,0xa(%rsp)
movzbl 0x6(%rsp),%edx
mov    %dl,0xb(%rsp)
mov    %eax,%edx
shr    $0x4,%dl
and    $0x3,%dl
mov    %dl,0xc(%rsp)
movzbl 0x5(%rsp),%edx
mov    %dl,0xd(%rsp)
shr    $0x6,%al
mov    %al,0xe(%rsp)
mov    %cl,0xf(%rsp)
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x8,%edx
mov    %r15,%rcx
call   1060 <fwrite@plt>
add    $0x4,%ebx
cmp    $0x1000,%ebx
jne    11a0 <lif2rom+0x60>
mov    $0x1000,%ebx
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
define i32 @lif2rom(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [8 x i8]
%9 = alloca [5 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
%13 = load i8*, i8** %4
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 -1, i32* %3
br label %86
18: ; preds = %2
%19 = load i8*, i8** %5
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %7
%21 = load i32*, i32** %7
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 -1, i32* %3
br label %86
24: ; preds = %18
store i32 0, i32* %10
br label %25
25: ; preds = %79, %24
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%27 = load i32*, i32** %6
%28 = call i32 @fread(i8* %26, i32 1, i32 5, i32* %27)
%29 = icmp ne i32 %28, 5
br i1 %29, label %30, label %31
30: ; preds = %25
br label %80
31: ; preds = %25
%32 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%33 = load i8, i8* %32
store i8 %33, i8* %12
%34 = load i8, i8* %12
%35 = zext i8 %34 to i32
%36 = ashr i32 %35, 0
%37 = and i32 %36, 3
%38 = trunc i32 %37 to i8
%39 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
store i8 %38, i8* %39
%40 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 4
%41 = load i8, i8* %40
%42 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 1
store i8 %41, i8* %42
%43 = load i8, i8* %12
%44 = zext i8 %43 to i32
%45 = ashr i32 %44, 2
%46 = and i32 %45, 3
%47 = trunc i32 %46 to i8
%48 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 2
store i8 %47, i8* %48
%49 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 3
%50 = load i8, i8* %49
%51 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 3
store i8 %50, i8* %51
%52 = load i8, i8* %12
%53 = zext i8 %52 to i32
%54 = ashr i32 %53, 4
%55 = and i32 %54, 3
%56 = trunc i32 %55 to i8
%57 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 4
store i8 %56, i8* %57
%58 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 2
%59 = load i8, i8* %58
%60 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 5
store i8 %59, i8* %60
%61 = load i8, i8* %12
%62 = zext i8 %61 to i32
%63 = ashr i32 %62, 6
%64 = and i32 %63, 3
%65 = trunc i32 %64 to i8
%66 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 6
store i8 %65, i8* %66
%67 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 1
%68 = load i8, i8* %67
%69 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 7
store i8 %68, i8* %69
%70 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%71 = load i32*, i32** %7
%72 = call i32 @fwrite(i8* %70, i32 1, i32 8, i32* %71)
%73 = load i32, i32* %10
%74 = add nsw i32 %73, 4
store i32 %74, i32* %10
%75 = load i32, i32* %10
%76 = icmp eq i32 %75, 4096
br i1 %76, label %77, label %78
77: ; preds = %31
br label %80
78: ; preds = %31
br label %79
79: ; preds = %78
br i1 true, label %25, label %80
80: ; preds = %79, %77, %30
%81 = load i32*, i32** %7
%82 = call i32 @fclose(i32* %81)
%83 = load i32*, i32** %6
%84 = call i32 @fclose(i32* %83)
%85 = load i32, i32* %10
store i32 %85, i32* %3
br label %86
86: ; preds = %80, %23, %17
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
define i32 @lif2rom(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca [8 x i8]
%4 = alloca [5 x i8]
%5 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %47, label %9
9: ; preds = %2
%10 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %47, label %12
12: ; preds = %9
%13 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 4
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 1
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 2
%16 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 3
%17 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 3
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 4
%19 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 2
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 5
%21 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 6
%22 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 1
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 7
br label %24
24: ; preds = %12, %28
%25 = phi i32 [ %41, %28 ], [ 0, %12 ]
%26 = call i32 @fread(i8* %6, i32 1, i32 5, i32* %7)
%27 = icmp eq i32 %26, 5
br i1 %27, label %28, label %43
28: ; preds = %24
%29 = load i8, i8* %6
%30 = and i8 %29, 3
store i8 %30, i8* %5
%31 = load i8, i8* %13
store i8 %31, i8* %14
%32 = lshr i8 %29, 2
%33 = and i8 %32, 3
store i8 %33, i8* %15
%34 = load i8, i8* %16
store i8 %34, i8* %17
%35 = lshr i8 %29, 4
%36 = and i8 %35, 3
store i8 %36, i8* %18
%37 = load i8, i8* %19
store i8 %37, i8* %20
%38 = lshr i8 %29, 6
store i8 %38, i8* %21
%39 = load i8, i8* %22
store i8 %39, i8* %23
%40 = call i32 @fwrite(i8* %5, i32 1, i32 8, i32* %10)
%41 = add nuw nsw i32 %25, 4
%42 = icmp eq i32 %41, 4096
br i1 %42, label %43, label %24
43: ; preds = %28, %24
%44 = phi i32 [ %25, %24 ], [ 4096, %28 ]
%45 = tail call i32 @fclose(i32* %10)
%46 = tail call i32 @fclose(i32* %7)
br label %47
47: ; preds = %9, %2, %43
%48 = phi i32 [ %44, %43 ], [ -1, %2 ], [ -1, %9 ]
ret i32 %48
}