#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 config_color_str_convert(char const *, int, char const *);
int /*<<< orphan*/ free(char *);
int get_color_ncurses(int, int);
char *strchr(char *, char);
char *strdup(char const *);
int parse_color_spec(const char *par, int linenr, const char *subj) {
  char *temp = strdup(par);
  char *komma = strchr(temp, ',');
  const char *fgstr = temp, *bgstr = "default";
  int fg = -1, bg = -1;
  int col = -1;
  if (komma) {
    *komma = 0x00;
    bgstr = komma + 1;
  }
  fg = config_color_str_convert(fgstr, linenr, subj);
  bg = config_color_str_convert(bgstr, linenr, subj);
  free(temp);
  if (fg == bg && fg != -1)
    fg = bg = -1;
  col = get_color_ncurses(fg, bg);
  return col;
}


x86 assembly (clang, -O0):
<parse_color_spec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xe6f(%rip),%rax
mov    %rax,-0x38(%rbp)
movl   $0xffffffff,-0x3c(%rbp)
movl   $0xffffffff,-0x40(%rbp)
movl   $0xffffffff,-0x44(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11c8 <parse_color_spec+0x78>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1060 <config_color_str_convert@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1060 <config_color_str_convert@plt>
mov    %eax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x3c(%rbp),%eax
cmp    -0x40(%rbp),%eax
jne    121b <parse_color_spec+0xcb>
cmpl   $0xffffffff,-0x3c(%rbp)
je     121b <parse_color_spec+0xcb>
movl   $0xffffffff,-0x40(%rbp)
movl   $0xffffffff,-0x3c(%rbp)
mov    -0x3c(%rbp),%edi
mov    -0x40(%rbp),%esi
call   1050 <get_color_ncurses@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_color_spec>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %esi,%r15d
call   1070 <strdup@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1184 <parse_color_spec+0x34>
mov    %rax,%rbp
movb   $0x0,(%rax)
add    $0x1,%rbp
jmp    118b <parse_color_spec+0x3b>
lea    0xe75(%rip),%rbp
mov    %r12,%rdi
mov    %r15d,%esi
mov    %r14,%rdx
call   1060 <config_color_str_convert@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
mov    %r15d,%esi
mov    %r14,%rdx
call   1060 <config_color_str_convert@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1030 <free@plt>
cmp    %ebp,%ebx
sete   %al
cmp    $0xffffffff,%ebx
setne  %cl
test   %al,%cl
mov    $0xffffffff,%eax
cmovne %eax,%ebx
cmovne %eax,%ebp
mov    %ebx,%edi
mov    %ebp,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <get_color_ncurses@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"default\00"
define i32 @parse_color_spec(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%14 = load i8*, i8** %4
%15 = call i8* @strdup(i8* %14)
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = call i8* @strchr(i8* %16, i8 signext 44)
store i8* %17, i8** %8
%18 = load i8*, i8** %7
store i8* %18, i8** %9
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %10
store i32 -1, i32* %11
store i32 -1, i32* %12
store i32 -1, i32* %13
%19 = load i8*, i8** %8
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %25
21: ; preds = %3
%22 = load i8*, i8** %8
store i8 0, i8* %22
%23 = load i8*, i8** %8
%24 = getelementptr inbounds i8, i8* %23, i64 1
store i8* %24, i8** %10
br label %25
25: ; preds = %21, %3
%26 = load i8*, i8** %9
%27 = load i32, i32* %5
%28 = load i8*, i8** %6
%29 = call i32 @config_color_str_convert(i8* %26, i32 %27, i8* %28)
store i32 %29, i32* %11
%30 = load i8*, i8** %10
%31 = load i32, i32* %5
%32 = load i8*, i8** %6
%33 = call i32 @config_color_str_convert(i8* %30, i32 %31, i8* %32)
store i32 %33, i32* %12
%34 = load i8*, i8** %7
%35 = call i32 @free(i8* %34)
%36 = load i32, i32* %11
%37 = load i32, i32* %12
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %43
39: ; preds = %25
%40 = load i32, i32* %11
%41 = icmp ne i32 %40, -1
br i1 %41, label %42, label %43
42: ; preds = %39
store i32 -1, i32* %12
store i32 -1, i32* %11
br label %43
43: ; preds = %42, %39, %25
%44 = load i32, i32* %11
%45 = load i32, i32* %12
%46 = call i32 @get_color_ncurses(i32 %44, i32 %45)
store i32 %46, i32* %13
%47 = load i32, i32* %13
ret i32 %47
}

LLVM IR (-O2):
@.str = [8 x i8] c"default\00"
define i32 @parse_color_spec(i8* nocapture %0, i32 %1, i8* %2) {
%4 = tail call i8* @strdup(i8* %0)
%5 = tail call i8* @strchr(i8* dereferenceable(1) %4, i8 signext 44)
%6 = icmp eq i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %3
store i8 0, i8* %5
%8 = getelementptr inbounds i8, i8* %5, i64 1
br label %9
9: ; preds = %7, %3
%10 = phi i8* [ %8, %7 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %3 ]
%11 = tail call i32 @config_color_str_convert(i8* %4, i32 %1, i8* %2)
%12 = tail call i32 @config_color_str_convert(i8* %10, i32 %1, i8* %2)
%13 = tail call i32 @free(i8* %4)
%14 = icmp eq i32 %11, %12
%15 = icmp ne i32 %11, -1
%16 = and i1 %15, %14
%17 = select i1 %16, i32 -1, i32 %11
%18 = select i1 %16, i32 -1, i32 %12
%19 = tail call i32 @get_color_ncurses(i32 %17, i32 %18)
ret i32 %19
}