#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 atoi(char *);
char *ext_arg(char *, char *);
int /*<<< orphan*/ printf(char *, char *, int);
double fun_rgb_hex(char *S) {
  char *tmp = S;
  char arg[50];
  int args[3] = {0, 0, 0};
  for (int i = 0; i < 3; i++) {
    tmp = ext_arg(tmp, arg);
    args[i] = (atoi(arg));
  }
  printf("\nRgb(%s) to Hex is %#x\n\n", S,
         (args[0] << 16) + (args[1] << 8) + args[2]);
  return (args[0] << 16) + (args[1] << 8) + args[2];
}


x86 assembly (clang, -O0):
<fun_rgb_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x5c(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
movl   $0x0,-0x60(%rbp)
cmpl   $0x3,-0x60(%rbp)
jge    11a7 <fun_rgb_hex+0x67>
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1030 <ext_arg@plt>
mov    %rax,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
movslq -0x60(%rbp),%rax
mov    %ecx,-0x5c(%rbp,%rax,4)
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    116b <fun_rgb_hex+0x2b>
mov    -0x8(%rbp),%rsi
mov    -0x5c(%rbp),%edx
shl    $0x10,%edx
mov    -0x58(%rbp),%eax
shl    $0x8,%eax
add    %eax,%edx
add    -0x54(%rbp),%edx
lea    0xe3d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x5c(%rbp),%eax
shl    $0x10,%eax
mov    -0x58(%rbp),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
add    -0x54(%rbp),%eax
cvtsi2sd %eax,%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fun_rgb_hex>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%r14
mov    %rsp,%r12
mov    %r12,%rsi
call   1030 <ext_arg@plt>
mov    %rax,%r15
mov    %r12,%rdi
call   1050 <atoi@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <ext_arg@plt>
mov    %rax,%r15
mov    %r12,%rdi
call   1050 <atoi@plt>
mov    %eax,%ebx
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <ext_arg@plt>
mov    %r12,%rdi
call   1050 <atoi@plt>
shl    $0x10,%ebp
shl    $0x8,%ebx
add    %ebp,%ebx
add    %eax,%ebx
lea    0xe6d(%rip),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <printf@plt>
cvtsi2sd %ebx,%xmm0
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"\0ARgb(%s) to Hex is %#x\0A\0A\00"
define double @fun_rgb_hex(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [50 x i8]
%5 = alloca [3 x i32]
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
store i8* %7, i8** %3
%8 = bitcast [3 x i32]* %5 to i8*
store i32 0, i32* %6
br label %9
9: ; preds = %21, %1
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %24
12: ; preds = %9
%13 = load i8*, i8** %3
%14 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%15 = call i8* @ext_arg(i8* %13, i8* %14)
store i8* %15, i8** %3
%16 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%17 = call i32 @atoi(i8* %16)
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 %19
store i32 %17, i32* %20
br label %21
21: ; preds = %12
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %9
24: ; preds = %9
%25 = load i8*, i8** %2
%26 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 0
%27 = load i32, i32* %26
%28 = shl i32 %27, 16
%29 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 1
%30 = load i32, i32* %29
%31 = shl i32 %30, 8
%32 = add nsw i32 %28, %31
%33 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 2
%34 = load i32, i32* %33
%35 = add nsw i32 %32, %34
%36 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %25, i32 %35)
%37 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 0
%38 = load i32, i32* %37
%39 = shl i32 %38, 16
%40 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 1
%41 = load i32, i32* %40
%42 = shl i32 %41, 8
%43 = add nsw i32 %39, %42
%44 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 2
%45 = load i32, i32* %44
%46 = add nsw i32 %43, %45
%47 = sitofp i32 %46 to double
ret double %47
}

LLVM IR (-O2):
@.str = [25 x i8] c"\0ARgb(%s) to Hex is %#x\0A\0A\00"
define double @fun_rgb_hex(i8* %0) {
%2 = alloca [50 x i8]
%3 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%4 = call i8* @ext_arg(i8* %0, i8* %3)
%5 = call i32 @atoi(i8* %3)
%6 = call i8* @ext_arg(i8* %4, i8* %3)
%7 = call i32 @atoi(i8* %3)
%8 = call i8* @ext_arg(i8* %6, i8* %3)
%9 = call i32 @atoi(i8* %3)
%10 = shl i32 %5, 16
%11 = shl i32 %7, 8
%12 = add nsw i32 %11, %10
%13 = add nsw i32 %12, %9
%14 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %13)
%15 = sitofp i32 %13 to double
ret double %15
}