#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, int, int);
int /*<<< orphan*/ scanf(char *, char *);
int strtol(char *, int /*<<< orphan*/ *, int);
void hex_to_dec() {
  char RGB[8];
  int i, j;
  char threeRGB[3][3];
  int array[3];
  scanf("%s", RGB);
  for (i = 1; i < 7; i += 2) {
    for (j = 0; j < 2; j++) {
      threeRGB[(i - 1) / 2][j] = RGB[i + j];
    }
    threeRGB[(i - 1) / 2][j] = '\0';
  }
  for (i = 0; i < 3; i++) {
    array[i] = strtol(threeRGB[i], NULL, 16);
  }
  printf("rgb(%d, %d, %d)", array[0], array[1], array[2]);
}


x86 assembly (clang, -O0):
<hex_to_dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x8(%rbp),%rsi
lea    0xebd(%rip),%rdi
call   1050 <scanf@plt>
movl   $0x1,-0xc(%rbp)
cmpl   $0x7,-0xc(%rbp)
jge    11df <hex_to_dec+0xaf>
movl   $0x0,-0x10(%rbp)
cmpl   $0x2,-0x10(%rbp)
jge    11ad <hex_to_dec+0x7d>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
cltq
mov    -0x8(%rbp,%rax,1),%al
mov    %al,-0x29(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x29(%rbp),%dl
movslq %eax,%rcx
lea    -0x19(%rbp),%rax
imul   $0x3,%rcx,%rcx
add    %rcx,%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1160 <hex_to_dec+0x30>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movslq %eax,%rcx
lea    -0x19(%rbp),%rax
imul   $0x3,%rcx,%rcx
add    %rcx,%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
jmp    114f <hex_to_dec+0x1f>
movl   $0x0,-0xc(%rbp)
cmpl   $0x3,-0xc(%rbp)
jge    1225 <hex_to_dec+0xf5>
movslq -0xc(%rbp),%rax
lea    -0x19(%rbp),%rdi
imul   $0x3,%rax,%rax
add    %rax,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %eax,%ecx
movslq -0xc(%rbp),%rax
mov    %ecx,-0x28(%rbp,%rax,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11e6 <hex_to_dec+0xb6>
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xdce(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_to_dec>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xec1(%rip),%rdi
lea    0x18(%rsp),%rsi
call   1050 <scanf@plt>
movzwl 0x19(%rsp),%eax
movzwl 0x1b(%rsp),%ecx
mov    %ax,0xe(%rsp)
movb   $0x0,0x10(%rsp)
lea    0x11(%rsp),%rbx
mov    %cx,0x11(%rsp)
movb   $0x0,0x13(%rsp)
lea    0x14(%rsp),%r14
movzwl 0x1d(%rsp),%eax
mov    %ax,0x14(%rsp)
movb   $0x0,0x16(%rsp)
lea    0xe(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %eax,%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
lea    0xe49(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %eax,%ecx
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [16 x i8] c"rgb(%d, %d, %d)\00"
define void @hex_to_dec() {
%1 = alloca [8 x i8]
%2 = alloca [3 x [3 x i8]]
%3 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [3 x [3 x i8]], [3 x [3 x i8]]* %2, i64 0, i64 0, i64 0
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 1
%7 = bitcast i8* %6 to i16*
%8 = bitcast [3 x [3 x i8]]* %2 to i16*
%9 = load i16, i16* %7
store i16 %9, i16* %8
%10 = getelementptr inbounds [3 x [3 x i8]], [3 x [3 x i8]]* %2, i64 0, i64 0, i64 2
store i8 0, i8* %10
%11 = getelementptr inbounds [3 x [3 x i8]], [3 x [3 x i8]]* %2, i64 0, i64 1, i64 0
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 3
%13 = bitcast i8* %12 to i16*
%14 = bitcast i8* %11 to i16*
%15 = load i16, i16* %13
store i16 %15, i16* %14
%16 = getelementptr inbounds [3 x [3 x i8]], [3 x [3 x i8]]* %2, i64 0, i64 1, i64 2
store i8 0, i8* %16
%17 = getelementptr inbounds [3 x [3 x i8]], [3 x [3 x i8]]* %2, i64 0, i64 2, i64 0
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 5
%19 = bitcast i8* %18 to i16*
%20 = bitcast i8* %17 to i16*
%21 = load i16, i16* %19
store i16 %21, i16* %20
%22 = getelementptr inbounds [3 x [3 x i8]], [3 x [3 x i8]]* %2, i64 0, i64 2, i64 2
store i8 0, i8* %22
%23 = call i32 @strtol(i8* nocapture %4, i32* null, i32 16)
%24 = call i32 @strtol(i8* nocapture %11, i32* null, i32 16)
%25 = call i32 @strtol(i8* nocapture %17, i32* null, i32 16)
%26 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 %24, i32 %25)
ret void
}