#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*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ my_mp_msg(int, char *, char *, char *);
int mystrtou32(char **, int, int /*<<< orphan*/ *);
int strtocolor(char **q, uint32_t *res) {
  uint32_t color = 0;
  int result;
  char *p = *q;
  if (*p == '&')
    ++p;
  else
    my_mp_msg(7, "MSGL_DBG2", "suspicious color format: \"%s\"\n", p);
  if (*p == 'H' || *p == 'h') {
    ++p;
    result = mystrtou32(&p, 16, &color);
  } else {
    result = mystrtou32(&p, 0, &color);
  }
  {
    unsigned char *tmp = (unsigned char *)(&color);
    unsigned char b;
    b = tmp[0];
    tmp[0] = tmp[3];
    tmp[3] = b;
    b = tmp[1];
    tmp[1] = tmp[2];
    tmp[2] = b;
  }
  if (*p == '&')
    ++p;
  *q = p;
  *res = color;
  return result;
}


x86 assembly (clang, -O0):
<strtocolor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x26,%eax
jne    1163 <strtocolor+0x43>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    117f <strtocolor+0x5f>
mov    -0x20(%rbp),%rcx
mov    $0x7,%edi
lea    0xe8d(%rip),%rsi
lea    0xe90(%rip),%rdx
call   1030 <my_mp_msg@plt>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x48,%eax
je     119f <strtocolor+0x7f>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x68,%eax
jne    11c5 <strtocolor+0xa5>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x10,%esi
lea    -0x14(%rbp),%rdx
call   1040 <mystrtou32@plt>
mov    %eax,-0x18(%rbp)
jmp    11d7 <strtocolor+0xb7>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
lea    -0x14(%rbp),%rdx
call   1040 <mystrtou32@plt>
mov    %eax,-0x18(%rbp)
lea    -0x14(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x29(%rbp)
mov    -0x28(%rbp),%rax
mov    0x3(%rax),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x29(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x28(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x29(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2(%rax),%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x29(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x26,%eax
jne    123d <strtocolor+0x11d>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtocolor>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movl   $0x0,0x4(%rsp)
mov    (%rdi),%rbx
mov    %rbx,0x8(%rsp)
cmpb   $0x26,(%rbx)
jne    114f <strtocolor+0x2f>
add    $0x1,%rbx
mov    %rbx,0x8(%rsp)
jmp    116a <strtocolor+0x4a>
lea    0xeaa(%rip),%rsi
lea    0xead(%rip),%rdx
mov    $0x7,%edi
mov    %rbx,%rcx
call   1030 <my_mp_msg@plt>
mov    (%rbx),%al
or     $0x20,%al
cmp    $0x68,%al
jne    1182 <strtocolor+0x62>
add    $0x1,%rbx
mov    %rbx,0x8(%rsp)
mov    $0x10,%esi
jmp    1184 <strtocolor+0x64>
xor    %esi,%esi
lea    0x8(%rsp),%rdi
lea    0x4(%rsp),%rdx
call   1040 <mystrtou32@plt>
mov    0x4(%rsp),%cl
mov    0x7(%rsp),%dl
mov    %dl,0x4(%rsp)
mov    %cl,0x7(%rsp)
rolw   $0x8,0x5(%rsp)
mov    0x8(%rsp),%rcx
xor    %edx,%edx
cmpb   $0x26,(%rcx)
sete   %dl
add    %rcx,%rdx
mov    %rdx,(%r15)
mov    0x4(%rsp),%ecx
mov    %ecx,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [10 x i8] c"MSGL_DBG2\00"
@.str.1 = [31 x i8] c"suspicious color format: \22%s\22\0A\00"
define i32 @strtocolor(i8** nocapture %0, i32* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = bitcast i8** %4 to i8*
%7 = load i8*, i8** %0
store i8* %7, i8** %4
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 38
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = getelementptr inbounds i8, i8* %7, i64 1
store i8* %11, i8** %4
br label %14
12: ; preds = %2
%13 = tail call i32 @my_mp_msg(i32 7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %14
14: ; preds = %12, %10
%15 = phi i8* [ %7, %12 ], [ %11, %10 ]
%16 = load i8, i8* %15
switch i8 %16, label %19 [
i8 72, label %17
i8 104, label %17
]
17: ; preds = %14, %14
%18 = getelementptr inbounds i8, i8* %15, i64 1
store i8* %18, i8** %4
br label %19
19: ; preds = %14, %17
%20 = phi i32 [ 16, %17 ], [ 0, %14 ]
%21 = call i32 @mystrtou32(i8** %4, i32 %20, i32* %3)
%22 = load i8, i8* %5
%23 = getelementptr inbounds i8, i8* %5, i64 3
%24 = load i8, i8* %23
store i8 %24, i8* %5
store i8 %22, i8* %23
%25 = getelementptr inbounds i8, i8* %5, i64 1
%26 = load i8, i8* %25
%27 = getelementptr inbounds i8, i8* %5, i64 2
%28 = load i8, i8* %27
store i8 %28, i8* %25
store i8 %26, i8* %27
%29 = load i8*, i8** %4
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 38
%32 = zext i1 %31 to i64
%33 = getelementptr i8, i8* %29, i64 %32
store i8* %33, i8** %0
%34 = load i32, i32* %3
store i32 %34, i32* %1
ret i32 %21
}