#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*/ sprintf(char *, char *, unsigned char const,
                           unsigned char const, unsigned char const);
void RGB2Hex(unsigned char const aRGB[3], char aoResultHexRGB[8]) {
  if (aoResultHexRGB) {
    if (aRGB) {
      sprintf(aoResultHexRGB, "#%02hhx%02hhx%02hhx", aRGB[0], aRGB[1], aRGB[2]);
    } else {
      aoResultHexRGB[0] = 0;
      aoResultHexRGB[1] = 0;
      aoResultHexRGB[2] = 0;
    }
  }
}


x86 assembly (clang, -O0):
<RGB2Hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1183 <RGB2Hex+0x73>
cmpq   $0x0,-0x8(%rbp)
je     1167 <RGB2Hex+0x57>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%dl
mov    -0x8(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x8(%rbp),%rax
lea    0xeae(%rip),%rsi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl 0x2(%rax),%r8d
call   1030 <sprintf@plt>
jmp    117e <RGB2Hex+0x6e>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x2(%rax)
jmp    1183 <RGB2Hex+0x73>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RGB2Hex>:
test   %rsi,%rsi
je     1141 <RGB2Hex+0x31>
test   %rdi,%rdi
je     1138 <RGB2Hex+0x28>
movzbl (%rdi),%edx
movzbl 0x1(%rdi),%ecx
movzbl 0x2(%rdi),%r8d
lea    0xed3(%rip),%rax
mov    %rsi,%rdi
mov    %rax,%rsi
jmp    1030 <sprintf@plt>
movw   $0x0,(%rsi)
movb   $0x0,0x2(%rsi)
ret

LLVM IR (-O0):
@.str = [20 x i8] c"#%02hhx%02hhx%02hhx\00"
define void @RGB2Hex(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%5 = load i8*, i8** %4
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %30
7: ; preds = %2
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %22
10: ; preds = %7
%11 = load i8*, i8** %4
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i8, i8* %16
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 2
%20 = load i8, i8* %19
%21 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8 zeroext %14, i8 zeroext %17, i8 zeroext %20)
br label %29
22: ; preds = %7
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i64 0
store i8 0, i8* %24
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 1
store i8 0, i8* %26
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i64 2
store i8 0, i8* %28
br label %29
29: ; preds = %22, %10
br label %30
30: ; preds = %29, %2
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"#%02hhx%02hhx%02hhx\00"
define void @RGB2Hex(i8* %0, i8* writeonly %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %16, label %4
4: ; preds = %2
%5 = icmp eq i8* %0, null
br i1 %5, label %13, label %6
6: ; preds = %4
%7 = load i8, i8* %0
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = load i8, i8* %8
%10 = getelementptr inbounds i8, i8* %0, i64 2
%11 = load i8, i8* %10
%12 = tail call i32 @sprintf(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8 zeroext %7, i8 zeroext %9, i8 zeroext %11)
br label %16
13: ; preds = %4
store i8 0, i8* %1
%14 = getelementptr inbounds i8, i8* %1, i64 1
store i8 0, i8* %14
%15 = getelementptr inbounds i8, i8* %1, i64 2
store i8 0, i8* %15
br label %16
16: ; preds = %6, %13, %2
ret void
}