#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*/ sscanf(char const *, char *, int *, char *, int *, char *,
                          int *);
scalar_t__ strchr(char *, char);
unsigned int nsvg__parseColorRGB(const char *str) {
  int r = -1, g = -1, b = -1;
  char s1[32] = "", s2[32] = "";
  sscanf(str + 4, "%d%[%%, \t]%d%[%%, \t]%d", &r, s1, &g, s2, &b);
  if (strchr(s1, '%')) {
    return (((unsigned int)(r * 255) / 100) |
            ((unsigned int)(g * 255) / 100 << 8) |
            ((unsigned int)(b * 255) / 100 << 16));
  } else {
    return (((unsigned int)r) | ((unsigned int)g << 8) |
            ((unsigned int)b << 16));
  }
}


x86 assembly (clang, -O0):
<nsvg__parseColorRGB>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
add    $0x4,%rdi
lea    -0x40(%rbp),%rcx
lea    -0x60(%rbp),%r9
lea    0xe78(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%r8
lea    -0x1c(%rbp),%rax
mov    %rax,(%rsp)
call   1050 <sscanf@plt>
lea    -0x40(%rbp),%rdi
mov    $0x25,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     1207 <nsvg__parseColorRGB+0xd7>
imul   $0xff,-0x14(%rbp),%eax
mov    $0x64,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x68(%rbp)
imul   $0xff,-0x18(%rbp),%eax
mov    $0x64,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
mov    -0x68(%rbp),%eax
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x64(%rbp)
imul   $0xff,-0x1c(%rbp),%eax
mov    $0x64,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
mov    -0x64(%rbp),%eax
shl    $0x10,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    121d <nsvg__parseColorRGB+0xed>
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x1c(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nsvg__parseColorRGB>:
push   %rbx
sub    $0x60,%rsp
movl   $0xffffffff,0x1c(%rsp)
ff
movl   $0xffffffff,0x18(%rsp)
ff
movl   $0xffffffff,0x14(%rsp)
ff
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
add    $0x4,%rdi
lea    0x14(%rsp),%rax
mov    %rax,(%rsp)
lea    0xe98(%rip),%rsi
lea    0x1c(%rsp),%rdx
lea    0x40(%rsp),%rbx
lea    0x18(%rsp),%r8
lea    0x20(%rsp),%r9
mov    %rbx,%rcx
call   1040 <sscanf@plt>
mov    %rbx,%rdi
mov    $0x25,%esi
call   1030 <strchr@plt>
mov    0x1c(%rsp),%edx
test   %rax,%rax
je     11e2 <nsvg__parseColorRGB+0xc2>
mov    %edx,%eax
shl    $0x8,%eax
sub    %edx,%eax
imul   $0x51eb851f,%rax,%rax
shr    $0x25,%rax
mov    0x18(%rsp),%ecx
mov    %ecx,%edx
shl    $0x8,%edx
sub    %ecx,%edx
imul   $0x51eb851f,%rdx,%rcx
shr    $0x20,%rcx
and    $0xffffffe0,%ecx
shl    $0x3,%ecx
or     %eax,%ecx
mov    0x14(%rsp),%eax
mov    %eax,%edx
shl    $0x8,%edx
sub    %eax,%edx
imul   $0x51eb851f,%rdx,%rax
shr    $0x25,%rax
jmp    11ef <nsvg__parseColorRGB+0xcf>
mov    0x18(%rsp),%ecx
shl    $0x8,%ecx
or     %edx,%ecx
mov    0x14(%rsp),%eax
shl    $0x10,%eax
or     %ecx,%eax
add    $0x60,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"%d%[%%, \09]%d%[%%, \09]%d\00"
define i32 @nsvg__parseColorRGB(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [32 x i8]
%8 = alloca [32 x i8]
store i8* %0, i8** %3
store i32 -1, i32* %4
store i32 -1, i32* %5
store i32 -1, i32* %6
%9 = bitcast [32 x i8]* %7 to i8*
%10 = bitcast [32 x i8]* %8 to i8*
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 4
%13 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%15 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32* %4, i8* %13, i32* %5, i8* %14, i32* %6)
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%17 = call i64 @strchr(i8* %16, i8 signext 37)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %33
19: ; preds = %1
%20 = load i32, i32* %4
%21 = mul nsw i32 %20, 255
%22 = udiv i32 %21, 100
%23 = load i32, i32* %5
%24 = mul nsw i32 %23, 255
%25 = udiv i32 %24, 100
%26 = shl i32 %25, 8
%27 = or i32 %22, %26
%28 = load i32, i32* %6
%29 = mul nsw i32 %28, 255
%30 = udiv i32 %29, 100
%31 = shl i32 %30, 16
%32 = or i32 %27, %31
store i32 %32, i32* %2
br label %41
33: ; preds = %1
%34 = load i32, i32* %4
%35 = load i32, i32* %5
%36 = shl i32 %35, 8
%37 = or i32 %34, %36
%38 = load i32, i32* %6
%39 = shl i32 %38, 16
%40 = or i32 %37, %39
store i32 %40, i32* %2
br label %41
41: ; preds = %33, %19
%42 = load i32, i32* %2
ret i32 %42
}

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