#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 GetInstrCode(char *);
int /*<<< orphan*/ TransToCode(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, char *);
char *strchr(char *, char);
int main(int argc, char **argv) {
  char a_line[80];
  char op_sym[8];
  int op_num;
  char *pcPos;
  FILE *pfIn, *pfOut;
  int n;
  if (argc < 3) {
    printf("ERROR:no enough command line arguments!\n");
    return 0;
  }
  if ((pfIn = fopen(argv[1], "r")) == NULL) {
    printf("ERROR:cannot open file %s for reading!\n", argv[1]);
    return 0;
  }
  if ((pfOut = fopen(argv[2], "w")) == NULL) {
    printf("ERROR:cannot open file %s for writing!\n", argv[2]);
    return 0;
  }
  while (!feof(pfIn)) {
    fgets(a_line, 80, pfIn);
    if ((pcPos = strchr(a_line, '#')) != NULL) {
      *pcPos = '\0';
    }
    n = sscanf(a_line, "%s", op_sym);
    if (n < 1) {
      continue;
    }
    op_num = GetInstrCode(op_sym);
    if (op_num > 15) {
      printf("ERROR: %s is a invalid instruction! \n", a_line);
      exit(-1);
    }
    fprintf(pfOut, "0x%08lx\n", TransToCode(a_line, op_num));
  }
  fclose(pfIn);
  fclose(pfOut);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11ed <main+0x3d>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    137e <main+0x1ce>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2d(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x80(%rbp)
cmp    $0x0,%rax
jne    1231 <main+0x81>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    137e <main+0x1ce>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe13(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x88(%rbp)
cmp    $0x0,%rax
jne    1278 <main+0xc8>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    137e <main+0x1ce>
jmp    127d <main+0xcd>
mov    -0x80(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    129b <main+0xeb>
jmp    1362 <main+0x1b2>
lea    -0x60(%rbp),%rdi
mov    -0x80(%rbp),%rdx
mov    $0x50,%esi
call   1060 <fgets@plt>
lea    -0x60(%rbp),%rdi
mov    $0x23,%esi
call   1040 <strchr@plt>
mov    %rax,-0x78(%rbp)
cmp    $0x0,%rax
je     12d0 <main+0x120>
mov    -0x78(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x60(%rbp),%rdi
lea    -0x68(%rbp),%rdx
lea    0xd9e(%rip),%rsi
call   10a0 <sscanf@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x1,-0x8c(%rbp)
jge    12fc <main+0x14c>
jmp    127d <main+0xcd>
lea    -0x68(%rbp),%rdi
call   10c0 <GetInstrCode@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0xf,-0x6c(%rbp)
jle    132e <main+0x17e>
lea    -0x60(%rbp),%rsi
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x88(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x6c(%rbp),%esi
call   1070 <TransToCode@plt>
mov    -0x98(%rbp),%rdi
mov    %eax,%edx
lea    0xd4e(%rip),%rsi
call   1080 <fprintf@plt>
jmp    127d <main+0xcd>
mov    -0x80(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x88(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
cmp    $0x2,%edi
jg     11e3 <main+0x23>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
jmp    125a <main+0x9a>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xe0f(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1239 <main+0x79>
mov    %rax,%rbx
mov    0x10(%rbp),%rdi
lea    0xe21(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1246 <main+0x86>
mov    %rax,%r14
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
je     126b <main+0xab>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    $0x1,%ebx
jmp    125a <main+0x9a>
mov    0x8(%rbp),%rsi
lea    0xdbe(%rip),%rdi
jmp    1251 <main+0x91>
mov    0x10(%rbp),%rsi
lea    0xddb(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(%rsp),%r15
lea    0xddd(%rip),%r12
lea    0x8(%rsp),%r13
lea    0xdfa(%rip),%rbp
jmp    12b7 <main+0xf7>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    %eax,%esi
call   1080 <TransToCode@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1090 <fprintf@plt>
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    1222 <main+0x62>
mov    %r15,%rdi
mov    $0x50,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
mov    %r15,%rdi
mov    $0x23,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     12dc <main+0x11c>
movb   $0x0,(%rax)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   10b0 <sscanf@plt>
test   %eax,%eax
jle    12a7 <main+0xe7>
mov    %r13,%rdi
call   10d0 <GetInstrCode@plt>
cmp    $0x10,%eax
jl     1290 <main+0xd0>
lea    0xd55(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [41 x i8] c"ERROR:no enough command line arguments!\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [40 x i8] c"ERROR:cannot open file %s for reading!\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [40 x i8] c"ERROR:cannot open file %s for writing!\0A\00"
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [38 x i8] c"ERROR: %s is a invalid instruction! \0A\00"
@.str.7 = [9 x i8] c"0x%08lx\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [80 x i8]
%7 = alloca [8 x i8]
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 3
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %81
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %10
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %28
23: ; preds = %17
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %26)
store i32 0, i32* %3
br label %81
28: ; preds = %17
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %32, i32** %11
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %39
34: ; preds = %28
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %37)
store i32 0, i32* %3
br label %81
39: ; preds = %28
br label %40
40: ; preds = %70, %60, %39
%41 = load i32*, i32** %10
%42 = call i32 @feof(i32* %41)
%43 = icmp ne i32 %42, 0
%44 = xor i1 %43, true
br i1 %44, label %45, label %76
45: ; preds = %40
%46 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%47 = load i32*, i32** %10
%48 = call i32 @fgets(i8* %46, i32 80, i32* %47)
%49 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%50 = call i8* @strchr(i8* %49, i8 signext 35)
store i8* %50, i8** %9
%51 = icmp ne i8* %50, null
br i1 %51, label %52, label %54
52: ; preds = %45
%53 = load i8*, i8** %9
store i8 0, i8* %53
br label %54
54: ; preds = %52, %45
%55 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%56 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%57 = call i32 @sscanf(i8* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %56)
store i32 %57, i32* %12
%58 = load i32, i32* %12
%59 = icmp slt i32 %58, 1
br i1 %59, label %60, label %61
60: ; preds = %54
br label %40
61: ; preds = %54
%62 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%63 = call i32 @GetInstrCode(i8* %62)
store i32 %63, i32* %8
%64 = load i32, i32* %8
%65 = icmp sgt i32 %64, 15
br i1 %65, label %66, label %70
66: ; preds = %61
%67 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i8* %67)
%69 = call i32 @exit(i32 -1)
unreachable
70: ; preds = %61
%71 = load i32*, i32** %11
%72 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%73 = load i32, i32* %8
%74 = call i32 @TransToCode(i8* %72, i32 %73)
%75 = call i32 @fprintf(i32* %71, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %74)
br label %40
76: ; preds = %40
%77 = load i32*, i32** %10
%78 = call i32 @fclose(i32* %77)
%79 = load i32*, i32** %11
%80 = call i32 @fclose(i32* %79)
store i32 1, i32* %3
br label %81
81: ; preds = %76, %34, %23, %15
%82 = load i32, i32* %3
ret i32 %82
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [40 x i8] c"ERROR:cannot open file %s for reading!\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [40 x i8] c"ERROR:cannot open file %s for writing!\0A\00"
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [38 x i8] c"ERROR: %s is a invalid instruction! \0A\00"
@.str.7 = [9 x i8] c"0x%08lx\0A\00"
@str = [40 x i8] c"ERROR:no enough command line arguments!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [80 x i8]
%4 = alloca [8 x i8]
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 3
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
br label %52
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i8*, i8** %11
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %52
18: ; preds = %10
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %26, label %23
23: ; preds = %18
%24 = call i32 @feof(i32* %13)
%25 = icmp eq i32 %24, 0
br i1 %25, label %29, label %49
26: ; preds = %18
%27 = load i8*, i8** %19
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %27)
br label %52
29: ; preds = %23, %46
%30 = call i32 @fgets(i8* %5, i32 80, i32* %13)
%31 = call i8* @strchr(i8* %5, i8 signext 35)
%32 = icmp eq i8* %31, null
br i1 %32, label %34, label %33
33: ; preds = %29
store i8 0, i8* %31
br label %34
34: ; preds = %33, %29
%35 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %6)
%36 = icmp slt i32 %35, 1
br i1 %36, label %46, label %37
37: ; preds = %34
%38 = call i32 @GetInstrCode(i8* %6)
%39 = icmp sgt i32 %38, 15
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i8* %5)
%42 = call i32 @exit(i32 -1)
unreachable
43: ; preds = %37
%44 = call i32 @TransToCode(i8* %5, i32 %38)
%45 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %43, %34
%47 = call i32 @feof(i32* %13)
%48 = icmp eq i32 %47, 0
br i1 %48, label %29, label %49
49: ; preds = %46, %23
%50 = call i32 @fclose(i32* %13)
%51 = call i32 @fclose(i32* %21)
br label %52
52: ; preds = %49, %26, %15, %8
%53 = phi i32 [ 0, %8 ], [ 0, %15 ], [ 0, %26 ], [ 1, %49 ]
ret i32 %53
}