#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 int32_t;

/* Variables and functions */
int strtol(char const *, char **, int);
int32_t Color_parse_hex(const char *s, int32_t default_color, int *err) {
  int32_t ret_color;
  char *tail;
  *err = 1;
  ret_color = strtol(s, &tail, 16);
  if (tail - s == 6)
    *err = 0;
  else if (tail - s == 3) {
    *err = 0;
    ret_color = ((ret_color & 0xf00) << 12) | ((ret_color & 0xf00) << 8) |
                ((ret_color & 0x0f0) << 8) | ((ret_color & 0x0f0) << 4) |
                ((ret_color & 0x00f) << 4) | ((ret_color & 0x00f) << 0);
  } else
    ret_color = default_color;
  return ret_color;
}


x86 assembly (clang, -O0):
<Color_parse_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x6,%rax
jne    1166 <Color_parse_hex+0x56>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
jmp    11e3 <Color_parse_hex+0xd3>
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x3,%rax
jne    11d8 <Color_parse_hex+0xc8>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x1c(%rbp),%eax
and    $0xf00,%eax
shl    $0xc,%eax
mov    -0x1c(%rbp),%ecx
and    $0xf00,%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x1c(%rbp),%ecx
and    $0xf0,%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x1c(%rbp),%ecx
and    $0xf0,%ecx
shl    $0x4,%ecx
or     %ecx,%eax
mov    -0x1c(%rbp),%ecx
and    $0xf,%ecx
shl    $0x4,%ecx
or     %ecx,%eax
mov    -0x1c(%rbp),%ecx
and    $0xf,%ecx
shl    $0x0,%ecx
or     %ecx,%eax
mov    %eax,-0x1c(%rbp)
jmp    11de <Color_parse_hex+0xce>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11e3 <Color_parse_hex+0xd3>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Color_parse_hex>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %esi,%ebx
mov    %rdi,%r15
movl   $0x1,(%rdx)
lea    0x8(%rsp),%rsi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    0x8(%rsp),%rcx
sub    %r15,%rcx
cmp    $0x3,%rcx
je     1155 <Color_parse_hex+0x45>
cmp    $0x6,%rcx
jne    118a <Color_parse_hex+0x7a>
movl   $0x0,(%r14)
mov    %eax,%ebx
jmp    118a <Color_parse_hex+0x7a>
movl   $0x0,(%r14)
mov    %eax,%ecx
and    $0xf00,%ecx
imul   $0x1100,%ecx,%ecx
mov    %eax,%edx
and    $0xf0,%edx
mov    %edx,%esi
shl    $0x8,%esi
or     %ecx,%esi
shl    $0x4,%edx
or     %esi,%edx
and    $0xf,%eax
mov    %eax,%ebx
shl    $0x4,%ebx
or     %edx,%ebx
or     %eax,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @Color_parse_hex(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%9 = load i32*, i32** %6
store i32 1, i32* %9
%10 = load i8*, i8** %4
%11 = call i32 @strtol(i8* %10, i8** %8, i32 16)
store i32 %11, i32* %7
%12 = load i8*, i8** %8
%13 = load i8*, i8** %4
%14 = ptrtoint i8* %12 to i64
%15 = ptrtoint i8* %13 to i64
%16 = sub i64 %14, %15
%17 = icmp eq i64 %16, 6
br i1 %17, label %18, label %20
18: ; preds = %3
%19 = load i32*, i32** %6
store i32 0, i32* %19
br label %55
20: ; preds = %3
%21 = load i8*, i8** %8
%22 = load i8*, i8** %4
%23 = ptrtoint i8* %21 to i64
%24 = ptrtoint i8* %22 to i64
%25 = sub i64 %23, %24
%26 = icmp eq i64 %25, 3
br i1 %26, label %27, label %52
27: ; preds = %20
%28 = load i32*, i32** %6
store i32 0, i32* %28
%29 = load i32, i32* %7
%30 = and i32 %29, 3840
%31 = shl i32 %30, 12
%32 = load i32, i32* %7
%33 = and i32 %32, 3840
%34 = shl i32 %33, 8
%35 = or i32 %31, %34
%36 = load i32, i32* %7
%37 = and i32 %36, 240
%38 = shl i32 %37, 8
%39 = or i32 %35, %38
%40 = load i32, i32* %7
%41 = and i32 %40, 240
%42 = shl i32 %41, 4
%43 = or i32 %39, %42
%44 = load i32, i32* %7
%45 = and i32 %44, 15
%46 = shl i32 %45, 4
%47 = or i32 %43, %46
%48 = load i32, i32* %7
%49 = and i32 %48, 15
%50 = shl i32 %49, 0
%51 = or i32 %47, %50
store i32 %51, i32* %7
br label %54
52: ; preds = %20
%53 = load i32, i32* %5
store i32 %53, i32* %7
br label %54
54: ; preds = %52, %27
br label %55
55: ; preds = %54, %18
%56 = load i32, i32* %7
ret i32 %56
}

LLVM IR (-O2):
define i32 @Color_parse_hex(i8* %0, i32 %1, i32* nocapture writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i32 1, i32* %2
%6 = call i32 @strtol(i8* %0, i8** %4, i32 16)
%7 = load i8*, i8** %4
%8 = ptrtoint i8* %7 to i64
%9 = ptrtoint i8* %0 to i64
%10 = sub i64 %8, %9
switch i64 %10, label %24 [
i64 6, label %11
i64 3, label %12
]
11: ; preds = %3
store i32 0, i32* %2
br label %24
12: ; preds = %3
store i32 0, i32* %2
%13 = and i32 %6, 3840
%14 = mul nuw nsw i32 %13, 4352
%15 = and i32 %6, 240
%16 = shl nuw nsw i32 %15, 8
%17 = or i32 %14, %16
%18 = shl nuw nsw i32 %15, 4
%19 = or i32 %17, %18
%20 = and i32 %6, 15
%21 = shl nuw nsw i32 %20, 4
%22 = or i32 %19, %21
%23 = or i32 %22, %20
br label %24
24: ; preds = %3, %12, %11
%25 = phi i32 [ %6, %11 ], [ %23, %12 ], [ %1, %3 ]
ret i32 %25
}