#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 */
char *strtok(int /*<<< orphan*/ *, char *);
long strtol(char *, char **, int);
int /*<<< orphan*/ theme_parse_error(int const, char *);
short parse_rgb_color_value(const int line_num, const int errors_are_fatal) {
  char *tmp;
  char *end;
  long color;
  if (!(tmp = strtok(NULL, " \t"))) {
    if (errors_are_fatal)
      theme_parse_error(line_num, "3 color values expected");
    return -1;
  }
  color = strtol(tmp, &end, 10);
  if (*end) {
    if (errors_are_fatal)
      theme_parse_error(line_num, "color value is not a valid number");
    return -1;
  }
  if (!((color) >= (0) && (color) <= (1000))) {
    if (errors_are_fatal)
      theme_parse_error(line_num, "color value should be in range 0-1000");
    return -1;
  }
  return color;
}


x86 assembly (clang, -O0):
<parse_rgb_color_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xeb7(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1180 <parse_rgb_color_value+0x50>
cmpl   $0x0,-0xc(%rbp)
je     1175 <parse_rgb_color_value+0x45>
mov    -0x8(%rbp),%edi
lea    0xe93(%rip),%rsi
call   1030 <theme_parse_error@plt>
movw   $0xffff,-0x2(%rbp)
jmp    120c <parse_rgb_color_value+0xdc>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11c7 <parse_rgb_color_value+0x97>
cmpl   $0x0,-0xc(%rbp)
je     11bc <parse_rgb_color_value+0x8c>
mov    -0x8(%rbp),%edi
lea    0xe64(%rip),%rsi
call   1030 <theme_parse_error@plt>
movw   $0xffff,-0x2(%rbp)
jmp    120c <parse_rgb_color_value+0xdc>
cmpq   $0x0,-0x28(%rbp)
jl     11e0 <parse_rgb_color_value+0xb0>
cmpq   $0x3e8,-0x28(%rbp)
jle    1204 <parse_rgb_color_value+0xd4>
cmpl   $0x0,-0xc(%rbp)
je     11f9 <parse_rgb_color_value+0xc9>
mov    -0x8(%rbp),%edi
lea    0xe49(%rip),%rsi
call   1030 <theme_parse_error@plt>
movw   $0xffff,-0x2(%rbp)
jmp    120c <parse_rgb_color_value+0xdc>
mov    -0x28(%rbp),%rax
mov    %ax,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_rgb_color_value>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %edi,%r14d
lea    0xebc(%rip),%rsi
xor    %edi,%edi
call   1050 <strtok@plt>
test   %rax,%rax
je     1180 <parse_rgb_color_value+0x50>
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     1191 <parse_rgb_color_value+0x61>
mov    $0xffff,%bx
test   %ebp,%ebp
je     11b1 <parse_rgb_color_value+0x81>
lea    0xe9d(%rip),%rsi
jmp    11a9 <parse_rgb_color_value+0x79>
mov    $0xffff,%bx
test   %ebp,%ebp
je     11b1 <parse_rgb_color_value+0x81>
lea    0xe74(%rip),%rsi
jmp    11a9 <parse_rgb_color_value+0x79>
cmp    $0x3e9,%rbx
jb     11b1 <parse_rgb_color_value+0x81>
mov    $0xffff,%bx
test   %ebp,%ebp
je     11b1 <parse_rgb_color_value+0x81>
lea    0xe94(%rip),%rsi
mov    %r14d,%edi
call   1030 <theme_parse_error@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c" \09\00"
@.str.1 = [24 x i8] c"3 color values expected\00"
@.str.2 = [34 x i8] c"color value is not a valid number\00"
@.str.3 = [38 x i8] c"color value should be in range 0-1000\00"
define signext i16 @parse_rgb_color_value(i32 %0, i32 %1) {
%3 = alloca i16
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
store i32 %0, i32* %4
store i32 %1, i32* %5
%9 = call i8* @strtok(i32* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %18, label %11
11: ; preds = %2
%12 = load i32, i32* %5
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* %4
%16 = call i32 @theme_parse_error(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %14, %11
store i16 -1, i16* %3
br label %47
18: ; preds = %2
%19 = load i8*, i8** %6
%20 = call i64 @strtol(i8* %19, i8** %7, i32 10)
store i64 %20, i64* %8
%21 = load i8*, i8** %7
%22 = load i8, i8* %21
%23 = icmp ne i8 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %18
%25 = load i32, i32* %5
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32, i32* %4
%29 = call i32 @theme_parse_error(i32 %28, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %27, %24
store i16 -1, i16* %3
br label %47
31: ; preds = %18
%32 = load i64, i64* %8
%33 = icmp sge i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i64, i64* %8
%36 = icmp sle i64 %35, 1000
br i1 %36, label %44, label %37
37: ; preds = %34, %31
%38 = load i32, i32* %5
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i32, i32* %4
%42 = call i32 @theme_parse_error(i32 %41, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %40, %37
store i16 -1, i16* %3
br label %47
44: ; preds = %34
%45 = load i64, i64* %8
%46 = trunc i64 %45 to i16
store i16 %46, i16* %3
br label %47
47: ; preds = %44, %43, %30, %17
%48 = load i16, i16* %3
ret i16 %48
}

LLVM IR (-O2):
@.str = [3 x i8] c" \09\00"
@.str.1 = [24 x i8] c"3 color values expected\00"
@.str.2 = [34 x i8] c"color value is not a valid number\00"
@.str.3 = [38 x i8] c"color value should be in range 0-1000\00"
define signext i16 @parse_rgb_color_value(i32 %0, i32 %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call i8* @strtok(i32* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = icmp eq i32 %1, 0
br i1 %8, label %28, label %9
9: ; preds = %7
%10 = tail call i32 @theme_parse_error(i32 %0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %28
11: ; preds = %2
%12 = call i64 @strtol(i8* %5, i8** %3, i32 10)
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %11
%17 = icmp eq i32 %1, 0
br i1 %17, label %28, label %18
18: ; preds = %16
%19 = tail call i32 @theme_parse_error(i32 %0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %28
20: ; preds = %11
%21 = icmp ult i64 %12, 1001
br i1 %21, label %26, label %22
22: ; preds = %20
%23 = icmp eq i32 %1, 0
br i1 %23, label %28, label %24
24: ; preds = %22
%25 = tail call i32 @theme_parse_error(i32 %0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %28
26: ; preds = %20
%27 = trunc i64 %12 to i16
br label %28
28: ; preds = %22, %24, %16, %18, %7, %9, %26
%29 = phi i16 [ %27, %26 ], [ -1, %9 ], [ -1, %7 ], [ -1, %18 ], [ -1, %16 ], [ -1, %24 ], [ -1, %22 ]
ret i16 %29
}