#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 bin2rom(char *f1, char *f2) {
  FILE *src;
  FILE *dest;
  unsigned char b[10];
  unsigned int v[10];
  unsigned char octets[10];
  int n;
  src = fopen(f1, "rb");
  if (src == NULL)
    return (-1);
  dest = fopen(f2, "wb");
  if (dest == NULL) {
    fclose(src);
    return (-1);
  }
  n = 0;
  while (fread(b, 1, 5, src) == 5) {
    v[0] = ((b[0] & 0xff)) + ((b[1] & 0x03) << 8);
    v[1] = ((b[1] & 0xfc) >> 2) + ((b[2] & 0x0f) << 6);
    v[2] = ((b[2] & 0xf0) >> 4) + ((b[3] & 0x3f) << 4);
    v[3] = ((b[3] & 0xc0) >> 6) + ((b[4] & 0xff) << 2);
    octets[0] = v[0] >> 8;
    octets[1] = v[0] & 0xff;
    octets[2] = v[1] >> 8;
    octets[3] = v[1] & 0xff;
    octets[4] = v[2] >> 8;
    octets[5] = v[2] & 0xff;
    octets[6] = v[3] >> 8;
    octets[7] = v[3] & 0xff;
    fwrite(octets, 1, 8, dest);
    n += 4;
  }
  fclose(src);
  fclose(dest);
  return (n);
}


x86 assembly (clang, -O0):
<bin2rom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%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 <bin2rom+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    12cf <bin2rom+0x18f>
mov    -0x18(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11af <bin2rom+0x6f>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12cf <bin2rom+0x18f>
movl   $0x0,-0x70(%rbp)
lea    -0x32(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x5,%edx
call   1030 <fread@plt>
cmp    $0x5,%eax
jne    12b7 <bin2rom+0x177>
movzbl -0x32(%rbp),%eax
and    $0xff,%eax
movzbl -0x31(%rbp),%ecx
and    $0x3,%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    %eax,-0x60(%rbp)
movzbl -0x31(%rbp),%eax
and    $0xfc,%eax
sar    $0x2,%eax
movzbl -0x30(%rbp),%ecx
and    $0xf,%ecx
shl    $0x6,%ecx
add    %ecx,%eax
mov    %eax,-0x5c(%rbp)
movzbl -0x30(%rbp),%eax
and    $0xf0,%eax
sar    $0x4,%eax
movzbl -0x2f(%rbp),%ecx
and    $0x3f,%ecx
shl    $0x4,%ecx
add    %ecx,%eax
mov    %eax,-0x58(%rbp)
movzbl -0x2f(%rbp),%eax
and    $0xc0,%eax
sar    $0x6,%eax
movzbl -0x2e(%rbp),%ecx
and    $0xff,%ecx
shl    $0x2,%ecx
add    %ecx,%eax
mov    %eax,-0x54(%rbp)
mov    -0x60(%rbp),%eax
shr    $0x8,%eax
mov    %al,-0x6a(%rbp)
mov    -0x60(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x69(%rbp)
mov    -0x5c(%rbp),%eax
shr    $0x8,%eax
mov    %al,-0x68(%rbp)
mov    -0x5c(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x67(%rbp)
mov    -0x58(%rbp),%eax
shr    $0x8,%eax
mov    %al,-0x66(%rbp)
mov    -0x58(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x65(%rbp)
mov    -0x54(%rbp),%eax
shr    $0x8,%eax
mov    %al,-0x64(%rbp)
mov    -0x54(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x63(%rbp)
lea    -0x6a(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x8,%edx
call   1060 <fwrite@plt>
mov    -0x70(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x70(%rbp)
jmp    11b6 <bin2rom+0x76>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x70(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bin2rom>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
lea    0xea8(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1274 <bin2rom+0x134>
mov    %rax,%r13
lea    0xe93(%rip),%rsi
mov    %rbp,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     127b <bin2rom+0x13b>
mov    %rax,%r14
lea    0xe(%rsp),%rdi
mov    $0x1,%esi
mov    $0x5,%edx
mov    %r13,%rcx
call   1030 <fread@plt>
xor    %ebp,%ebp
cmp    $0x5,%eax
jne    126a <bin2rom+0x12a>
xor    %ebp,%ebp
lea    0x4(%rsp),%r15
lea    0xe(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl 0xe(%rsp),%esi
movzbl 0xf(%rsp),%edx
mov    %edx,%ebx
and    $0x3,%bl
movzbl 0x10(%rsp),%ecx
movzbl 0x11(%rsp),%edi
movzbl 0x12(%rsp),%r8d
mov    %bl,0x4(%rsp)
mov    %sil,0x5(%rsp)
mov    %ecx,%eax
shr    $0x2,%al
and    $0x3,%al
mov    %al,0x6(%rsp)
shr    $0x2,%dl
mov    %ecx,%eax
shl    $0x6,%al
or     %dl,%al
mov    %al,0x7(%rsp)
mov    %edi,%eax
shr    $0x4,%al
and    $0x3,%al
mov    %al,0x8(%rsp)
shr    $0x4,%cl
mov    %edi,%eax
shl    $0x4,%al
or     %cl,%al
mov    %al,0x9(%rsp)
mov    %r8d,%eax
shr    $0x6,%al
mov    %al,0xa(%rsp)
shr    $0x6,%dil
shl    $0x2,%r8b
or     %dil,%r8b
mov    %r8b,0xb(%rsp)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x8,%edx
mov    %r14,%rcx
call   1060 <fwrite@plt>
add    $0x4,%ebp
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x5,%edx
mov    %r13,%rcx
call   1030 <fread@plt>
cmp    $0x5,%eax
je     11c0 <bin2rom+0x80>
mov    %r13,%rdi
call   1040 <fclose@plt>
jmp    1283 <bin2rom+0x143>
mov    $0xffffffff,%ebp
jmp    128b <bin2rom+0x14b>
mov    $0xffffffff,%ebp
mov    %r13,%r14
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
define i32 @bin2rom(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [10 x i8]
%9 = alloca [10 x i32]
%10 = alloca [10 x i8]
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%12 = load i8*, i8** %4
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 -1, i32* %3
br label %130
17: ; preds = %2
%18 = load i8*, i8** %5
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %7
%20 = load i32*, i32** %7
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i32*, i32** %6
%24 = call i32 @fclose(i32* %23)
store i32 -1, i32* %3
br label %130
25: ; preds = %17
store i32 0, i32* %11
br label %26
26: ; preds = %31, %25
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%28 = load i32*, i32** %6
%29 = call i32 @fread(i8* %27, i32 1, i32 5, i32* %28)
%30 = icmp eq i32 %29, 5
br i1 %30, label %31, label %124
31: ; preds = %26
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = and i32 %34, 255
%36 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 1
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = and i32 %38, 3
%40 = shl i32 %39, 8
%41 = add nsw i32 %35, %40
%42 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 0
store i32 %41, i32* %42
%43 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 1
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = and i32 %45, 252
%47 = ashr i32 %46, 2
%48 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 2
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = and i32 %50, 15
%52 = shl i32 %51, 6
%53 = add nsw i32 %47, %52
%54 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 1
store i32 %53, i32* %54
%55 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 2
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = and i32 %57, 240
%59 = ashr i32 %58, 4
%60 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 3
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = and i32 %62, 63
%64 = shl i32 %63, 4
%65 = add nsw i32 %59, %64
%66 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 2
store i32 %65, i32* %66
%67 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 3
%68 = load i8, i8* %67
%69 = zext i8 %68 to i32
%70 = and i32 %69, 192
%71 = ashr i32 %70, 6
%72 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 4
%73 = load i8, i8* %72
%74 = zext i8 %73 to i32
%75 = and i32 %74, 255
%76 = shl i32 %75, 2
%77 = add nsw i32 %71, %76
%78 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 3
store i32 %77, i32* %78
%79 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 0
%80 = load i32, i32* %79
%81 = lshr i32 %80, 8
%82 = trunc i32 %81 to i8
%83 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
store i8 %82, i8* %83
%84 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 0
%85 = load i32, i32* %84
%86 = and i32 %85, 255
%87 = trunc i32 %86 to i8
%88 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 1
store i8 %87, i8* %88
%89 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 1
%90 = load i32, i32* %89
%91 = lshr i32 %90, 8
%92 = trunc i32 %91 to i8
%93 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 2
store i8 %92, i8* %93
%94 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 1
%95 = load i32, i32* %94
%96 = and i32 %95, 255
%97 = trunc i32 %96 to i8
%98 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 3
store i8 %97, i8* %98
%99 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 2
%100 = load i32, i32* %99
%101 = lshr i32 %100, 8
%102 = trunc i32 %101 to i8
%103 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 4
store i8 %102, i8* %103
%104 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 2
%105 = load i32, i32* %104
%106 = and i32 %105, 255
%107 = trunc i32 %106 to i8
%108 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 5
store i8 %107, i8* %108
%109 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 3
%110 = load i32, i32* %109
%111 = lshr i32 %110, 8
%112 = trunc i32 %111 to i8
%113 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 6
store i8 %112, i8* %113
%114 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 3
%115 = load i32, i32* %114
%116 = and i32 %115, 255
%117 = trunc i32 %116 to i8
%118 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 7
store i8 %117, i8* %118
%119 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
%120 = load i32*, i32** %7
%121 = call i32 @fwrite(i8* %119, i32 1, i32 8, i32* %120)
%122 = load i32, i32* %11
%123 = add nsw i32 %122, 4
store i32 %123, i32* %11
br label %26
124: ; preds = %26
%125 = load i32*, i32** %6
%126 = call i32 @fclose(i32* %125)
%127 = load i32*, i32** %7
%128 = call i32 @fclose(i32* %127)
%129 = load i32, i32* %11
store i32 %129, i32* %3
br label %130
130: ; preds = %124, %22, %16
%131 = load i32, i32* %3
ret i32 %131
}

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