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

/* Variables and functions */
short rgba_from_hex3_string(char const *);
short rgba_from_hex6_string(char const *);
size_t strlen(char const *);
int32_t rgba_from_hex_string(const char *str, short *ok) {
  size_t len = strlen(str);
  *ok = 1;
  if (6 == len)
    return rgba_from_hex6_string(str);
  if (3 == len)
    return rgba_from_hex3_string(str);
  return *ok = 0;
}


x86 assembly (clang, -O0):
<rgba_from_hex_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movw   $0x1,(%rax)
mov    $0x6,%eax
cmp    -0x20(%rbp),%rax
jne    1177 <rgba_from_hex_string+0x47>
mov    -0x10(%rbp),%rdi
call   1040 <rgba_from_hex6_string@plt>
mov    %ax,-0x2(%rbp)
jmp    11a7 <rgba_from_hex_string+0x77>
mov    $0x3,%eax
cmp    -0x20(%rbp),%rax
jne    1198 <rgba_from_hex_string+0x68>
mov    -0x10(%rbp),%rdi
call   1050 <rgba_from_hex3_string@plt>
mov    %ax,-0x2(%rbp)
jmp    11a7 <rgba_from_hex_string+0x77>
mov    -0x18(%rbp),%rax
movw   $0x0,(%rax)
movw   $0x0,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rgba_from_hex_string>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
movw   $0x1,(%r14)
cmp    $0x3,%rax
je     1160 <rgba_from_hex_string+0x30>
cmp    $0x6,%rax
jne    116f <rgba_from_hex_string+0x3f>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <rgba_from_hex6_string@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <rgba_from_hex3_string@plt>
movw   $0x0,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define signext i16 @rgba_from_hex_string(i8* %0, i16* %1) {
%3 = alloca i16
%4 = alloca i8*
%5 = alloca i16*
%6 = alloca i64
store i8* %0, i8** %4
store i16* %1, i16** %5
%7 = load i8*, i8** %4
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %6
%9 = load i16*, i16** %5
store i16 1, i16* %9
%10 = load i64, i64* %6
%11 = icmp eq i64 6, %10
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call signext i16 @rgba_from_hex6_string(i8* %13)
store i16 %14, i16* %3
br label %23
15: ; preds = %2
%16 = load i64, i64* %6
%17 = icmp eq i64 3, %16
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i8*, i8** %4
%20 = call signext i16 @rgba_from_hex3_string(i8* %19)
store i16 %20, i16* %3
br label %23
21: ; preds = %15
%22 = load i16*, i16** %5
store i16 0, i16* %22
store i16 0, i16* %3
br label %23
23: ; preds = %21, %18, %12
%24 = load i16, i16* %3
ret i16 %24
}

LLVM IR (-O2):
define signext i16 @rgba_from_hex_string(i8* %0, i16* nocapture writeonly %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
store i16 1, i16* %1
switch i64 %3, label %8 [
i64 6, label %4
i64 3, label %6
]
4: ; preds = %2
%5 = tail call signext i16 @rgba_from_hex6_string(i8* %0)
br label %9
6: ; preds = %2
%7 = tail call signext i16 @rgba_from_hex3_string(i8* %0)
br label %9
8: ; preds = %2
store i16 0, i16* %1
br label %9
9: ; preds = %8, %6, %4
%10 = phi i16 [ %5, %4 ], [ %7, %6 ], [ 0, %8 ]
ret i16 %10
}