// File: matthewarcus[P]mmps/image.cpp
// Function: Rgb::Rgb(char const*)
Rgb::Rgb(const char *s)
{
  int r_,g_,b_;
  if (sscanf(s,"%d:%d:%d",&r_,&g_,&b_) == 3){
    r = r_;
    g = g_;
    b = b_;
    // Should use a lookup table here really.
  } else {
    const char *p = s;
    const char *d = "dark";
    bool dark = false;
    if (memcmp(p,d,strlen(d)) == 0) {
      p += strlen(d);
      dark = true;
    }
    if (strcmp(p,"black") == 0) *this = black;
    else if (strcmp(p,"white") == 0) *this = white;
    else if (strcmp(p,"red") == 0) *this = red;
    else if (strcmp(p,"green") == 0) *this = green;
    else if (strcmp(p,"blue") == 0) *this = blue;
    else if (strcmp(p,"cyan") == 0) *this = cyan;
    else if (strcmp(p,"magenta") == 0) *this = magenta;
    else if (strcmp(p,"yellow") == 0) *this = yellow;
    else if (strcmp(p,"orange") == 0) *this = orange;
    else fprintf(stderr,"Invalid color specification: %s\n",s);
    if (dark) {
      double f = 0.6;
      r = (unsigned char)(r * f);
      g = (unsigned char)(g * f);
      b = (unsigned char)(b * f);
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x2f05(%rip), %rsi      # 0x15958
leaq -0x14(%rbp), %rdx
leaq -0x18(%rbp), %rcx
leaq -0x1c(%rbp), %r8
movb $0x0, %al
callq 0x5290
cmpl $0x3, %eax
jne 0x12a85
movq -0x48(%rbp), %rax
movl -0x14(%rbp), %ecx
movb %cl, (%rax)
movl -0x18(%rbp), %ecx
movb %cl, 0x1(%rax)
movl -0x1c(%rbp), %ecx
movb %cl, 0x2(%rax)
jmp 0x12d1b
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
leaq 0x2ecd(%rip), %rax      # 0x15961
movq %rax, -0x30(%rbp)
movb $0x0, -0x31(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rdi
callq 0x5100
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq %rax, %rdx
callq 0x5110
cmpl $0x0, %eax
jne 0x12adf
movq -0x30(%rbp), %rdi
callq 0x5100
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movb $0x1, -0x31(%rbp)
movq -0x28(%rbp), %rdi
leaq 0x2e7c(%rip), %rsi      # 0x15966
callq 0x5350
cmpl $0x0, %eax
jne 0x12b10
movq -0x48(%rbp), %rax
movw 0xa829(%rip), %cx       # 0x1d328
movw %cx, (%rax)
movb 0xa822(%rip), %cl       # 0x1d32a
movb %cl, 0x2(%rax)
jmp 0x12cbb
movq -0x28(%rbp), %rdi
leaq 0x2e51(%rip), %rsi      # 0x1596c
callq 0x5350
cmpl $0x0, %eax
jne 0x12b41
movq -0x48(%rbp), %rax
movw 0xa7fb(%rip), %cx       # 0x1d32b
movw %cx, (%rax)
movb 0xa7f4(%rip), %cl       # 0x1d32d
movb %cl, 0x2(%rax)
jmp 0x12cb9
movq -0x28(%rbp), %rdi
leaq 0x2e26(%rip), %rsi      # 0x15972
callq 0x5350
cmpl $0x0, %eax
jne 0x12b72
movq -0x48(%rbp), %rax
movw 0xa7cd(%rip), %cx       # 0x1d32e
movw %cx, (%rax)
movb 0xa7c6(%rip), %cl       # 0x1d330
movb %cl, 0x2(%rax)
jmp 0x12cb7
movq -0x28(%rbp), %rdi
leaq 0x2df9(%rip), %rsi      # 0x15976
callq 0x5350
cmpl $0x0, %eax
jne 0x12ba3
movq -0x48(%rbp), %rax
movw 0xa79f(%rip), %cx       # 0x1d331
movw %cx, (%rax)
movb 0xa798(%rip), %cl       # 0x1d333
movb %cl, 0x2(%rax)
jmp 0x12cb5
movq -0x28(%rbp), %rdi
leaq 0x2dce(%rip), %rsi      # 0x1597c
callq 0x5350
cmpl $0x0, %eax
jne 0x12bd4
movq -0x48(%rbp), %rax
movw 0xa771(%rip), %cx       # 0x1d334
movw %cx, (%rax)
movb 0xa76a(%rip), %cl       # 0x1d336
movb %cl, 0x2(%rax)
jmp 0x12cb3
movq -0x28(%rbp), %rdi
leaq 0x2da2(%rip), %rsi      # 0x15981
callq 0x5350
cmpl $0x0, %eax
jne 0x12c05
movq -0x48(%rbp), %rax
movw 0xa743(%rip), %cx       # 0x1d337
movw %cx, (%rax)
movb 0xa73c(%rip), %cl       # 0x1d339
movb %cl, 0x2(%rax)
jmp 0x12cb1
movq -0x28(%rbp), %rdi
leaq 0x2d76(%rip), %rsi      # 0x15986
callq 0x5350
cmpl $0x0, %eax
jne 0x12c33
movq -0x48(%rbp), %rax
movw 0xa715(%rip), %cx       # 0x1d33a
movw %cx, (%rax)
movb 0xa70e(%rip), %cl       # 0x1d33c
movb %cl, 0x2(%rax)
jmp 0x12caf
movq -0x28(%rbp), %rdi
leaq 0x2d50(%rip), %rsi      # 0x1598e
callq 0x5350
cmpl $0x0, %eax
jne 0x12c61
movq -0x48(%rbp), %rax
movw 0xa6ea(%rip), %cx       # 0x1d33d
movw %cx, (%rax)
movb 0xa6e3(%rip), %cl       # 0x1d33f
movb %cl, 0x2(%rax)
jmp 0x12cad
movq -0x28(%rbp), %rdi
leaq 0x2d29(%rip), %rsi      # 0x15995
callq 0x5350
cmpl $0x0, %eax
jne 0x12c8f
movq -0x48(%rbp), %rax
movw 0xa6bf(%rip), %cx       # 0x1d340
movw %cx, (%rax)
movb 0xa6b8(%rip), %cl       # 0x1d342
movb %cl, 0x2(%rax)
jmp 0x12cab
movq 0xa34a(%rip), %rax      # 0x1cfe0
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x2cf8(%rip), %rsi      # 0x1599c
movb $0x0, %al
callq 0x5370
jmp 0x12cad
jmp 0x12caf
jmp 0x12cb1
jmp 0x12cb3
jmp 0x12cb5
jmp 0x12cb7
jmp 0x12cb9
jmp 0x12cbb
testb $0x1, -0x31(%rbp)
je 0x12d19
movq -0x48(%rbp), %rax
movabsq $0x3fe3333333333333, %rcx # imm = 0x3FE3333333333333
movq %rcx, -0x40(%rbp)
movzbl (%rax), %ecx
cvtsi2sd %ecx, %xmm0
movsd -0x40(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movb %cl, (%rax)
movzbl 0x1(%rax), %ecx
cvtsi2sd %ecx, %xmm0
movsd -0x40(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movb %cl, 0x1(%rax)
movzbl 0x2(%rax), %ecx
cvtsi2sd %ecx, %xmm0
movsd -0x40(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movb %cl, 0x2(%rax)
jmp 0x12d1b
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)