#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 sscanf(char const *, char *, unsigned int *, unsigned int *,
           unsigned int *);
int iupStrToRGB(const char *str, unsigned char *r, unsigned char *g,
                unsigned char *b) {
  unsigned int ri = 0, gi = 0, bi = 0;
  if (!str)
    return 0;
  if (str[0] == '#') {
    str++;
    if (sscanf(str, "%2X%2X%2X", &ri, &gi, &bi) != 3)
      return 0;
  } else {
    if (sscanf(str, "%u %u %u", &ri, &gi, &bi) != 3)
      return 0;
  }
  if (ri > 255 || gi > 255 || bi > 255)
    return 0;
  *r = (unsigned char)ri;
  *g = (unsigned char)gi;
  *b = (unsigned char)bi;
  return 1;
}


x86 assembly (clang, -O0):
<iupStrToRGB>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1154 <iupStrToRGB+0x44>
movl   $0x0,-0x4(%rbp)
jmp    1237 <iupStrToRGB+0x127>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    11a6 <iupStrToRGB+0x96>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe85(%rip),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x34(%rbp),%r8
call   1030 <sscanf@plt>
cmp    $0x3,%eax
je     11a1 <iupStrToRGB+0x91>
movl   $0x0,-0x4(%rbp)
jmp    1237 <iupStrToRGB+0x127>
jmp    11dc <iupStrToRGB+0xcc>
mov    -0x10(%rbp),%rdi
lea    0xe59(%rip),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x34(%rbp),%r8
call   1030 <sscanf@plt>
cmp    $0x3,%eax
je     11d7 <iupStrToRGB+0xc7>
movl   $0x0,-0x4(%rbp)
jmp    1237 <iupStrToRGB+0x127>
jmp    11dc <iupStrToRGB+0xcc>
cmpl   $0xff,-0x2c(%rbp)
ja     1203 <iupStrToRGB+0xf3>
cmpl   $0xff,-0x30(%rbp)
ja     1203 <iupStrToRGB+0xf3>
cmpl   $0xff,-0x34(%rbp)
jbe    120f <iupStrToRGB+0xff>
movl   $0x0,-0x4(%rbp)
jmp    1237 <iupStrToRGB+0x127>
mov    -0x2c(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x30(%rbp),%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x34(%rbp),%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iupStrToRGB>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
xor    %ebx,%ebx
test   %rdi,%rdi
je     11a7 <iupStrToRGB+0x97>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
cmpb   $0x23,(%rdi)
jne    1155 <iupStrToRGB+0x45>
add    $0x1,%rdi
lea    0xead(%rip),%rsi
jmp    115c <iupStrToRGB+0x4c>
lea    0xeae(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
call   1030 <sscanf@plt>
cmp    $0x3,%eax
jne    11a7 <iupStrToRGB+0x97>
mov    0x14(%rsp),%eax
cmp    $0xff,%eax
ja     11a7 <iupStrToRGB+0x97>
mov    0x10(%rsp),%ecx
cmp    $0xff,%ecx
ja     11a7 <iupStrToRGB+0x97>
mov    0xc(%rsp),%edx
cmp    $0xff,%edx
ja     11a7 <iupStrToRGB+0x97>
mov    %al,(%r12)
mov    %cl,(%r15)
mov    %dl,(%r14)
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [10 x i8] c"%2X%2X%2X\00"
@.str.1 = [9 x i8] c"%u %u %u\00"
define i32 @iupStrToRGB(i8* %0, i8* nocapture writeonly %1, i8* nocapture writeonly %2, i8* nocapture writeonly %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%9 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%10 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%11 = icmp eq i8* %0, null
br i1 %11, label %35, label %12
12: ; preds = %4
%13 = load i8, i8* %0
%14 = icmp eq i8 %13, 35
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = getelementptr inbounds i8, i8* %0, i64 1
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %5, i32* %6, i32* %7)
%18 = icmp eq i32 %17, 3
br i1 %18, label %22, label %35
19: ; preds = %12
%20 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %5, i32* %6, i32* %7)
%21 = icmp eq i32 %20, 3
br i1 %21, label %22, label %35
22: ; preds = %19, %15
%23 = load i32, i32* %5
%24 = icmp ugt i32 %23, 255
%25 = load i32, i32* %6
%26 = icmp ugt i32 %25, 255
%27 = select i1 %24, i1 true, i1 %26
%28 = load i32, i32* %7
%29 = icmp ugt i32 %28, 255
%30 = select i1 %27, i1 true, i1 %29
br i1 %30, label %35, label %31
31: ; preds = %22
%32 = trunc i32 %23 to i8
store i8 %32, i8* %1
%33 = trunc i32 %25 to i8
store i8 %33, i8* %2
%34 = trunc i32 %28 to i8
store i8 %34, i8* %3
br label %35
35: ; preds = %22, %19, %15, %4, %31
%36 = phi i32 [ 1, %31 ], [ 0, %4 ], [ 0, %15 ], [ 0, %19 ], [ 0, %22 ]
ret i32 %36
}