// File: probonopd[P]decodeir/DecodeIR.cpp
// Function: main
int main(int argc, char* argv[]) 
{
  unsigned int i = 1; 
  int type; 

  raw_to_pronto(&argc, &argv);
  sscanf(argv[i++], "%x", &type); 
  if (type != 0) 
{
    std::cerr << "Can only handle type 0000\n"; 
    exit(1); 
    }
  int fcode; 
  sscanf(argv[i++], "%x", &fcode); 
  int frequency = (int) (1000000.0/((double)fcode * 0.241246)); 
  int intro_length, rep_length; 
  sscanf(argv[i++], "%x", &intro_length); 
  sscanf(argv[i++], "%x", &rep_length); 

  int *data = new int[2*(intro_length+rep_length)]; 
  for (int j = 0; j < 2*(intro_length+rep_length); j++) 
    {
    int ncycles; 
    sscanf(argv[i++], "%x", &ncycles); 
    data[j] = (int)(1000000.0/frequency*ncycles); 
    }
  unsigned int decodeir_context[2] = { 0, 0}; 
  char protocol[255] = ""; 
  int device = -1; 
  int subdevice = -1; 
  int obc = -1; 
  int hex[4] = { -1, -1, -1, -1}; 
  char misc_message[255] = ""; 
  char error_message[255] = ""; 
    
  do 
    {
    DecodeIR(decodeir_context, data, frequency, intro_length, rep_length, 
           protocol, &device, &subdevice, &obc, hex, misc_message, 
           error_message); 

    if (protocol[0] != '\0') 
      std::cout 
      << "protocol=" << protocol 
      << " device=" << device 
      << " subdevice=" << subdevice 
      << " obc=" << obc 
      << " hex0=" << hex[0] 
      << " hex1=" << hex[1] 
      << " hex2=" << hex[2] 
      << " hex3=" << hex[3] 
      << " misc=" << misc_message 
      << " error=" << error_message << "\n"; 
    }
  while (protocol[0] != '\0'); 
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x398, %rsp            # imm = 0x398
movl $0x0, -0x1c(%rbp)
movl %edi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movl $0x1, -0x2c(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x17ad0
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movl %ecx, %ecx
movq (%rax,%rcx,8), %rdi
leaq 0x34c8(%rip), %rsi      # 0x1b216
leaq -0x30(%rbp), %rdx
movb $0x0, %al
callq 0x2130
cmpl $0x0, -0x30(%rbp)
je 0x17d7c
movq 0x7282(%rip), %rdi      # 0x1efe8
leaq 0x34ac(%rip), %rsi      # 0x1b219
callq 0x2140
movl $0x1, %edi
callq 0x21a0
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movl %ecx, %ecx
movq (%rax,%rcx,8), %rdi
leaq 0x347e(%rip), %rsi      # 0x1b216
leaq -0x34(%rbp), %rdx
movb $0x0, %al
callq 0x2130
cvtsi2sdl -0x34(%rbp), %xmm1
movsd 0x29b8(%rip), %xmm0     # 0x1a768
mulsd %xmm0, %xmm1
movsd 0x2984(%rip), %xmm0     # 0x1a740
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movl %ecx, %ecx
movq (%rax,%rcx,8), %rdi
leaq 0x3433(%rip), %rsi      # 0x1b216
leaq -0x3c(%rbp), %rdx
movb $0x0, %al
callq 0x2130
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movl %ecx, %ecx
movq (%rax,%rcx,8), %rdi
leaq 0x340c(%rip), %rsi      # 0x1b216
leaq -0x40(%rbp), %rdx
movb $0x0, %al
callq 0x2130
movl -0x3c(%rbp), %eax
addl -0x40(%rbp), %eax
shll %eax
cltq
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl -0x3c(%rbp), %ecx
addl -0x40(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
jge 0x17eb5
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movl %ecx, %ecx
movq (%rax,%rcx,8), %rdi
leaq 0x33a0(%rip), %rsi      # 0x1b216
leaq -0x50(%rbp), %rdx
movb $0x0, %al
callq 0x2130
cvtsi2sdl -0x38(%rbp), %xmm1
movsd 0x28b2(%rip), %xmm0     # 0x1a740
divsd %xmm1, %xmm0
cvtsi2sdl -0x50(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
movq -0x48(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x17e4b
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x20c0
leaq -0x160(%rbp), %rdi
xorl %esi, %esi
movl $0xff, %edx
callq 0x20c0
movl $0xffffffff, -0x164(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x168(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x16c(%rbp) # imm = 0xFFFFFFFF
movq 0x3393(%rip), %rax      # 0x1b290
movq %rax, -0x180(%rbp)
movq 0x338d(%rip), %rax      # 0x1b298
movq %rax, -0x178(%rbp)
leaq -0x280(%rbp), %rdi
xorl %esi, %esi
movl $0xff, %edx
callq 0x20c0
leaq -0x380(%rbp), %rdi
xorl %esi, %esi
movl $0xff, %edx
callq 0x20c0
leaq -0x58(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl -0x38(%rbp), %edx
movl -0x3c(%rbp), %ecx
movl -0x40(%rbp), %r8d
leaq -0x160(%rbp), %r9
leaq -0x180(%rbp), %r11
leaq -0x280(%rbp), %r10
leaq -0x380(%rbp), %rax
leaq -0x164(%rbp), %r15
leaq -0x168(%rbp), %r14
leaq -0x16c(%rbp), %rbx
movq %r15, (%rsp)
movq %r14, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movq %rax, 0x28(%rsp)
callq 0x17980
movsbl -0x160(%rbp), %eax
cmpl $0x0, %eax
je 0x180e5
movq 0x7014(%rip), %rdi      # 0x1efc8
leaq 0x3279(%rip), %rsi      # 0x1b234
callq 0x2140
movq %rax, %rdi
leaq -0x160(%rbp), %rsi
callq 0x2140
movq %rax, %rdi
leaq 0x3265(%rip), %rsi      # 0x1b23e
callq 0x2140
movq %rax, %rdi
movl -0x164(%rbp), %esi
callq 0x2210
movq %rax, %rdi
leaq 0x3251(%rip), %rsi      # 0x1b247
callq 0x2140
movq %rax, %rdi
movl -0x168(%rbp), %esi
callq 0x2210
movq %rax, %rdi
leaq 0x3240(%rip), %rsi      # 0x1b253
callq 0x2140
movq %rax, %rdi
movl -0x16c(%rbp), %esi
callq 0x2210
movq %rax, %rdi
leaq 0x3229(%rip), %rsi      # 0x1b259
callq 0x2140
movq %rax, %rdi
movl -0x180(%rbp), %esi
callq 0x2210
movq %rax, %rdi
leaq 0x3213(%rip), %rsi      # 0x1b260
callq 0x2140
movq %rax, %rdi
movl -0x17c(%rbp), %esi
callq 0x2210
movq %rax, %rdi
leaq 0x31fd(%rip), %rsi      # 0x1b267
callq 0x2140
movq %rax, %rdi
movl -0x178(%rbp), %esi
callq 0x2210
movq %rax, %rdi
leaq 0x31e7(%rip), %rsi      # 0x1b26e
callq 0x2140
movq %rax, %rdi
movl -0x174(%rbp), %esi
callq 0x2210
movq %rax, %rdi
leaq 0x31d1(%rip), %rsi      # 0x1b275
callq 0x2140
movq %rax, %rdi
leaq -0x280(%rbp), %rsi
callq 0x2140
movq %rax, %rdi
leaq 0x31ba(%rip), %rsi      # 0x1b27c
callq 0x2140
movq %rax, %rdi
leaq -0x380(%rbp), %rsi
callq 0x2140
movq %rax, %rdi
leaq 0x3152(%rip), %rsi      # 0x1b232
callq 0x2140
jmp 0x180e7
movsbl -0x160(%rbp), %eax
cmpl $0x0, %eax
jne 0x17f38
movl -0x1c(%rbp), %eax
addq $0x398, %rsp            # imm = 0x398
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax,%rax)