// File: /workspace/github_cpp_makefile_star2_O1/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 0x10ff4
movq %rsi, %r13
movq (%rsi), %rbx
movq 0x8(%rbx), %r15
leaq 0x228e(%rip), %rsi      # 0x130e0
movq %r15, %rdi
callq 0x21b0
testl %eax, %eax
je 0x10ff4
movq (%rbx), %rdi
callq 0x2240
movq %rax, 0x54af(%rip)      # 0x16320
movq %r15, %rdi
callq 0x2240
movq %rax, %rbx
leaq 0x2262(%rip), %rsi      # 0x130e5
movq %rax, %rdi
callq 0x21e0
movq %rax, %r14
movq %rax, %rdi
movq %r15, %rsi
callq 0x21b0
movl %eax, -0x2c(%rbp)
testq %r14, %r14
je 0x10f53
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 0x10f5b
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 0x21f4(%rip), %rsi      # 0x130e7
xorl %eax, %eax
callq 0x2060
movq %r15, %rdi
callq 0x2240
leaq 0x5417(%rip), %rcx      # 0x16320
movq %rax, (%rcx,%rbx,8)
cmpl $0x0, -0x2c(%rbp)
je 0x10f26
xorl %edi, %edi
leaq 0x21c9(%rip), %rsi      # 0x130e5
callq 0x21e0
movq %rax, %r14
jmp 0x10f38
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 0x10f5e
cmpq $0x7ff, %rbx            # imm = 0x7FF
movq %r12, %rbx
jb 0x10ebc
jmp 0x10f5e
movl $0x5, %r12d
jmp 0x10f66
movq %rbx, %r12
movq -0x38(%rbp), %r13
movq -0x48(%rbp), %rbx
movq %rbx, %rdi
callq 0x2180
leaq 0x216b(%rip), %rdi      # 0x130e0
callq 0x2240
movq %rax, 0x53a7(%rip)      # 0x16328
leaq 0x5398(%rip), %rbx      # 0x16320
leaq 0x215d(%rip), %rdi      # 0x130ec
callq 0x2240
movq %rax, 0x5395(%rip)      # 0x16330
leal -0x4(%r12), %eax
shrl $0x1f, %eax
leal (%r12,%rax), %edx
addl $-0x4, %edx
sarl %edx
leaq 0x2134(%rip), %rsi      # 0x130e7
leaq -0x50(%rbp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2060
movq %r14, %rdi
callq 0x2240
movq %rax, 0x5368(%rip)      # 0x16338
movq 0x5351(%rip), %rdi      # 0x16328
callq 0x2240
movq %rax, 0x535d(%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