#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 int /*<<< orphan*/ value;

/* Variables and functions */
int atoi(char const *);
int /*<<< orphan*/ free(char *);
int gui_color_convert_rgb_to_term(int, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
char *strchr(char const *, char);
char *string_strndup(char const *, int);
const char *plugin_api_info_color_rgb2term_cb(const void *pointer, void *data,
                                              const char *info_name,
                                              const char *arguments) {
  static char value[32];
  int rgb, limit;
  char *pos, *color;
  (void)pointer;
  (void)data;
  (void)info_name;
  if (!arguments || !arguments[0])
    return NULL;
  limit = 256;
  pos = strchr(arguments, ',');
  if (pos) {
    color = string_strndup(arguments, pos - arguments);
    if (!color)
      return NULL;
    rgb = atoi(color);
    limit = atoi(pos + 1);
    free(color);
  } else {
    rgb = atoi(arguments);
  }
  snprintf(value, sizeof(value), "%d",
           gui_color_convert_rgb_to_term(rgb, limit));
  return value;
}


x86 assembly (clang, -O0):
<plugin_api_info_color_rgb2term_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1190 <plugin_api_info_color_rgb2term_cb+0x30>
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
jne    119d <plugin_api_info_color_rgb2term_cb+0x3d>
movq   $0x0,-0x8(%rbp)
jmp    1259 <plugin_api_info_color_rgb2term_cb+0xf9>
movl   $0x100,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     121d <plugin_api_info_color_rgb2term_cb+0xbd>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1070 <string_strndup@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11f3 <plugin_api_info_color_rgb2term_cb+0x93>
movq   $0x0,-0x8(%rbp)
jmp    1259 <plugin_api_info_color_rgb2term_cb+0xf9>
mov    -0x40(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
call   1080 <atoi@plt>
mov    %eax,-0x30(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
jmp    1229 <plugin_api_info_color_rgb2term_cb+0xc9>
mov    -0x28(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
call   1060 <gui_color_convert_rgb_to_term@plt>
mov    %eax,%ecx
lea    0x2e23(%rip),%rdi
mov    $0x20,%esi
lea    0xdb7(%rip),%rdx
call   1050 <snprintf@plt>
lea    0x2e0b(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plugin_api_info_color_rgb2term_cb>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rcx,%rcx
je     11c1 <plugin_api_info_color_rgb2term_cb+0x61>
mov    %rcx,%rbx
cmpb   $0x0,(%rcx)
je     11c1 <plugin_api_info_color_rgb2term_cb+0x61>
mov    %rbx,%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11c5 <plugin_api_info_color_rgb2term_cb+0x65>
mov    %rax,%r14
mov    %r14d,%esi
sub    %ebx,%esi
mov    %rbx,%rdi
call   1070 <string_strndup@plt>
test   %rax,%rax
je     11c1 <plugin_api_info_color_rgb2term_cb+0x61>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <atoi@plt>
mov    %eax,%r15d
add    $0x1,%r14
mov    %r14,%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11d5 <plugin_api_info_color_rgb2term_cb+0x75>
xor    %ebx,%ebx
jmp    11fc <plugin_api_info_color_rgb2term_cb+0x9c>
mov    %rbx,%rdi
call   1080 <atoi@plt>
mov    %eax,%r15d
mov    $0x100,%ebp
mov    %r15d,%edi
mov    %ebp,%esi
call   1060 <gui_color_convert_rgb_to_term@plt>
lea    0x2e7a(%rip),%rbx
lea    0xe13(%rip),%rdx
mov    %rbx,%rdi
mov    $0x20,%esi
mov    %eax,%ecx
call   1050 <snprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@plugin_api_info_color_rgb2term_cb.value = internal global [32 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
define i8* @plugin_api_info_color_rgb2term_cb(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%14 = load i8*, i8** %6
%15 = load i8*, i8** %7
%16 = load i8*, i8** %8
%17 = load i8*, i8** %9
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %24
19: ; preds = %4
%20 = load i8*, i8** %9
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = icmp ne i8 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %19, %4
store i8* null, i8** %5
br label %58
25: ; preds = %19
store i32 256, i32* %11
%26 = load i8*, i8** %9
%27 = call i8* @strchr(i8* %26, i8 signext 44)
store i8* %27, i8** %12
%28 = load i8*, i8** %12
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %50
30: ; preds = %25
%31 = load i8*, i8** %9
%32 = load i8*, i8** %12
%33 = load i8*, i8** %9
%34 = ptrtoint i8* %32 to i64
%35 = ptrtoint i8* %33 to i64
%36 = sub i64 %34, %35
%37 = trunc i64 %36 to i32
%38 = call i8* @string_strndup(i8* %31, i32 %37)
store i8* %38, i8** %13
%39 = load i8*, i8** %13
%40 = icmp ne i8* %39, null
br i1 %40, label %42, label %41
41: ; preds = %30
store i8* null, i8** %5
br label %58
42: ; preds = %30
%43 = load i8*, i8** %13
%44 = call i32 @atoi(i8* %43)
store i32 %44, i32* %10
%45 = load i8*, i8** %12
%46 = getelementptr inbounds i8, i8* %45, i64 1
%47 = call i32 @atoi(i8* %46)
store i32 %47, i32* %11
%48 = load i8*, i8** %13
%49 = call i32 @free(i8* %48)
br label %53
50: ; preds = %25
%51 = load i8*, i8** %9
%52 = call i32 @atoi(i8* %51)
store i32 %52, i32* %10
br label %53
53: ; preds = %50, %42
%54 = load i32, i32* %10
%55 = load i32, i32* %11
%56 = call i32 @gui_color_convert_rgb_to_term(i32 %54, i32 %55)
%57 = call i32 @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @plugin_api_info_color_rgb2term_cb.value, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %56)
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @plugin_api_info_color_rgb2term_cb.value, i64 0, i64 0), i8** %5
br label %58
58: ; preds = %53, %41, %24
%59 = load i8*, i8** %5
ret i8* %59
}

LLVM IR (-O2):
@plugin_api_info_color_rgb2term_cb.value = internal global [32 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
define i8* @plugin_api_info_color_rgb2term_cb(i8* nocapture readnone %0, i8* nocapture readnone %1, i8* nocapture readnone %2, i8* %3) {
%5 = icmp eq i8* %3, null
br i1 %5, label %31, label %6
6: ; preds = %4
%7 = load i8, i8* %3
%8 = icmp eq i8 %7, 0
br i1 %8, label %31, label %9
9: ; preds = %6
%10 = tail call i8* @strchr(i8* %3, i8 signext 44)
%11 = icmp eq i8* %10, null
br i1 %11, label %24, label %12
12: ; preds = %9
%13 = ptrtoint i8* %10 to i64
%14 = ptrtoint i8* %3 to i64
%15 = sub i64 %13, %14
%16 = trunc i64 %15 to i32
%17 = tail call i8* @string_strndup(i8* %3, i32 %16)
%18 = icmp eq i8* %17, null
br i1 %18, label %31, label %19
19: ; preds = %12
%20 = tail call i32 @atoi(i8* %17)
%21 = getelementptr inbounds i8, i8* %10, i64 1
%22 = tail call i32 @atoi(i8* %21)
%23 = tail call i32 @free(i8* %17)
br label %26
24: ; preds = %9
%25 = tail call i32 @atoi(i8* %3)
br label %26
26: ; preds = %24, %19
%27 = phi i32 [ %22, %19 ], [ 256, %24 ]
%28 = phi i32 [ %20, %19 ], [ %25, %24 ]
%29 = tail call i32 @gui_color_convert_rgb_to_term(i32 %28, i32 %27)
%30 = tail call i32 @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @plugin_api_info_color_rgb2term_cb.value, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %12, %4, %6, %26
%32 = phi i8* [ getelementptr inbounds ([32 x i8], [32 x i8]* @plugin_api_info_color_rgb2term_cb.value, i64 0, i64 0), %26 ], [ null, %6 ], [ null, %4 ], [ null, %12 ]
ret i8* %32
}