#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 /*<<< orphan*/ camserv_log(char *, char *, char *, char *);
int /*<<< orphan*/ sscanf(char const *, char *, int *, int *, int *);
int /*<<< orphan*/ strcmp(char const *, char *);
int /*<<< orphan*/ strlen(char const *);
int /*<<< orphan*/ valid_rgb_color(char const *);
int process_color(const char *color, int is_bg, char *secname,
                  unsigned char *rint, unsigned char *gint,
                  unsigned char *bint) {
  if (!color || !strlen(color)) {
    camserv_log("textfilter",
                "Invalid [%s]:%s color given.  "
                "Using default",
                secname, is_bg ? "bg" : "fg");
    if (is_bg) {
      *rint = (0x00ff0000 & 0x00000000) >> 16;
      *gint = (0x0000ff00 & 0x00000000) >> 8;
      *bint = (0x000000ff & 0x00000000) >> 0;
      return 0x00000000;
    } else {
      *rint = (0x00ff0000 & 0x00ffffff) >> 16;
      *gint = (0x0000ff00 & 0x00ffffff) >> 8;
      *bint = (0x000000ff & 0x00ffffff) >> 0;
      return 0x00ffffff;
    }
  }
  if (!strcmp(color, "transparent"))
    return 0xff000000;
  else {
    int rf, gf, bf;
    if (!valid_rgb_color(color)) {
      camserv_log("textfilter",
                  "Invalid [%s]:%s color given.  "
                  "Format should be: #RRGGBB, or 'transparent",
                  secname, is_bg ? "bg" : "fg");
      if (is_bg) {
        *rint = (0x00ff0000 & 0x00000000) >> 16;
        *gint = (0x0000ff00 & 0x00000000) >> 8;
        *bint = (0x000000ff & 0x00000000) >> 0;
        return 0x00000000;
      } else {
        *rint = (0x00ff0000 & 0x00ffffff) >> 16;
        *gint = (0x0000ff00 & 0x00ffffff) >> 8;
        *bint = (0x000000ff & 0x00ffffff) >> 0;
        return 0x00ffffff;
      }
    }
    sscanf(color, "%*c%2x%2x%2x", &rf, &gf, &bf);
    *rint = rf;
    *gint = gf;
    *bint = bf;
    return (*rint << 16) | (*gint << 8) | *bint;
  }
}


x86 assembly (clang, -O0):
<process_color>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118c <process_color+0x3c>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jne    1207 <process_color+0xb7>
mov    -0x20(%rbp),%rdx
mov    -0x14(%rbp),%esi
lea    0xea0(%rip),%rcx
lea    0xe96(%rip),%rax
cmp    $0x0,%esi
cmovne %rax,%rcx
lea    0xe51(%rip),%rdi
lea    0xe55(%rip),%rsi
call   1060 <camserv_log@plt>
cmpl   $0x0,-0x14(%rbp)
je     11e6 <process_color+0x96>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1318 <process_color+0x1c8>
mov    -0x28(%rbp),%rax
movb   $0xff,(%rax)
mov    -0x30(%rbp),%rax
movb   $0xff,(%rax)
mov    -0x38(%rbp),%rax
movb   $0xff,(%rax)
movl   $0xffffff,-0x4(%rbp)
jmp    1318 <process_color+0x1c8>
mov    -0x10(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    122c <process_color+0xdc>
movl   $0xff000000,-0x4(%rbp)
jmp    1318 <process_color+0x1c8>
mov    -0x10(%rbp),%rdi
call   1030 <valid_rgb_color@plt>
cmp    $0x0,%eax
jne    12b9 <process_color+0x169>
mov    -0x20(%rbp),%rdx
mov    -0x14(%rbp),%esi
lea    0xdee(%rip),%rcx
lea    0xde4(%rip),%rax
cmp    $0x0,%esi
cmovne %rax,%rcx
lea    0xd9f(%rip),%rdi
lea    0xdd5(%rip),%rsi
call   1060 <camserv_log@plt>
cmpl   $0x0,-0x14(%rbp)
je     1298 <process_color+0x148>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1318 <process_color+0x1c8>
mov    -0x28(%rbp),%rax
movb   $0xff,(%rax)
mov    -0x30(%rbp),%rax
movb   $0xff,(%rax)
mov    -0x38(%rbp),%rax
movb   $0xff,(%rax)
movl   $0xffffff,-0x4(%rbp)
jmp    1318 <process_color+0x1c8>
mov    -0x10(%rbp),%rdi
lea    0xdc2(%rip),%rsi
lea    -0x3c(%rbp),%rdx
lea    -0x40(%rbp),%rcx
lea    -0x44(%rbp),%r8
call   1070 <sscanf@plt>
mov    -0x3c(%rbp),%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x40(%rbp),%eax
mov    %al,%cl
mov    -0x30(%rbp),%rax
mov    %cl,(%rax)
mov    -0x44(%rbp),%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
shl    $0x10,%eax
mov    -0x30(%rbp),%rcx
movzbl (%rcx),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x38(%rbp),%rcx
movzbl (%rcx),%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_color>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r14
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r13
mov    %esi,%ebp
test   %rdi,%rdi
je     11f0 <process_color+0xa0>
mov    %rdi,%rbx
call   1040 <strlen@plt>
test   %eax,%eax
je     11f0 <process_color+0xa0>
lea    0xef6(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1243 <process_color+0xf3>
mov    %rbx,%rdi
call   1030 <valid_rgb_color@plt>
test   %eax,%eax
je     1257 <process_color+0x107>
lea    0xedb(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    %rbx,%rdi
call   1070 <sscanf@plt>
mov    0x14(%rsp),%al
mov    %al,(%r12)
mov    0x10(%rsp),%al
mov    %al,(%r15)
mov    0xc(%rsp),%eax
movzbl %al,%ecx
mov    %cl,(%r14)
movzbl (%r12),%eax
shl    $0x10,%eax
movzbl (%r15),%edx
shl    $0x8,%edx
or     %ecx,%eax
or     %edx,%eax
jmp    1248 <process_color+0xf8>
test   %ebp,%ebp
lea    0xe41(%rip),%rax
lea    0xe37(%rip),%rcx
cmove  %rax,%rcx
lea    0xdf5(%rip),%rdi
lea    0xdf9(%rip),%rsi
mov    %r13,%rdx
call   1060 <camserv_log@plt>
test   %ebp,%ebp
je     122f <process_color+0xdf>
movb   $0x0,(%r12)
movb   $0x0,(%r15)
movb   $0x0,(%r14)
xor    %eax,%eax
jmp    1248 <process_color+0xf8>
movb   $0xff,(%r12)
movb   $0xff,(%r15)
movb   $0xff,(%r14)
mov    $0xffffff,%eax
jmp    1248 <process_color+0xf8>
mov    $0xff000000,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %ebp,%ebp
lea    0xdda(%rip),%rax
lea    0xdd0(%rip),%rcx
cmove  %rax,%rcx
lea    0xd8e(%rip),%rdi
lea    0xdc4(%rip),%rsi
jmp    1212 <process_color+0xc2>

LLVM IR (-O0):
@.str = [11 x i8] c"textfilter\00"
@.str.1 = [44 x i8] c"Invalid [%s]:%s color given. Using default\00"
@.str.2 = [3 x i8] c"bg\00"
@.str.3 = [3 x i8] c"fg\00"
@.str.4 = [12 x i8] c"transparent\00"
@.str.5 = [73 x i8] c"Invalid [%s]:%s color given. Format should be: #RRGGBB, or 'transparent\00"
@.str.6 = [13 x i8] c"%*c%2x%2x%2x\00"
define i32 @process_color(i8* %0, i32 %1, i8* %2, i8* %3, i8* %4, i8* %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i8* %0, i8** %8
store i32 %1, i32* %9
store i8* %2, i8** %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store i8* %5, i8** %13
%17 = load i8*, i8** %8
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %23
19: ; preds = %6
%20 = load i8*, i8** %8
%21 = call i32 @strlen(i8* %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %40, label %23
23: ; preds = %19, %6
%24 = load i8*, i8** %10
%25 = load i32, i32* %9
%26 = icmp ne i32 %25, 0
%27 = zext i1 %26 to i64
%28 = select i1 %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0)
%29 = call i32 @camserv_log(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %24, i8* %28)
%30 = load i32, i32* %9
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %23
%33 = load i8*, i8** %11
store i8 0, i8* %33
%34 = load i8*, i8** %12
store i8 0, i8* %34
%35 = load i8*, i8** %13
store i8 0, i8* %35
store i32 0, i32* %7
br label %91
36: ; preds = %23
%37 = load i8*, i8** %11
store i8 -1, i8* %37
%38 = load i8*, i8** %12
store i8 -1, i8* %38
%39 = load i8*, i8** %13
store i8 -1, i8* %39
store i32 16777215, i32* %7
br label %91
40: ; preds = %19
%41 = load i8*, i8** %8
%42 = call i32 @strcmp(i8* %41, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%43 = icmp ne i32 %42, 0
br i1 %43, label %45, label %44
44: ; preds = %40
store i32 -16777216, i32* %7
br label %91
45: ; preds = %40
%46 = load i8*, i8** %8
%47 = call i32 @valid_rgb_color(i8* %46)
%48 = icmp ne i32 %47, 0
br i1 %48, label %66, label %49
49: ; preds = %45
%50 = load i8*, i8** %10
%51 = load i32, i32* %9
%52 = icmp ne i32 %51, 0
%53 = zext i1 %52 to i64
%54 = select i1 %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0)
%55 = call i32 @camserv_log(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.5, i64 0, i64 0), i8* %50, i8* %54)
%56 = load i32, i32* %9
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %49
%59 = load i8*, i8** %11
store i8 0, i8* %59
%60 = load i8*, i8** %12
store i8 0, i8* %60
%61 = load i8*, i8** %13
store i8 0, i8* %61
store i32 0, i32* %7
br label %91
62: ; preds = %49
%63 = load i8*, i8** %11
store i8 -1, i8* %63
%64 = load i8*, i8** %12
store i8 -1, i8* %64
%65 = load i8*, i8** %13
store i8 -1, i8* %65
store i32 16777215, i32* %7
br label %91
66: ; preds = %45
%67 = load i8*, i8** %8
%68 = call i32 @sscanf(i8* %67, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32* %14, i32* %15, i32* %16)
%69 = load i32, i32* %14
%70 = trunc i32 %69 to i8
%71 = load i8*, i8** %11
store i8 %70, i8* %71
%72 = load i32, i32* %15
%73 = trunc i32 %72 to i8
%74 = load i8*, i8** %12
store i8 %73, i8* %74
%75 = load i32, i32* %16
%76 = trunc i32 %75 to i8
%77 = load i8*, i8** %13
store i8 %76, i8* %77
%78 = load i8*, i8** %11
%79 = load i8, i8* %78
%80 = zext i8 %79 to i32
%81 = shl i32 %80, 16
%82 = load i8*, i8** %12
%83 = load i8, i8* %82
%84 = zext i8 %83 to i32
%85 = shl i32 %84, 8
%86 = or i32 %81, %85
%87 = load i8*, i8** %13
%88 = load i8, i8* %87
%89 = zext i8 %88 to i32
%90 = or i32 %86, %89
store i32 %90, i32* %7
br label %91
91: ; preds = %66, %62, %58, %44, %36, %32
%92 = load i32, i32* %7
ret i32 %92
}

LLVM IR (-O2):
@.str = [11 x i8] c"textfilter\00"
@.str.1 = [44 x i8] c"Invalid [%s]:%s color given. Using default\00"
@.str.2 = [3 x i8] c"bg\00"
@.str.3 = [3 x i8] c"fg\00"
@.str.4 = [12 x i8] c"transparent\00"
@.str.5 = [73 x i8] c"Invalid [%s]:%s color given. Format should be: #RRGGBB, or 'transparent\00"
@.str.6 = [13 x i8] c"%*c%2x%2x%2x\00"
define i32 @process_color(i8* %0, i32 %1, i8* %2, i8* nocapture %3, i8* nocapture %4, i8* nocapture writeonly %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = icmp eq i8* %0, null
br i1 %10, label %14, label %11
11: ; preds = %6
%12 = tail call i32 @strlen(i8* %0)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %11, %6
%15 = icmp eq i32 %1, 0
%16 = select i1 %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%17 = tail call i32 @camserv_log(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %16)
br i1 %15, label %19, label %18
18: ; preds = %14
store i8 0, i8* %3
store i8 0, i8* %4
store i8 0, i8* %5
br label %54
19: ; preds = %14
store i8 -1, i8* %3
store i8 -1, i8* %4
store i8 -1, i8* %5
br label %54
20: ; preds = %11
%21 = tail call i32 @strcmp(i8* %0, i8* dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%22 = icmp eq i32 %21, 0
br i1 %22, label %54, label %23
23: ; preds = %20
%24 = bitcast i32* %7 to i8*
%25 = bitcast i32* %8 to i8*
%26 = bitcast i32* %9 to i8*
%27 = tail call i32 @valid_rgb_color(i8* %0)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %23
%30 = icmp eq i32 %1, 0
%31 = select i1 %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%32 = tail call i32 @camserv_log(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.5, i64 0, i64 0), i8* %2, i8* %31)
br i1 %30, label %34, label %33
33: ; preds = %29
store i8 0, i8* %3
store i8 0, i8* %4
store i8 0, i8* %5
br label %52
34: ; preds = %29
store i8 -1, i8* %3
store i8 -1, i8* %4
store i8 -1, i8* %5
br label %52
35: ; preds = %23
%36 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32* %7, i32* %8, i32* %9)
%37 = load i32, i32* %7
%38 = trunc i32 %37 to i8
store i8 %38, i8* %3
%39 = load i32, i32* %8
%40 = trunc i32 %39 to i8
store i8 %40, i8* %4
%41 = load i32, i32* %9
%42 = trunc i32 %41 to i8
store i8 %42, i8* %5
%43 = load i8, i8* %3
%44 = zext i8 %43 to i32
%45 = shl nuw nsw i32 %44, 16
%46 = load i8, i8* %4
%47 = zext i8 %46 to i32
%48 = shl nuw nsw i32 %47, 8
%49 = and i32 %41, 255
%50 = or i32 %45, %49
%51 = or i32 %50, %48
br label %52
52: ; preds = %35, %34, %33
%53 = phi i32 [ %51, %35 ], [ 0, %33 ], [ 16777215, %34 ]
br label %54
54: ; preds = %20, %52, %19, %18
%55 = phi i32 [ %53, %52 ], [ 0, %18 ], [ 16777215, %19 ], [ -16777216, %20 ]
ret i32 %55
}