#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*/ nsvg__isspace(char const);
int /*<<< orphan*/ sscanf(char const *, char *, unsigned int *);
unsigned int nsvg__parseColorHex(const char *str) {
  unsigned int c = 0, r = 0, g = 0, b = 0;
  int n = 0;
  str++;
  while (str[n] && !nsvg__isspace(str[n]))
    n++;
  if (n == 6) {
    sscanf(str, "%x", &c);
  } else if (n == 3) {
    sscanf(str, "%x", &c);
    c = (c & 0xf) | ((c & 0xf0) << 4) | ((c & 0xf00) << 8);
    c |= c << 4;
  }
  r = (c >> 16) & 0xff;
  g = (c >> 8) & 0xff;
  b = c & 0xff;
  return (((unsigned int)r) | ((unsigned int)g << 8) | ((unsigned int)b << 16));
}


x86 assembly (clang, -O0):
<nsvg__parseColorHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
je     1191 <nsvg__parseColorHex+0x71>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <nsvg__isspace@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11a1 <nsvg__parseColorHex+0x81>
jmp    11af <nsvg__parseColorHex+0x8f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115b <nsvg__parseColorHex+0x3b>
cmpl   $0x6,-0x1c(%rbp)
jne    11d2 <nsvg__parseColorHex+0xb2>
mov    -0x8(%rbp),%rdi
lea    0xe3c(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1030 <sscanf@plt>
jmp    1226 <nsvg__parseColorHex+0x106>
cmpl   $0x3,-0x1c(%rbp)
jne    1221 <nsvg__parseColorHex+0x101>
mov    -0x8(%rbp),%rdi
lea    0xe19(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1030 <sscanf@plt>
mov    -0xc(%rbp),%eax
and    $0xf,%eax
mov    -0xc(%rbp),%ecx
and    $0xf0,%ecx
shl    $0x4,%ecx
or     %ecx,%eax
mov    -0xc(%rbp),%ecx
and    $0xf00,%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x4,%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1226 <nsvg__parseColorHex+0x106>
mov    -0xc(%rbp),%eax
shr    $0x10,%eax
and    $0xff,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x14(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x18(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nsvg__parseColorHex>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
mov    0x1(%rdi),%al
test   %al,%al
je     1190 <nsvg__parseColorHex+0x70>
mov    %rdi,%r15
lea    0x1(%rdi),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1040 <nsvg__isspace@plt>
test   %eax,%eax
jne    116a <nsvg__parseColorHex+0x4a>
movzbl 0x2(%r15,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
jne    1150 <nsvg__parseColorHex+0x30>
cmp    $0x3,%ebx
je     1194 <nsvg__parseColorHex+0x74>
xor    %eax,%eax
cmp    $0x6,%ebx
jne    11d0 <nsvg__parseColorHex+0xb0>
lea    0xe83(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %r14,%rdi
call   1030 <sscanf@plt>
mov    0xc(%rsp),%eax
jmp    11d0 <nsvg__parseColorHex+0xb0>
xor    %eax,%eax
jmp    11d0 <nsvg__parseColorHex+0xb0>
lea    0xe65(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %r14,%rdi
call   1030 <sscanf@plt>
mov    0xc(%rsp),%ecx
mov    %ecx,%eax
and    $0xf,%eax
mov    %ecx,%edx
shl    $0x4,%edx
and    $0xf00,%edx
or     %eax,%edx
shl    $0x8,%ecx
and    $0xf0000,%ecx
or     %edx,%ecx
mov    %ecx,%eax
shl    $0x4,%eax
or     %ecx,%eax
mov    %eax,%ecx
shr    $0x10,%ecx
movzbl %cl,%ecx
mov    %eax,%edx
and    $0xff00,%edx
or     %ecx,%edx
movzbl %al,%eax
shl    $0x10,%eax
or     %edx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%x\00"
define i32 @nsvg__parseColorHex(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%8 = load i8*, i8** %2
%9 = getelementptr inbounds i8, i8* %8, i32 1
store i8* %9, i8** %2
br label %10
10: ; preds = %29, %1
%11 = load i8*, i8** %2
%12 = load i32, i32* %7
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %10
%19 = load i8*, i8** %2
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = call i32 @nsvg__isspace(i8 signext %23)
%25 = icmp ne i32 %24, 0
%26 = xor i1 %25, true
br label %27
27: ; preds = %18, %10
%28 = phi i1 [ false, %10 ], [ %26, %18 ]
br i1 %28, label %29, label %32
29: ; preds = %27
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %10
32: ; preds = %27
%33 = load i32, i32* %7
%34 = icmp eq i32 %33, 6
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i8*, i8** %2
%37 = call i32 @sscanf(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
br label %59
38: ; preds = %32
%39 = load i32, i32* %7
%40 = icmp eq i32 %39, 3
br i1 %40, label %41, label %58
41: ; preds = %38
%42 = load i8*, i8** %2
%43 = call i32 @sscanf(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%44 = load i32, i32* %3
%45 = and i32 %44, 15
%46 = load i32, i32* %3
%47 = and i32 %46, 240
%48 = shl i32 %47, 4
%49 = or i32 %45, %48
%50 = load i32, i32* %3
%51 = and i32 %50, 3840
%52 = shl i32 %51, 8
%53 = or i32 %49, %52
store i32 %53, i32* %3
%54 = load i32, i32* %3
%55 = shl i32 %54, 4
%56 = load i32, i32* %3
%57 = or i32 %56, %55
store i32 %57, i32* %3
br label %58
58: ; preds = %41, %38
br label %59
59: ; preds = %58, %35
%60 = load i32, i32* %3
%61 = lshr i32 %60, 16
%62 = and i32 %61, 255
store i32 %62, i32* %4
%63 = load i32, i32* %3
%64 = lshr i32 %63, 8
%65 = and i32 %64, 255
store i32 %65, i32* %5
%66 = load i32, i32* %3
%67 = and i32 %66, 255
store i32 %67, i32* %6
%68 = load i32, i32* %4
%69 = load i32, i32* %5
%70 = shl i32 %69, 8
%71 = or i32 %68, %70
%72 = load i32, i32* %6
%73 = shl i32 %72, 16
%74 = or i32 %71, %73
ret i32 %74
}

LLVM IR (-O2):
@.str = [3 x i8] c"%x\00"
define i32 @nsvg__parseColorHex(i8* nocapture %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = getelementptr inbounds i8, i8* %0, i64 1
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 0
br i1 %6, label %37, label %7
7: ; preds = %1, %13
%8 = phi i64 [ %14, %13 ], [ 0, %1 ]
%9 = phi i8 [ %17, %13 ], [ %5, %1 ]
%10 = phi i32 [ %15, %13 ], [ 0, %1 ]
%11 = tail call i32 @nsvg__isspace(i8 signext %9)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %7
%14 = add nuw i64 %8, 1
%15 = add nuw nsw i32 %10, 1
%16 = getelementptr inbounds i8, i8* %4, i64 %14
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %21, label %7
19: ; preds = %7
%20 = trunc i64 %8 to i32
br label %21
21: ; preds = %13, %19
%22 = phi i32 [ %20, %19 ], [ %15, %13 ]
switch i32 %22, label %37 [
i32 6, label %23
i32 3, label %26
]
23: ; preds = %21
%24 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%25 = load i32, i32* %2
br label %37
26: ; preds = %21
%27 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%28 = load i32, i32* %2
%29 = and i32 %28, 15
%30 = shl i32 %28, 4
%31 = and i32 %30, 3840
%32 = or i32 %31, %29
%33 = shl i32 %28, 8
%34 = and i32 %33, 983040
%35 = or i32 %32, %34
%36 = mul nuw nsw i32 %35, 17
br label %37
37: ; preds = %1, %21, %26, %23
%38 = phi i32 [ 0, %21 ], [ %36, %26 ], [ %25, %23 ], [ 0, %1 ]
%39 = lshr i32 %38, 16
%40 = and i32 %39, 255
%41 = and i32 %38, 65280
%42 = or i32 %40, %41
%43 = shl i32 %38, 16
%44 = and i32 %43, 16711680
%45 = or i32 %42, %44
ret i32 %45
}