#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 */
typedef int /*<<< orphan*/ row;
typedef int /*<<< orphan*/ dupe;

/* Variables and functions */
int atoi(char *);
int chopString(char *, char *, char **, int);
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ strncpy(char *, char *, int);
int bedParseRgb(char *itemRgb) {
  char dupe[64];
  int wordCount;
  char *row[4];
  strncpy(dupe, itemRgb, sizeof(dupe));
  wordCount = chopString(dupe, ",", row, (sizeof(row) / sizeof((row)[0])));
  if ((wordCount != 3) ||
      (!isdigit(row[0][0]) || !isdigit(row[1][0]) || !isdigit(row[2][0])))
    return (-1);
  return (((atoi(row[0]) & 0xff) << 16) | ((atoi(row[1]) & 0xff) << 8) |
          (atoi(row[2]) & 0xff));
}


x86 assembly (clang, -O0):
<bedParseRgb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x40,%edx
call   1040 <strncpy@plt>
lea    -0x50(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xe90(%rip),%rsi
mov    $0x4,%ecx
call   1030 <chopString@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x3,-0x54(%rbp)
jne    11c6 <bedParseRgb+0x86>
mov    -0x80(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isdigit@plt>
cmp    $0x0,%eax
je     11c6 <bedParseRgb+0x86>
mov    -0x78(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isdigit@plt>
cmp    $0x0,%eax
je     11c6 <bedParseRgb+0x86>
mov    -0x70(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isdigit@plt>
cmp    $0x0,%eax
jne    11d2 <bedParseRgb+0x92>
movl   $0xffffffff,-0x4(%rbp)
jmp    1227 <bedParseRgb+0xe7>
mov    -0x80(%rbp),%rdi
call   1060 <atoi@plt>
and    $0xff,%eax
shl    $0x10,%eax
mov    %eax,-0x88(%rbp)
mov    -0x78(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%eax
and    $0xff,%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x84(%rbp)
mov    -0x70(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x84(%rbp),%eax
and    $0xff,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bedParseRgb>:
push   %rbp
push   %rbx
sub    $0x68,%rsp
mov    %rdi,%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x40,%edx
call   1040 <strncpy@plt>
lea    0xe9e(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    $0x4,%ecx
call   1030 <chopString@plt>
mov    $0xffffffff,%ebx
cmp    $0x3,%eax
jne    11de <bedParseRgb+0x9e>
mov    (%rsp),%rax
movsbl (%rax),%edi
call   1050 <isdigit@plt>
test   %eax,%eax
je     11de <bedParseRgb+0x9e>
mov    0x8(%rsp),%rax
movsbl (%rax),%edi
call   1050 <isdigit@plt>
test   %eax,%eax
je     11de <bedParseRgb+0x9e>
mov    0x10(%rsp),%rax
movsbl (%rax),%edi
call   1050 <isdigit@plt>
test   %eax,%eax
je     11de <bedParseRgb+0x9e>
mov    (%rsp),%rdi
call   1060 <atoi@plt>
movzbl %al,%ebx
shl    $0x10,%ebx
mov    0x8(%rsp),%rdi
call   1060 <atoi@plt>
shl    $0x8,%eax
movzwl %ax,%ebp
or     %ebx,%ebp
mov    0x10(%rsp),%rdi
call   1060 <atoi@plt>
movzbl %al,%ebx
or     %ebp,%ebx
mov    %ebx,%eax
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
define i32 @bedParseRgb(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [64 x i8]
%5 = alloca i32
%6 = alloca [4 x i8*]
store i8* %0, i8** %3
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = call i32 @strncpy(i8* %7, i8* %8, i32 64)
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 0
%12 = call i32 @chopString(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %11, i32 4)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 3
br i1 %14, label %36, label %15
15: ; preds = %1
%16 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 0
%17 = load i8*, i8** %16
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = call i32 @isdigit(i8 signext %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %36
22: ; preds = %15
%23 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 1
%24 = load i8*, i8** %23
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = call i32 @isdigit(i8 signext %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %22
%30 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 2
%31 = load i8*, i8** %30
%32 = getelementptr inbounds i8, i8* %31, i64 0
%33 = load i8, i8* %32
%34 = call i32 @isdigit(i8 signext %33)
%35 = icmp ne i32 %34, 0
br i1 %35, label %37, label %36
36: ; preds = %29, %22, %15, %1
store i32 -1, i32* %2
br label %54
37: ; preds = %29
%38 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 0
%39 = load i8*, i8** %38
%40 = call i32 @atoi(i8* %39)
%41 = and i32 %40, 255
%42 = shl i32 %41, 16
%43 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 1
%44 = load i8*, i8** %43
%45 = call i32 @atoi(i8* %44)
%46 = and i32 %45, 255
%47 = shl i32 %46, 8
%48 = or i32 %42, %47
%49 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 2
%50 = load i8*, i8** %49
%51 = call i32 @atoi(i8* %50)
%52 = and i32 %51, 255
%53 = or i32 %48, %52
store i32 %53, i32* %2
br label %54
54: ; preds = %37, %36
%55 = load i32, i32* %2
ret i32 %55
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
define i32 @bedParseRgb(i8* %0) {
%2 = alloca [64 x i8]
%3 = alloca [4 x i8*]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = bitcast [4 x i8*]* %3 to i8*
%6 = call i32 @strncpy(i8* %4, i8* %0, i32 64)
%7 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 0
%8 = call i32 @chopString(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %7, i32 4)
%9 = icmp eq i32 %8, 3
br i1 %9, label %10, label %41
10: ; preds = %1
%11 = load i8*, i8** %7
%12 = load i8, i8* %11
%13 = call i32 @isdigit(i8 signext %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %41, label %15
15: ; preds = %10
%16 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 1
%17 = load i8*, i8** %16
%18 = load i8, i8* %17
%19 = call i32 @isdigit(i8 signext %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %41, label %21
21: ; preds = %15
%22 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 2
%23 = load i8*, i8** %22
%24 = load i8, i8* %23
%25 = call i32 @isdigit(i8 signext %24)
%26 = icmp eq i32 %25, 0
br i1 %26, label %41, label %27
27: ; preds = %21
%28 = load i8*, i8** %7
%29 = call i32 @atoi(i8* %28)
%30 = shl i32 %29, 16
%31 = and i32 %30, 16711680
%32 = load i8*, i8** %16
%33 = call i32 @atoi(i8* %32)
%34 = shl i32 %33, 8
%35 = and i32 %34, 65280
%36 = or i32 %35, %31
%37 = load i8*, i8** %22
%38 = call i32 @atoi(i8* %37)
%39 = and i32 %38, 255
%40 = or i32 %36, %39
br label %41
41: ; preds = %1, %10, %15, %21, %27
%42 = phi i32 [ %40, %27 ], [ -1, %21 ], [ -1, %15 ], [ -1, %10 ], [ -1, %1 ]
ret i32 %42
}