#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*/ FILE;

/* Variables and functions */
char *color_to_str(short);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
scalar_t__ get_idc_bg(short);
scalar_t__ get_idc_fg(short);
int /*<<< orphan*/ pair_content(short, short *, short *);
void emit_colorpair(FILE *fh, short pair) {
  char *fg_str = NULL, *bg_str = NULL;
  short cfg = 0, cbg = 0;
  pair_content(pair, &cfg, &cbg);
  if (cfg == cbg || pair == 0) {
    fprintf(fh, "default,default");
    return;
  }
  fg_str = get_idc_fg(pair) ? color_to_str(-1) : color_to_str(cfg);
  bg_str = get_idc_bg(pair) ? color_to_str(-1) : color_to_str(cbg);
  fprintf(fh, "%s,%s", fg_str, bg_str);
  free(bg_str);
  free(fg_str);
}


x86 assembly (clang, -O0):
<emit_colorpair>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movw   $0x0,-0x22(%rbp)
movw   $0x0,-0x24(%rbp)
lea    -0x22(%rbp),%rsi
lea    -0x24(%rbp),%rdx
movswl -0xa(%rbp),%edi
call   1050 <pair_content@plt>
movswl -0x22(%rbp),%eax
movswl -0x24(%rbp),%ecx
cmp    %ecx,%eax
je     11bd <emit_colorpair+0x5d>
movswl -0xa(%rbp),%eax
cmp    $0x0,%eax
jne    11d4 <emit_colorpair+0x74>
mov    -0x8(%rbp),%rdi
lea    0xe38(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1276 <emit_colorpair+0x116>
movswl -0xa(%rbp),%edi
call   1070 <get_idc_fg@plt>
cmp    $0x0,%rax
je     11fa <emit_colorpair+0x9a>
mov    $0xffffffff,%edi
call   1080 <color_to_str@plt>
mov    %rax,-0x30(%rbp)
jmp    1207 <emit_colorpair+0xa7>
movswl -0x22(%rbp),%edi
call   1080 <color_to_str@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
movswl -0xa(%rbp),%edi
call   1030 <get_idc_bg@plt>
cmp    $0x0,%rax
je     1235 <emit_colorpair+0xd5>
mov    $0xffffffff,%edi
call   1080 <color_to_str@plt>
mov    %rax,-0x38(%rbp)
jmp    1242 <emit_colorpair+0xe2>
movswl -0x24(%rbp),%edi
call   1080 <color_to_str@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xdb3(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<emit_colorpair>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
movw   $0x0,0xe(%rsp)
movw   $0x0,0xc(%rsp)
lea    0xe(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1050 <pair_content@plt>
test   %bx,%bx
je     1211 <emit_colorpair+0xa1>
movzwl 0xc(%rsp),%eax
cmp    %ax,0xe(%rsp)
je     1211 <emit_colorpair+0xa1>
movswl %bx,%ebp
mov    %ebp,%edi
call   1070 <get_idc_fg@plt>
neg    %rax
sbb    %eax,%eax
or     0xe(%rsp),%ax
movswl %ax,%edi
call   1090 <color_to_str@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1030 <get_idc_bg@plt>
neg    %rax
sbb    %eax,%eax
or     0xc(%rsp),%ax
movswl %ax,%edi
call   1090 <color_to_str@plt>
mov    %rax,%rbp
lea    0xe21(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbp,%rdi
call   1040 <free@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
jmp    122a <emit_colorpair+0xba>
lea    0xde8(%rip),%rdi
mov    $0xf,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1080 <fwrite@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"default,default\00"
@.str.1 = [6 x i8] c"%s,%s\00"
define void @emit_colorpair(i32* %0, i16 signext %1) {
%3 = alloca i32*
%4 = alloca i16
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i16
%8 = alloca i16
store i32* %0, i32** %3
store i16 %1, i16* %4
store i8* null, i8** %5
store i8* null, i8** %6
store i16 0, i16* %7
store i16 0, i16* %8
%9 = load i16, i16* %4
%10 = call i32 @pair_content(i16 signext %9, i16* %7, i16* %8)
%11 = load i16, i16* %7
%12 = sext i16 %11 to i32
%13 = load i16, i16* %8
%14 = sext i16 %13 to i32
%15 = icmp eq i32 %12, %14
br i1 %15, label %20, label %16
16: ; preds = %2
%17 = load i16, i16* %4
%18 = sext i16 %17 to i32
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16, %2
%21 = load i32*, i32** %3
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %52
23: ; preds = %16
%24 = load i16, i16* %4
%25 = call i64 @get_idc_fg(i16 signext %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i8* @color_to_str(i16 signext -1)
br label %32
29: ; preds = %23
%30 = load i16, i16* %7
%31 = call i8* @color_to_str(i16 signext %30)
br label %32
32: ; preds = %29, %27
%33 = phi i8* [ %28, %27 ], [ %31, %29 ]
store i8* %33, i8** %5
%34 = load i16, i16* %4
%35 = call i64 @get_idc_bg(i16 signext %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i8* @color_to_str(i16 signext -1)
br label %42
39: ; preds = %32
%40 = load i16, i16* %8
%41 = call i8* @color_to_str(i16 signext %40)
br label %42
42: ; preds = %39, %37
%43 = phi i8* [ %38, %37 ], [ %41, %39 ]
store i8* %43, i8** %6
%44 = load i32*, i32** %3
%45 = load i8*, i8** %5
%46 = load i8*, i8** %6
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %45, i8* %46)
%48 = load i8*, i8** %6
%49 = call i32 @free(i8* %48)
%50 = load i8*, i8** %5
%51 = call i32 @free(i8* %50)
br label %52
52: ; preds = %42, %20
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"default,default\00"
@.str.1 = [6 x i8] c"%s,%s\00"
define void @emit_colorpair(i32* nocapture %0, i16 signext %1) {
%3 = alloca i16
%4 = alloca i16
%5 = bitcast i16* %3 to i8*
store i16 0, i16* %3
%6 = bitcast i16* %4 to i8*
store i16 0, i16* %4
%7 = call i32 @pair_content(i16 signext %1, i16* %3, i16* %4)
%8 = load i16, i16* %3
%9 = load i16, i16* %4
%10 = icmp eq i16 %8, %9
%11 = icmp eq i16 %1, 0
%12 = or i1 %11, %10
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i64 @fwrite(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64 15, i64 1, i32* %0)
br label %29
15: ; preds = %2
%16 = call i64 @get_idc_fg(i16 signext %1)
%17 = icmp eq i64 %16, 0
%18 = load i16, i16* %3
%19 = select i1 %17, i16 %18, i16 -1
%20 = call i8* @color_to_str(i16 signext %19)
%21 = call i64 @get_idc_bg(i16 signext %1)
%22 = icmp eq i64 %21, 0
%23 = load i16, i16* %4
%24 = select i1 %22, i16 %23, i16 -1
%25 = call i8* @color_to_str(i16 signext %24)
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %25)
%27 = call i32 @free(i8* %25)
%28 = call i32 @free(i8* %20)
br label %29
29: ; preds = %15, %13
ret void
}