#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*/ printf(char *, ...);
int rgb_to_hex_help(int);
int strlen(char *);
void rgb_to_hex(char *rgb) {
  int best = 0, rgb_helper = 0, coun = 0, rgb_num, rgb_num1;
  printf("#");
  for (rgb_helper = 0; rgb_helper < strlen(rgb); best = 0) {
    for (; rgb[coun] != ','; coun++, rgb_helper++) {
      if (rgb[coun] != ' ') {
        best = best * 10 + rgb[coun] - '0';
      }
      if (rgb[coun + 1] == '\n') {
        rgb_helper = rgb_helper + 100;
        break;
      }
    }
    rgb_num = best / 16;
    rgb_num1 = best % 16;
    printf("%c", rgb_to_hex_help(rgb_num));
    printf("%c", rgb_to_hex_help(rgb_num1));
    coun++;
    rgb_helper++;
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<rgb_to_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    1277 <rgb_to_hex+0x147>
jmp    1187 <rgb_to_hex+0x57>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2c,%eax
je     120d <rgb_to_hex+0xdd>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
je     11c9 <rgb_to_hex+0x99>
imul   $0xa,-0xc(%rbp),%eax
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
add    %ecx,%eax
sub    $0x30,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11f1 <rgb_to_hex+0xc1>
mov    -0x10(%rbp),%eax
add    $0x64,%eax
mov    %eax,-0x10(%rbp)
jmp    120d <rgb_to_hex+0xdd>
jmp    11f6 <rgb_to_hex+0xc6>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1187 <rgb_to_hex+0x57>
mov    -0xc(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <rgb_to_hex_help@plt>
mov    %eax,%esi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1050 <rgb_to_hex_help@plt>
mov    %eax,%esi
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
jmp    1166 <rgb_to_hex+0x36>
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rgb_to_hex>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x23,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11ea <rgb_to_hex+0xba>
xor    %r12d,%r12d
xor    %ebx,%ebx
jmp    11a6 <rgb_to_hex+0x76>
nopl   0x0(%rax)
add    $0x64,%r12d
lea    0xf(%r15),%edi
test   %r15d,%r15d
cmovns %r15d,%edi
mov    %edi,%eax
and    $0xfffffff0,%eax
sub    %eax,%r15d
sar    $0x4,%edi
call   1050 <rgb_to_hex_help@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
mov    %r15d,%edi
call   1050 <rgb_to_hex_help@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
add    $0x1,%r12d
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %eax,%r12d
jge    11ea <rgb_to_hex+0xba>
movslq %ebx,%rbx
mov    (%r14,%rbx,1),%al
add    $0x1,%rbx
xor    %r15d,%r15d
cmp    $0x20,%al
je     11d3 <rgb_to_hex+0xa3>
nopl   0x0(%rax,%rax,1)
cmp    $0x2c,%al
je     1164 <rgb_to_hex+0x34>
movsbl %al,%eax
lea    (%r15,%r15,4),%ecx
lea    (%rax,%rcx,2),%r15d
add    $0xffffffd0,%r15d
movzbl (%r14,%rbx,1),%eax
cmp    $0xa,%al
je     1160 <rgb_to_hex+0x30>
add    $0x1,%r12d
add    $0x1,%rbx
cmp    $0x20,%al
jne    11c0 <rgb_to_hex+0x90>
jmp    11d3 <rgb_to_hex+0xa3>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
define void @rgb_to_hex(i8* %0) {
%2 = tail call i32 @putchar(i32 35)
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %45
5: ; preds = %1, %32
%6 = phi i32 [ %42, %32 ], [ 0, %1 ]
%7 = phi i64 [ %41, %32 ], [ 0, %1 ]
%8 = shl i64 %7, 32
%9 = ashr exact i64 %8, 32
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
br label %12
12: ; preds = %5, %30
%13 = phi i8 [ %11, %5 ], [ %26, %30 ]
%14 = phi i64 [ %9, %5 ], [ %24, %30 ]
%15 = phi i32 [ %6, %5 ], [ %31, %30 ]
%16 = phi i32 [ 0, %5 ], [ %23, %30 ]
switch i8 %13, label %17 [
i8 44, label %32
i8 32, label %22
]
17: ; preds = %12
%18 = sext i8 %13 to i32
%19 = mul nsw i32 %16, 10
%20 = add i32 %19, -48
%21 = add i32 %20, %18
br label %22
22: ; preds = %12, %17
%23 = phi i32 [ %21, %17 ], [ %16, %12 ]
%24 = add i64 %14, 1
%25 = getelementptr inbounds i8, i8* %0, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 10
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = add nsw i32 %15, 100
br label %32
30: ; preds = %22
%31 = add nsw i32 %15, 1
br label %12
32: ; preds = %12, %28
%33 = phi i32 [ %29, %28 ], [ %15, %12 ]
%34 = phi i32 [ %23, %28 ], [ %16, %12 ]
%35 = sdiv i32 %34, 16
%36 = srem i32 %34, 16
%37 = tail call i32 @rgb_to_hex_help(i32 %35)
%38 = tail call i32 @putchar(i32 %37)
%39 = tail call i32 @rgb_to_hex_help(i32 %36)
%40 = tail call i32 @putchar(i32 %39)
%41 = add i64 %14, 1
%42 = add nsw i32 %33, 1
%43 = tail call i32 @strlen(i8* %0)
%44 = icmp slt i32 %42, %43
br i1 %44, label %5, label %45
45: ; preds = %32, %1
%46 = tail call i32 @putchar(i32 10)
ret void
}