#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int a2rom(char *f1, char *f2) {
  FILE *src;
  FILE *dest;
  char ligne[80];
  unsigned char buf[4];
  int i, n;
  src = fopen(f1, "rt");
  if (src == NULL)
    return (-1);
  dest = fopen(f2, "wb");
  if (dest == NULL)
    return (-1);
  i = 0;
  do {
    if (fgets(ligne, 80, src) == NULL)
      break;
    if (ligne[0] == 0)
      break;
    n = ligne[10];
    ligne[10] = ligne[12];
    ligne[12] = n;
    sscanf(&ligne[10], "%x", &n);
    buf[0] = n >> 8;
    buf[1] = n;
    fwrite(buf, 1, 2, dest);
    i++;
    if (i == 4096)
      break;
  } while (1);
  fclose(dest);
  fclose(src);
}


x86 assembly (clang, -O0):
<a2rom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118e <a2rom+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a9 <a2rom+0x159>
mov    -0x18(%rbp),%rdi
lea    0xe6a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b9 <a2rom+0x69>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a9 <a2rom+0x159>
movl   $0x0,-0x88(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x50,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    11e4 <a2rom+0x94>
jmp    1297 <a2rom+0x147>
movsbl -0x80(%rbp),%eax
cmp    $0x0,%eax
jne    11f6 <a2rom+0xa6>
jmp    1297 <a2rom+0x147>
movsbl -0x76(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x74(%rbp),%al
mov    %al,-0x76(%rbp)
mov    -0x8c(%rbp),%eax
mov    %al,-0x74(%rbp)
lea    -0x80(%rbp),%rdi
add    $0xa,%rdi
lea    0xde8(%rip),%rsi
lea    -0x8c(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x8c(%rbp),%eax
sar    $0x8,%eax
mov    %al,-0x84(%rbp)
mov    -0x8c(%rbp),%eax
mov    %al,-0x83(%rbp)
lea    -0x84(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2,%edx
call   1070 <fwrite@plt>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
cmpl   $0x1000,-0x88(%rbp)
jne    1283 <a2rom+0x133>
jmp    1297 <a2rom+0x147>
jmp    1288 <a2rom+0x138>
mov    $0x1,%al
test   $0x1,%al
jne    11c3 <a2rom+0x73>
jmp    1297 <a2rom+0x147>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<a2rom>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%rbx
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     122f <a2rom+0xdf>
mov    %rax,%r14
lea    0xe83(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     122f <a2rom+0xdf>
mov    %rax,%rbx
mov    $0x1000,%r13d
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%rbp
lea    0xc(%rsp),%r15
nopl   0x0(%rax)
mov    %r12,%rdi
mov    $0x50,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     121f <a2rom+0xcf>
cmpb   $0x0,0x10(%rsp)
je     121f <a2rom+0xcf>
movsbl 0x1a(%rsp),%eax
mov    %eax,0x8(%rsp)
movzbl 0x1c(%rsp),%ecx
mov    %cl,0x1a(%rsp)
mov    %al,0x1c(%rsp)
lea    0x1a(%rsp),%rdi
lea    0xe18(%rip),%rsi
mov    %rbp,%rdx
call   1050 <sscanf@plt>
movzwl 0x8(%rsp),%eax
rol    $0x8,%ax
mov    %ax,0xc(%rsp)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x2,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
add    $0xffffffff,%r13d
jne    11b0 <a2rom+0x60>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rt\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [3 x i8] c"%x\00"
define i32 @a2rom(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [80 x i8]
%9 = alloca [4 x i8]
%10 = alloca i32
%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 %70
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 %23
22: ; preds = %17
store i32 -1, i32* %3
br label %70
23: ; preds = %17
store i32 0, i32* %10
br label %24
24: ; preds = %64, %23
%25 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%26 = load i32*, i32** %6
%27 = call i32* @fgets(i8* %25, i32 80, i32* %26)
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %30
29: ; preds = %24
br label %65
30: ; preds = %24
%31 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %30
br label %65
36: ; preds = %30
%37 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 10
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
store i32 %39, i32* %11
%40 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 12
%41 = load i8, i8* %40
%42 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 10
store i8 %41, i8* %42
%43 = load i32, i32* %11
%44 = trunc i32 %43 to i8
%45 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 12
store i8 %44, i8* %45
%46 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 10
%47 = call i32 @sscanf(i8* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %11)
%48 = load i32, i32* %11
%49 = ashr i32 %48, 8
%50 = trunc i32 %49 to i8
%51 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
store i8 %50, i8* %51
%52 = load i32, i32* %11
%53 = trunc i32 %52 to i8
%54 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 1
store i8 %53, i8* %54
%55 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%56 = load i32*, i32** %7
%57 = call i32 @fwrite(i8* %55, i32 1, i32 2, i32* %56)
%58 = load i32, i32* %10
%59 = add nsw i32 %58, 1
store i32 %59, i32* %10
%60 = load i32, i32* %10
%61 = icmp eq i32 %60, 4096
br i1 %61, label %62, label %63
62: ; preds = %36
br label %65
63: ; preds = %36
br label %64
64: ; preds = %63
br i1 true, label %24, label %65
65: ; preds = %64, %62, %35, %29
%66 = load i32*, i32** %7
%67 = call i32 @fclose(i32* %66)
%68 = load i32*, i32** %6
%69 = call i32 @fclose(i32* %68)
br label %70
70: ; preds = %65, %22, %16
%71 = load i32, i32* %3
ret i32 %71
}

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