#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 */
scalar_t__ strtoul(char *, char **, int);
int parse_hex_color(char *buff) {
  char *endp = buff;
  int t = (int)strtoul(buff, &endp, 16);
  if (endp != buff)
    return ((t >> 8) & 0xf800) | ((t >> 5) & 0x07e0) | ((t >> 3) & 0x1f);
  return -1;
}


x86 assembly (clang, -O0):
<parse_hex_color>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1030 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1173 <parse_hex_color+0x63>
mov    -0x1c(%rbp),%eax
sar    $0x8,%eax
and    $0xf800,%eax
mov    -0x1c(%rbp),%ecx
sar    $0x5,%ecx
and    $0x7e0,%ecx
or     %ecx,%eax
mov    -0x1c(%rbp),%ecx
sar    $0x3,%ecx
and    $0x1f,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    117a <parse_hex_color+0x6a>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_hex_color>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rdi,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x10,%edx
call   1030 <strtoul@plt>
cmp    %rbx,0x8(%rsp)
je     1155 <parse_hex_color+0x45>
mov    %eax,%ecx
shr    $0x8,%ecx
and    $0xf800,%ecx
mov    %eax,%edx
shr    $0x5,%edx
and    $0x7e0,%edx
or     %ecx,%edx
shr    $0x3,%eax
and    $0x1f,%eax
or     %edx,%eax
jmp    115a <parse_hex_color+0x4a>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @parse_hex_color(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
store i8* %6, i8** %4
%7 = load i8*, i8** %3
%8 = call i64 @strtoul(i8* %7, i8** %4, i32 16)
%9 = trunc i64 %8 to i32
store i32 %9, i32* %5
%10 = load i8*, i8** %4
%11 = load i8*, i8** %3
%12 = icmp ne i8* %10, %11
br i1 %12, label %13, label %25
13: ; preds = %1
%14 = load i32, i32* %5
%15 = ashr i32 %14, 8
%16 = and i32 %15, 63488
%17 = load i32, i32* %5
%18 = ashr i32 %17, 5
%19 = and i32 %18, 2016
%20 = or i32 %16, %19
%21 = load i32, i32* %5
%22 = ashr i32 %21, 3
%23 = and i32 %22, 31
%24 = or i32 %20, %23
store i32 %24, i32* %2
br label %26
25: ; preds = %1
store i32 -1, i32* %2
br label %26
26: ; preds = %25, %13
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
define i32 @parse_hex_color(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* %0, i8** %2
%4 = call i64 @strtoul(i8* %0, i8** %2, i32 16)
%5 = trunc i64 %4 to i32
%6 = load i8*, i8** %2
%7 = icmp eq i8* %6, %0
br i1 %7, label %17, label %8
8: ; preds = %1
%9 = lshr i32 %5, 8
%10 = and i32 %9, 63488
%11 = lshr i32 %5, 5
%12 = and i32 %11, 2016
%13 = or i32 %10, %12
%14 = lshr i32 %5, 3
%15 = and i32 %14, 31
%16 = or i32 %13, %15
br label %17
17: ; preds = %1, %8
%18 = phi i32 [ %16, %8 ], [ -1, %1 ]
ret i32 %18
}