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


x86 assembly (clang, -O0):
<iupStrToRGBA>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0xff,-0x40(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115f <iupStrToRGBA+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    1262 <iupStrToRGBA+0x152>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    11b5 <iupStrToRGBA+0xa5>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7a(%rip),%rsi
lea    -0x34(%rbp),%rdx
lea    -0x38(%rbp),%rcx
lea    -0x3c(%rbp),%r8
lea    -0x40(%rbp),%r9
call   1030 <sscanf@plt>
cmp    $0x3,%eax
jge    11b0 <iupStrToRGBA+0xa0>
movl   $0x0,-0x4(%rbp)
jmp    1262 <iupStrToRGBA+0x152>
jmp    11ef <iupStrToRGBA+0xdf>
mov    -0x10(%rbp),%rdi
lea    0xe4d(%rip),%rsi
lea    -0x34(%rbp),%rdx
lea    -0x38(%rbp),%rcx
lea    -0x3c(%rbp),%r8
lea    -0x40(%rbp),%r9
call   1030 <sscanf@plt>
cmp    $0x3,%eax
jge    11ea <iupStrToRGBA+0xda>
movl   $0x0,-0x4(%rbp)
jmp    1262 <iupStrToRGBA+0x152>
jmp    11ef <iupStrToRGBA+0xdf>
cmpl   $0xff,-0x34(%rbp)
ja     1223 <iupStrToRGBA+0x113>
cmpl   $0xff,-0x38(%rbp)
ja     1223 <iupStrToRGBA+0x113>
cmpl   $0xff,-0x3c(%rbp)
ja     1223 <iupStrToRGBA+0x113>
cmpl   $0xff,-0x40(%rbp)
jbe    122f <iupStrToRGBA+0x11f>
movl   $0x0,-0x4(%rbp)
jmp    1262 <iupStrToRGBA+0x152>
mov    -0x34(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x38(%rbp),%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
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)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iupStrToRGBA>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
movl   $0xff,(%rsp)
xor    %ebx,%ebx
test   %rdi,%rdi
je     11c9 <iupStrToRGBA+0xb9>
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
cmpb   $0x23,(%rdi)
jne    1165 <iupStrToRGBA+0x55>
add    $0x1,%rdi
lea    0xe9d(%rip),%rsi
jmp    116c <iupStrToRGBA+0x5c>
lea    0xea1(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
mov    %rsp,%r9
call   1030 <sscanf@plt>
cmp    $0x3,%eax
jl     11c9 <iupStrToRGBA+0xb9>
mov    0xc(%rsp),%eax
cmp    $0xff,%eax
ja     11c9 <iupStrToRGBA+0xb9>
mov    0x8(%rsp),%ecx
cmp    $0xff,%ecx
ja     11c9 <iupStrToRGBA+0xb9>
mov    0x4(%rsp),%edx
cmp    $0xff,%edx
ja     11c9 <iupStrToRGBA+0xb9>
mov    (%rsp),%esi
cmp    $0xff,%esi
ja     11c9 <iupStrToRGBA+0xb9>
mov    %al,0x0(%r13)
mov    %cl,(%r12)
mov    %dl,(%r15)
mov    %sil,(%r14)
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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