// File: /workspace/github_cpp_makefile_star2_O3/probonopd[P]decodeir/DecodeIR.cpp
// Function: raw_to_pronto(int*, char***)
int raw_to_pronto(int* argcp, char** argvp[]) {
  if (*argcp<2)
    return 0;

  char *p1 = (*argvp)[1];
  if (strcmp(p1,"0000")==0)
    return 0;

  const int max_size = 2048;
  static char* argv[max_size];
  argv[0] = strdup((*argvp)[0]);

  char *st = strdup(p1);
  char *ch = strtok(st, ",");
  int comma_separated = strcmp(ch,p1)!=0;

  char buf[8];
  int size = 5;

  for (int i=1; ch && size<max_size && i<(*argcp)+1;) {
    int value = abs(atoi(ch));
    sprintf(buf,"%04X", value*38000/1000000);
    argv[size++] = strdup(buf);
    ch = comma_separated ? strtok(NULL, ",") : (*argvp)[++i];
  }

  free(st);

  argv[1] = strdup("0000");
  argv[2] = strdup("006D");
  sprintf(buf,"%04X", (size-4)/2);
  argv[3] = strdup(buf);
  argv[4] = strdup(argv[1]);

  *argvp = argv;
  *argcp = size;

  return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
xorl %r14d, %r14d
movq %rdi, -0x40(%rbp)
cmpl $0x2, (%rdi)
jl 0x10e38
movq %rsi, %r13
movq (%rsi), %rbx
movq 0x8(%rbx), %r15
leaq 0x2441(%rip), %rsi      # 0x130d7
movq %r15, %rdi
callq 0x21b0
testl %eax, %eax
je 0x10e38
movq (%rbx), %rdi
callq 0x2240
movq %rax, 0x566b(%rip)      # 0x16320
movq %r15, %rdi
callq 0x2240
movq %rax, %rbx
leaq 0x2415(%rip), %rsi      # 0x130dc
movq %rax, %rdi
callq 0x21e0
movq %rax, %r14
movq %rax, %rdi
movq %r15, %rsi
callq 0x21b0
movl %eax, -0x2c(%rbp)
testq %r14, %r14
je 0x10d97
movq %rbx, -0x48(%rbp)
movq %r13, -0x38(%rbp)
movl $0x1, %r13d
movl $0x5, %ebx
leaq -0x50(%rbp), %r15
movq -0x40(%rbp), %rax
cmpl (%rax), %r13d
jg 0x10d9f
movq %r14, %rdi
callq 0x21d0
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
imull $0x9470, %ecx, %eax     # imm = 0x9470
imulq $0x431bde83, %rax, %rdx # imm = 0x431BDE83
shrq $0x32, %rdx
movq %r15, %rdi
leaq 0x23a7(%rip), %rsi      # 0x130de
xorl %eax, %eax
callq 0x2060
movq %r15, %rdi
callq 0x2240
leaq 0x55d3(%rip), %rcx      # 0x16320
movq %rax, (%rcx,%rbx,8)
cmpl $0x0, -0x2c(%rbp)
je 0x10d6a
xorl %edi, %edi
leaq 0x237c(%rip), %rsi      # 0x130dc
callq 0x21e0
movq %rax, %r14
jmp 0x10d7c
movq -0x38(%rbp), %rax
movq (%rax), %rax
movslq %r13d, %rcx
incl %r13d
movq 0x8(%rax,%rcx,8), %r14
leaq 0x1(%rbx), %r12
testq %r14, %r14
je 0x10da2
cmpq $0x7ff, %rbx            # imm = 0x7FF
movq %r12, %rbx
jb 0x10d00
jmp 0x10da2
movl $0x5, %r12d
jmp 0x10daa
movq %rbx, %r12
movq -0x38(%rbp), %r13
movq -0x48(%rbp), %rbx
movq %rbx, %rdi
callq 0x2180
leaq 0x231e(%rip), %rdi      # 0x130d7
callq 0x2240
movq %rax, 0x5563(%rip)      # 0x16328
leaq 0x5554(%rip), %rbx      # 0x16320
leaq 0x2310(%rip), %rdi      # 0x130e3
callq 0x2240
movq %rax, 0x5551(%rip)      # 0x16330
leal -0x4(%r12), %eax
shrl $0x1f, %eax
leal (%r12,%rax), %edx
addl $-0x4, %edx
sarl %edx
leaq 0x22e7(%rip), %rsi      # 0x130de
leaq -0x50(%rbp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2060
movq %r14, %rdi
callq 0x2240
movq %rax, 0x5524(%rip)      # 0x16338
movq 0x550d(%rip), %rdi      # 0x16328
callq 0x2240
movq %rax, 0x5519(%rip)      # 0x16340
movq %rbx, (%r13)
movq -0x40(%rbp), %rax
movl %r12d, (%rax)
movl $0x1, %r14d
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq