#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int coloridx(char *);
char *strchr(char *, char);
void parsecolor(char *col, int *fg, int *bg) {
  char *p;
  p = strchr(col, ':');
  if (p == NULL) {
    *fg = coloridx(col);
    *bg = -1;
  } else {
    *p++ = '\0';
    *fg = coloridx(col);
    *bg = coloridx(p);
  }
}


x86 assembly (clang, -O0):
<parsecolor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1171 <parsecolor+0x51>
mov    -0x8(%rbp),%rdi
call   1040 <coloridx@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
movl   $0xffffffff,(%rax)
jmp    11a5 <parsecolor+0x85>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <coloridx@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rdi
call   1040 <coloridx@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parsecolor>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     115f <parsecolor+0x3f>
mov    %rax,%rbx
add    $0x1,%rbx
movb   $0x0,(%rax)
mov    %r12,%rdi
call   1040 <coloridx@plt>
mov    %eax,(%r15)
mov    %rbx,%rdi
call   1040 <coloridx@plt>
jmp    116f <parsecolor+0x4f>
mov    %r12,%rdi
call   1040 <coloridx@plt>
mov    %eax,(%r15)
mov    $0xffffffff,%eax
mov    %eax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @parsecolor(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%8 = load i8*, i8** %4
%9 = call i8* @strchr(i8* %8, i8 signext 58)
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %17
12: ; preds = %3
%13 = load i8*, i8** %4
%14 = call i32 @coloridx(i8* %13)
%15 = load i32*, i32** %5
store i32 %14, i32* %15
%16 = load i32*, i32** %6
store i32 -1, i32* %16
br label %26
17: ; preds = %3
%18 = load i8*, i8** %7
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %7
store i8 0, i8* %18
%20 = load i8*, i8** %4
%21 = call i32 @coloridx(i8* %20)
%22 = load i32*, i32** %5
store i32 %21, i32* %22
%23 = load i8*, i8** %7
%24 = call i32 @coloridx(i8* %23)
%25 = load i32*, i32** %6
store i32 %24, i32* %25
br label %26
26: ; preds = %17, %12
ret void
}

LLVM IR (-O2):
define void @parsecolor(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @coloridx(i8* %0)
store i32 %7, i32* %1
br label %12
8: ; preds = %3
%9 = getelementptr inbounds i8, i8* %4, i64 1
store i8 0, i8* %4
%10 = tail call i32 @coloridx(i8* %0)
store i32 %10, i32* %1
%11 = tail call i32 @coloridx(i8* %9)
br label %12
12: ; preds = %8, %6
%13 = phi i32 [ %11, %8 ], [ -1, %6 ]
store i32 %13, i32* %2
ret void
}