#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 rom2bin(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, 8, src) == 8) {
    v[0] = (b[0] << 8) + b[1];
    v[1] = (b[2] << 8) + b[3];
    v[2] = (b[4] << 8) + b[5];
    v[3] = (b[6] << 8) + b[7];
    octets[0] = v[0] & 0xff;
    octets[1] = ((v[1] << 2) & 0xfc) + ((v[0] >> 8) & 0x03);
    octets[2] = ((v[2] << 4) & 0xf0) + ((v[1] >> 6) & 0x0f);
    octets[3] = ((v[3] << 6) & 0xc0) + ((v[2] >> 4) & 0x3f);
    octets[4] = ((v[3] >> 2) & 0xff);
    fwrite(octets, 1, 5, dest);
    n += 4;
  }
  fclose(src);
  fclose(dest);
  return (n);
}


x86 assembly (clang, -O0):
<rom2bin>:
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 <rom2bin+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b7 <rom2bin+0x177>
mov    -0x18(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11af <rom2bin+0x6f>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b7 <rom2bin+0x177>
movl   $0x0,-0x70(%rbp)
lea    -0x32(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x8,%edx
call   1030 <fread@plt>
cmp    $0x8,%eax
jne    129f <rom2bin+0x15f>
movzbl -0x32(%rbp),%eax
shl    $0x8,%eax
movzbl -0x31(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x60(%rbp)
movzbl -0x30(%rbp),%eax
shl    $0x8,%eax
movzbl -0x2f(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x5c(%rbp)
movzbl -0x2e(%rbp),%eax
shl    $0x8,%eax
movzbl -0x2d(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x58(%rbp)
movzbl -0x2c(%rbp),%eax
shl    $0x8,%eax
movzbl -0x2b(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x54(%rbp)
mov    -0x60(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x6a(%rbp)
mov    -0x5c(%rbp),%eax
shl    $0x2,%eax
and    $0xfc,%eax
mov    -0x60(%rbp),%ecx
shr    $0x8,%ecx
and    $0x3,%ecx
add    %ecx,%eax
mov    %al,-0x69(%rbp)
mov    -0x58(%rbp),%eax
shl    $0x4,%eax
and    $0xf0,%eax
mov    -0x5c(%rbp),%ecx
shr    $0x6,%ecx
and    $0xf,%ecx
add    %ecx,%eax
mov    %al,-0x68(%rbp)
mov    -0x54(%rbp),%eax
shl    $0x6,%eax
and    $0xc0,%eax
mov    -0x58(%rbp),%ecx
shr    $0x4,%ecx
and    $0x3f,%ecx
add    %ecx,%eax
mov    %al,-0x67(%rbp)
mov    -0x54(%rbp),%eax
shr    $0x2,%eax
and    $0xff,%eax
mov    %al,-0x66(%rbp)
lea    -0x6a(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x5,%edx
call   1060 <fwrite@plt>
mov    -0x70(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x70(%rbp)
jmp    11b6 <rom2bin+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):
<rom2bin>:
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     1266 <rom2bin+0x126>
mov    %rax,%r13
lea    0xe93(%rip),%rsi
mov    %rbp,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     126e <rom2bin+0x12e>
mov    %rax,%r14
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
mov    $0x8,%edx
mov    %r13,%rcx
call   1030 <fread@plt>
xor    %r15d,%r15d
cmp    $0x8,%eax
jne    125c <rom2bin+0x11c>
xor    %r15d,%r15d
lea    0x4(%rsp),%r12
nop
movzbl 0x4(%rsp),%ebx
movzbl 0x5(%rsp),%r8d
movzbl 0x6(%rsp),%edx
shl    $0x8,%edx
movzbl 0x7(%rsp),%edi
or     %edi,%edx
movzbl 0x8(%rsp),%eax
shl    $0x8,%eax
movzbl 0x9(%rsp),%esi
or     %esi,%eax
movzbl 0xa(%rsp),%ecx
shl    $0x8,%ecx
movzbl 0xb(%rsp),%ebp
or     %ebp,%ecx
mov    %r8b,0xe(%rsp)
lea    0x0(,%rdi,4),%edi
and    $0x3,%bl
or     %dil,%bl
mov    %bl,0xf(%rsp)
shl    $0x4,%esi
shr    $0x6,%edx
and    $0xf,%edx
or     %esi,%edx
mov    %dl,0x10(%rsp)
shl    $0x6,%ebp
shr    $0x4,%eax
and    $0x3f,%eax
or     %ebp,%eax
mov    %al,0x11(%rsp)
shr    $0x2,%ecx
mov    %cl,0x12(%rsp)
lea    0xe(%rsp),%rdi
mov    $0x1,%esi
mov    $0x5,%edx
mov    %r14,%rcx
call   1060 <fwrite@plt>
add    $0x4,%r15d
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x8,%edx
mov    %r13,%rcx
call   1030 <fread@plt>
cmp    $0x8,%eax
je     11b0 <rom2bin+0x70>
mov    %r13,%rdi
call   1040 <fclose@plt>
jmp    1277 <rom2bin+0x137>
mov    $0xffffffff,%r15d
jmp    127f <rom2bin+0x13f>
mov    $0xffffffff,%r15d
mov    %r13,%r14
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r15d,%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 @rom2bin(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 %123
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 %123
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 8, i32* %28)
%30 = icmp eq i32 %29, 8
br i1 %30, label %31, label %117
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 = shl i32 %34, 8
%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 = add nsw i32 %35, %38
%40 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 0
store i32 %39, i32* %40
%41 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 2
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = shl i32 %43, 8
%45 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 3
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = add nsw i32 %44, %47
%49 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 1
store i32 %48, i32* %49
%50 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 4
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = shl i32 %52, 8
%54 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 5
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = add nsw i32 %53, %56
%58 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 2
store i32 %57, i32* %58
%59 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 6
%60 = load i8, i8* %59
%61 = zext i8 %60 to i32
%62 = shl i32 %61, 8
%63 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 7
%64 = load i8, i8* %63
%65 = zext i8 %64 to i32
%66 = add nsw i32 %62, %65
%67 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 3
store i32 %66, i32* %67
%68 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 0
%69 = load i32, i32* %68
%70 = and i32 %69, 255
%71 = trunc i32 %70 to i8
%72 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
store i8 %71, i8* %72
%73 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 1
%74 = load i32, i32* %73
%75 = shl i32 %74, 2
%76 = and i32 %75, 252
%77 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 0
%78 = load i32, i32* %77
%79 = lshr i32 %78, 8
%80 = and i32 %79, 3
%81 = add i32 %76, %80
%82 = trunc i32 %81 to i8
%83 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 1
store i8 %82, i8* %83
%84 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 2
%85 = load i32, i32* %84
%86 = shl i32 %85, 4
%87 = and i32 %86, 240
%88 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 1
%89 = load i32, i32* %88
%90 = lshr i32 %89, 6
%91 = and i32 %90, 15
%92 = add i32 %87, %91
%93 = trunc i32 %92 to i8
%94 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 2
store i8 %93, i8* %94
%95 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 3
%96 = load i32, i32* %95
%97 = shl i32 %96, 6
%98 = and i32 %97, 192
%99 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 2
%100 = load i32, i32* %99
%101 = lshr i32 %100, 4
%102 = and i32 %101, 63
%103 = add i32 %98, %102
%104 = trunc i32 %103 to i8
%105 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 3
store i8 %104, i8* %105
%106 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 3
%107 = load i32, i32* %106
%108 = lshr i32 %107, 2
%109 = and i32 %108, 255
%110 = trunc i32 %109 to i8
%111 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 4
store i8 %110, i8* %111
%112 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
%113 = load i32*, i32** %7
%114 = call i32 @fwrite(i8* %112, i32 1, i32 5, i32* %113)
%115 = load i32, i32* %11
%116 = add nsw i32 %115, 4
store i32 %116, i32* %11
br label %26
117: ; preds = %26
%118 = load i32*, i32** %6
%119 = call i32 @fclose(i32* %118)
%120 = load i32*, i32** %7
%121 = call i32 @fclose(i32* %120)
%122 = load i32, i32* %11
store i32 %122, i32* %3
br label %123
123: ; preds = %117, %22, %16
%124 = load i32, i32* %3
ret i32 %124
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
define i32 @rom2bin(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 %75, 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 %71, label %12
12: ; preds = %9
%13 = call i32 @fread(i8* %5, i32 1, i32 8, i32* %7)
%14 = icmp eq i32 %13, 8
br i1 %14, label %15, label %68
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]* %3, i64 0, i64 5
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 6
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 7
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 1
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 2
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 3
%26 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 4
br label %27
27: ; preds = %15, %27
%28 = phi i32 [ 0, %15 ], [ %65, %27 ]
%29 = load i8, i8* %5
%30 = load i8, i8* %16
%31 = load i8, i8* %17
%32 = zext i8 %31 to i32
%33 = shl nuw nsw i32 %32, 8
%34 = load i8, i8* %18
%35 = zext i8 %34 to i32
%36 = or i32 %33, %35
%37 = load i8, i8* %19
%38 = zext i8 %37 to i32
%39 = shl nuw nsw i32 %38, 8
%40 = load i8, i8* %20
%41 = zext i8 %40 to i32
%42 = or i32 %39, %41
%43 = load i8, i8* %21
%44 = zext i8 %43 to i32
%45 = shl nuw nsw i32 %44, 8
%46 = load i8, i8* %22
%47 = zext i8 %46 to i32
%48 = or i32 %45, %47
store i8 %30, i8* %6
%49 = shl i8 %34, 2
%50 = and i8 %29, 3
%51 = or i8 %49, %50
store i8 %51, i8* %23
%52 = shl nuw nsw i32 %41, 4
%53 = lshr i32 %36, 6
%54 = and i32 %53, 15
%55 = or i32 %52, %54
%56 = trunc i32 %55 to i8
store i8 %56, i8* %24
%57 = shl nuw nsw i32 %47, 6
%58 = lshr i32 %42, 4
%59 = and i32 %58, 63
%60 = or i32 %57, %59
%61 = trunc i32 %60 to i8
store i8 %61, i8* %25
%62 = lshr i32 %48, 2
%63 = trunc i32 %62 to i8
store i8 %63, i8* %26
%64 = call i32 @fwrite(i8* %6, i32 1, i32 5, i32* %10)
%65 = add nuw nsw i32 %28, 4
%66 = call i32 @fread(i8* %5, i32 1, i32 8, i32* %7)
%67 = icmp eq i32 %66, 8
br i1 %67, label %27, label %68
68: ; preds = %27, %12
%69 = phi i32 [ 0, %12 ], [ %65, %27 ]
%70 = tail call i32 @fclose(i32* %7)
br label %71
71: ; preds = %9, %68
%72 = phi i32* [ %10, %68 ], [ %7, %9 ]
%73 = phi i32 [ %69, %68 ], [ -1, %9 ]
%74 = tail call i32 @fclose(i32* %72)
br label %75
75: ; preds = %71, %2
%76 = phi i32 [ -1, %2 ], [ %73, %71 ]
ret i32 %76
}