// File: jmbjorndalen[P]Malbolge-gen/interp-orig.c
// Function: main
int main( int argc, char **argv )
{
  FILE *f;
  unsigned short i = 0, j;
  int x;
  unsigned short *mem;
  if ( argc != 2 )
  {
    fputs( "invalid command line\n", stderr );
    return ( 1 );
  }
  if ( ( f = fopen( argv[1], "r" ) ) == NULL )
  {
    fputs( "can't open file\n", stderr );
    return ( 1 );
  }
#ifdef _MSC_VER
  mem = (unsigned short *)_halloc( 59049, sizeof(unsigned short) );
#else
  mem = (unsigned short *)malloc( sizeof(unsigned short) * 59049 );
#endif
  if ( mem == NULL )
  {
    fclose( f );
    fputs( "can't allocate memory\n", stderr );
    return ( 1 );
  }
  while ( ( x = getc( f ) ) != EOF )
  {
    if ( isspace( x ) ) continue;
    if ( x < 127 && x > 32 )
    {
      if ( strchr( "ji*p</vo", xlat1[( x - 33 + i ) % 94] ) == NULL )
      {
        fputs( "invalid character in source file\n", stderr );
        free( mem );
        fclose( f );
        return ( 1 );
      }
    }
    if ( i == 59049 )
    {
      fputs( "input file too long\n", stderr );
      free( mem );
      fclose( f );
      return ( 1 );
    }
    mem[i++] = x;
  }
  fclose( f );
  while ( i < 59049 ) mem[i] = op( mem[i - 1], mem[i - 2] ), i++;
  exec( mem );
  free( mem );
  // This printf added by John Markus Bj�rndalen. Output without newline tends to disappear under the shell prompt. This will prevent some 
  // confusion.
  printf("\n");  
  return ( 0 );
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movw $0x0, -0x1a(%rbp)
cmpl $0x2, -0x8(%rbp)
je 0x401744
movq $0x4c86e8, %rax         # imm = 0x4C86E8
movq (%rax), %rsi
leaq 0x96a4f(%rip), %rdi     # 0x498182
callq 0x412610
movl $0x1, -0x4(%rbp)
jmp 0x401955
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xadef4(%rip), %rsi     # 0x4af647
callq 0x412510
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0x401784
movq $0x4c86e8, %rax         # imm = 0x4C86E8
movq (%rax), %rsi
leaq 0x96a25(%rip), %rdi     # 0x498198
callq 0x412610
movl $0x1, -0x4(%rbp)
jmp 0x401955
movl $0x1cd52, %edi          # imm = 0x1CD52
callq 0x41ff60
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x4017c4
movq -0x18(%rbp), %rdi
callq 0x4120d0
movq $0x4c86e8, %rax         # imm = 0x4C86E8
movq (%rax), %rsi
leaq 0x969f6(%rip), %rdi     # 0x4981a9
callq 0x412610
movl $0x1, -0x4(%rbp)
jmp 0x401955
jmp 0x4017c6
movq -0x18(%rbp), %rdi
callq 0x4147e0
movl %eax, -0x20(%rbp)
cmpl $-0x1, %eax
je 0x4018d1
callq 0x404940
movq (%rax), %rax
movslq -0x20(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
je 0x4017f7
jmp 0x4017c6
cmpl $0x7f, -0x20(%rbp)
jge 0x40186d
cmpl $0x20, -0x20(%rbp)
jle 0x40186d
movl -0x20(%rbp), %eax
subl $0x21, %eax
movzwl -0x1a(%rbp), %ecx
addl %ecx, %eax
movl $0x5e, %ecx
cltd
idivl %ecx
movslq %edx, %rcx
leaq 0x967ef(%rip), %rax     # 0x498010
movsbl (%rax,%rcx), %esi
leaq 0x96994(%rip), %rdi     # 0x4981c0
callq 0x4010d8
cmpq $0x0, %rax
jne 0x40186b
movq $0x4c86e8, %rax         # imm = 0x4C86E8
movq (%rax), %rsi
leaq 0x96981(%rip), %rdi     # 0x4981c9
callq 0x412610
movq -0x28(%rbp), %rdi
callq 0x4202a0
movq -0x18(%rbp), %rdi
callq 0x4120d0
movl $0x1, -0x4(%rbp)
jmp 0x401955
jmp 0x40186d
movzwl -0x1a(%rbp), %eax
cmpl $0xe6a9, %eax           # imm = 0xE6A9
jne 0x4018ac
movq $0x4c86e8, %rax         # imm = 0x4C86E8
movq (%rax), %rsi
leaq 0x96962(%rip), %rdi     # 0x4981eb
callq 0x412610
movq -0x28(%rbp), %rdi
callq 0x4202a0
movq -0x18(%rbp), %rdi
callq 0x4120d0
movl $0x1, -0x4(%rbp)
jmp 0x401955
movl -0x20(%rbp), %eax
movw %ax, %dx
movq -0x28(%rbp), %rax
movw -0x1a(%rbp), %cx
movw %cx, %si
addw $0x1, %si
movw %si, -0x1a(%rbp)
movzwl %cx, %ecx
movw %dx, (%rax,%rcx,2)
jmp 0x4017c6
movq -0x18(%rbp), %rdi
callq 0x4120d0
movzwl -0x1a(%rbp), %eax
cmpl $0xe6a9, %eax           # imm = 0xE6A9
jge 0x40192e
movq -0x28(%rbp), %rax
movzwl -0x1a(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movw (%rax,%rcx,2), %dx
movq -0x28(%rbp), %rax
movzwl -0x1a(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movzwl %dx, %edi
movzwl (%rax,%rcx,2), %esi
callq 0x401960
movw %ax, %dx
movq -0x28(%rbp), %rax
movzwl -0x1a(%rbp), %ecx
movw %dx, (%rax,%rcx,2)
movw -0x1a(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x1a(%rbp)
jmp 0x4018da
movq -0x28(%rbp), %rdi
callq 0x401a20
movq -0x28(%rbp), %rdi
callq 0x4202a0
leaq 0x96e23(%rip), %rdi     # 0x49876a
movb $0x0, %al
callq 0x40bb80
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nop