#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 /*<<< orphan*/ strcmp(char const *, char *);
int /*<<< orphan*/ strlen(char const *);
int /*<<< orphan*/ valid_bw_color(char const *);
int process_bw(const char *strcolour, int is_bg, char *secname,
               unsigned char *resval) {
  if (!strcolour || !strlen(strcolour)) {
    camserv_log("textfilter",
                "Invalid [%s]:%s value given.  "
                "Using default",
                secname, is_bg ? "bg" : "fg");
    if (is_bg) {
      *resval = (0x00ff0000 & 0x00000000) >> 16;
      return 0x00000000;
    } else {
      *resval = (0x00ff0000 & 0x00ffffff) >> 16;
      return 0x00ffffff;
    }
  }
  if (!strcmp(strcolour, "transparent"))
    return 0xff000000;
  else {
    int bwval;
    if (!valid_bw_color(strcolour)) {
      camserv_log("textfilter",
                  "Invalid [%s]:%s color given.  "
                  "Format should be: #CC, or 'transparent'",
                  secname, is_bg ? "bg" : "fg");
      if (is_bg) {
        *resval = (0x00ff0000 & 0x00000000) >> 16;
        return 0x00000000;
      } else {
        *resval = (0x00ff0000 & 0x00ffffff) >> 16;
        return 0x00ffffff;
      }
    }
    sscanf(strcolour, "%*c%2x", &bwval);
    *resval = bwval;
    return (*resval << 16);
  }
}


x86 assembly (clang, -O0):
<process_bw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1184 <process_bw+0x34>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jne    11e3 <process_bw+0x93>
mov    -0x20(%rbp),%rdx
mov    -0x14(%rbp),%esi
lea    0xea8(%rip),%rcx
lea    0xe9e(%rip),%rax
cmp    $0x0,%esi
cmovne %rax,%rcx
lea    0xe59(%rip),%rdi
lea    0xe5d(%rip),%rsi
call   1060 <camserv_log@plt>
cmpl   $0x0,-0x14(%rbp)
je     11d0 <process_bw+0x80>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    12a5 <process_bw+0x155>
mov    -0x28(%rbp),%rax
movb   $0xff,(%rax)
movl   $0xffffff,-0x4(%rbp)
jmp    12a5 <process_bw+0x155>
mov    -0x10(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1208 <process_bw+0xb8>
movl   $0xff000000,-0x4(%rbp)
jmp    12a5 <process_bw+0x155>
mov    -0x10(%rbp),%rdi
call   1030 <valid_bw_color@plt>
cmp    $0x0,%eax
jne    1279 <process_bw+0x129>
mov    -0x20(%rbp),%rdx
mov    -0x14(%rbp),%esi
lea    0xe12(%rip),%rcx
lea    0xe08(%rip),%rax
cmp    $0x0,%esi
cmovne %rax,%rcx
lea    0xdc3(%rip),%rdi
lea    0xe05(%rip),%rsi
call   1060 <camserv_log@plt>
cmpl   $0x0,-0x14(%rbp)
je     1266 <process_bw+0x116>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    12a5 <process_bw+0x155>
mov    -0x28(%rbp),%rax
movb   $0xff,(%rax)
movl   $0xffffff,-0x4(%rbp)
jmp    12a5 <process_bw+0x155>
mov    -0x10(%rbp),%rdi
lea    0xe0b(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1070 <sscanf@plt>
mov    -0x2c(%rbp),%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
shl    $0x10,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_bw>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%ebp
test   %rdi,%rdi
je     11b2 <process_bw+0x62>
mov    %rdi,%rbx
call   1040 <strlen@plt>
test   %eax,%eax
je     11b2 <process_bw+0x62>
lea    0xec6(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11f3 <process_bw+0xa3>
mov    %rbx,%rdi
call   1030 <valid_bw_color@plt>
test   %eax,%eax
je     1203 <process_bw+0xb3>
lea    0xef9(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
call   1070 <sscanf@plt>
mov    0x4(%rsp),%eax
mov    %al,(%r14)
movzbl %al,%eax
shl    $0x10,%eax
jmp    11f8 <process_bw+0xa8>
test   %ebp,%ebp
lea    0xe7f(%rip),%rax
lea    0xe75(%rip),%rcx
cmove  %rax,%rcx
lea    0xe33(%rip),%rdi
lea    0xe37(%rip),%rsi
mov    %r15,%rdx
call   1060 <camserv_log@plt>
test   %ebp,%ebp
je     11e8 <process_bw+0x98>
movb   $0x0,(%r14)
xor    %eax,%eax
jmp    11f8 <process_bw+0xa8>
movb   $0xff,(%r14)
mov    $0xffffff,%eax
jmp    11f8 <process_bw+0xa8>
mov    $0xff000000,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
test   %ebp,%ebp
lea    0xe2e(%rip),%rax
lea    0xe24(%rip),%rcx
cmove  %rax,%rcx
lea    0xde2(%rip),%rdi
lea    0xe24(%rip),%rsi
jmp    11d4 <process_bw+0x84>

LLVM IR (-O0):
@.str = [11 x i8] c"textfilter\00"
@.str.1 = [44 x i8] c"Invalid [%s]:%s value 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 = [70 x i8] c"Invalid [%s]:%s color given. Format should be: #CC, or 'transparent'\00"
@.str.6 = [7 x i8] c"%*c%2x\00"
define i32 @process_bw(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %4
%14 = load i8*, i8** %6
%15 = call i32 @strlen(i8* %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %30, label %17
17: ; preds = %13, %4
%18 = load i8*, i8** %8
%19 = load i32, i32* %7
%20 = icmp ne i32 %19, 0
%21 = zext i1 %20 to i64
%22 = select i1 %20, 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)
%23 = 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* %18, i8* %22)
%24 = load i32, i32* %7
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %17
%27 = load i8*, i8** %9
store i8 0, i8* %27
store i32 0, i32* %5
br label %62
28: ; preds = %17
%29 = load i8*, i8** %9
store i8 -1, i8* %29
store i32 16777215, i32* %5
br label %62
30: ; preds = %13
%31 = load i8*, i8** %6
%32 = call i32 @strcmp(i8* %31, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%33 = icmp ne i32 %32, 0
br i1 %33, label %35, label %34
34: ; preds = %30
store i32 -16777216, i32* %5
br label %62
35: ; preds = %30
%36 = load i8*, i8** %6
%37 = call i32 @valid_bw_color(i8* %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %52, label %39
39: ; preds = %35
%40 = load i8*, i8** %8
%41 = load i32, i32* %7
%42 = icmp ne i32 %41, 0
%43 = zext i1 %42 to i64
%44 = select i1 %42, 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)
%45 = call i32 @camserv_log(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.5, i64 0, i64 0), i8* %40, i8* %44)
%46 = load i32, i32* %7
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %39
%49 = load i8*, i8** %9
store i8 0, i8* %49
store i32 0, i32* %5
br label %62
50: ; preds = %39
%51 = load i8*, i8** %9
store i8 -1, i8* %51
store i32 16777215, i32* %5
br label %62
52: ; preds = %35
%53 = load i8*, i8** %6
%54 = call i32 @sscanf(i8* %53, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32* %10)
%55 = load i32, i32* %10
%56 = trunc i32 %55 to i8
%57 = load i8*, i8** %9
store i8 %56, i8* %57
%58 = load i8*, i8** %9
%59 = load i8, i8* %58
%60 = zext i8 %59 to i32
%61 = shl i32 %60, 16
store i32 %61, i32* %5
br label %62
62: ; preds = %52, %50, %48, %34, %28, %26
%63 = load i32, i32* %5
ret i32 %63
}

LLVM IR (-O2):
@.str = [11 x i8] c"textfilter\00"
@.str.1 = [44 x i8] c"Invalid [%s]:%s value 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 = [70 x i8] c"Invalid [%s]:%s color given. Format should be: #CC, or 'transparent'\00"
@.str.6 = [7 x i8] c"%*c%2x\00"
define i32 @process_bw(i8* %0, i32 %1, i8* %2, i8* nocapture writeonly %3) {
%5 = alloca i32
%6 = icmp eq i8* %0, null
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = tail call i32 @strlen(i8* %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %7, %4
%11 = icmp eq i32 %1, 0
%12 = select i1 %11, 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)
%13 = 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* %12)
br i1 %11, label %15, label %14
14: ; preds = %10
store i8 0, i8* %3
br label %37
15: ; preds = %10
store i8 -1, i8* %3
br label %37
16: ; preds = %7
%17 = tail call i32 @strcmp(i8* %0, i8* dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%18 = icmp eq i32 %17, 0
br i1 %18, label %37, label %19
19: ; preds = %16
%20 = bitcast i32* %5 to i8*
%21 = tail call i32 @valid_bw_color(i8* %0)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = icmp eq i32 %1, 0
%25 = select i1 %24, 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)
%26 = tail call i32 @camserv_log(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.5, i64 0, i64 0), i8* %2, i8* %25)
br i1 %24, label %28, label %27
27: ; preds = %23
store i8 0, i8* %3
br label %35
28: ; preds = %23
store i8 -1, i8* %3
br label %35
29: ; preds = %19
%30 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32* %5)
%31 = load i32, i32* %5
%32 = trunc i32 %31 to i8
store i8 %32, i8* %3
%33 = shl i32 %31, 16
%34 = and i32 %33, 16711680
br label %35
35: ; preds = %29, %28, %27
%36 = phi i32 [ %34, %29 ], [ 0, %27 ], [ 16777215, %28 ]
br label %37
37: ; preds = %16, %35, %15, %14
%38 = phi i32 [ %36, %35 ], [ 0, %14 ], [ 16777215, %15 ], [ -16777216, %16 ]
ret i32 %38
}