#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*/ COLOR_GREEN;
int /*<<< orphan*/ COLOR_RED;
int /*<<< orphan*/ LOG(char *, int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ error_exit(int /*<<< orphan*/, char *);
int find_alloc_colorpair(int /*<<< orphan*/, int);
int /*<<< orphan*/ get_idc_bg(int);
int /*<<< orphan*/ get_idc_fg(int);
void test_colors(void) {
  int id0 = find_alloc_colorpair(COLOR_RED, -1);
  int id1 = find_alloc_colorpair(COLOR_RED, -1);
  int id2 = find_alloc_colorpair(COLOR_GREEN, -1);
  int id3 = find_alloc_colorpair(COLOR_RED, -1);
  LOG("%d %d,%d\n", id0, get_idc_fg(id0), get_idc_bg(id0));
  LOG("%d %d,%d\n", id1, get_idc_fg(id1), get_idc_bg(id1));
  LOG("%d %d,%d\n", id2, get_idc_fg(id2), get_idc_bg(id2));
  LOG("%d %d,%d\n", id3, get_idc_fg(id3), get_idc_bg(id3));
  error_exit(0, "");
}


x86 assembly (clang, -O0):
<test_colors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    $0xffffffff,%esi
call   1040 <find_alloc_colorpair@plt>
mov    %eax,-0x4(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
mov    $0xffffffff,%esi
call   1040 <find_alloc_colorpair@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
mov    $0xffffffff,%esi
call   1040 <find_alloc_colorpair@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    $0xffffffff,%esi
call   1040 <find_alloc_colorpair@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <get_idc_fg@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <get_idc_bg@plt>
mov    -0x30(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    %eax,%ecx
lea    0xe28(%rip),%rdi
call   1070 <LOG@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <get_idc_fg@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <get_idc_bg@plt>
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    %eax,%ecx
lea    0xdfb(%rip),%rdi
call   1070 <LOG@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <get_idc_fg@plt>
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <get_idc_bg@plt>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    %eax,%ecx
lea    0xdce(%rip),%rdi
call   1070 <LOG@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%edi
call   1060 <get_idc_fg@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <get_idc_bg@plt>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    %eax,%ecx
lea    0xda1(%rip),%rdi
call   1070 <LOG@plt>
xor    %edi,%edi
lea    0xd9c(%rip),%rsi
call   1050 <error_exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_colors>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e76(%rip),%rbx
mov    (%rbx),%edi
mov    $0xffffffff,%esi
call   1040 <find_alloc_colorpair@plt>
mov    %eax,%ebp
mov    (%rbx),%edi
mov    $0xffffffff,%esi
call   1040 <find_alloc_colorpair@plt>
mov    %eax,%r13d
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
mov    $0xffffffff,%esi
call   1040 <find_alloc_colorpair@plt>
mov    %eax,%r12d
mov    (%rbx),%edi
mov    $0xffffffff,%esi
call   1040 <find_alloc_colorpair@plt>
mov    %eax,%r15d
mov    %ebp,%edi
call   1060 <get_idc_fg@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <get_idc_bg@plt>
lea    0xe45(%rip),%r14
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %eax,%ecx
call   1070 <LOG@plt>
mov    %r13d,%edi
call   1060 <get_idc_fg@plt>
mov    %eax,%ebx
mov    %r13d,%edi
call   1030 <get_idc_bg@plt>
mov    %r14,%rdi
mov    %r13d,%esi
mov    %ebx,%edx
mov    %eax,%ecx
call   1070 <LOG@plt>
mov    %r12d,%edi
call   1060 <get_idc_fg@plt>
mov    %eax,%ebx
mov    %r12d,%edi
call   1030 <get_idc_bg@plt>
mov    %r14,%rdi
mov    %r12d,%esi
mov    %ebx,%edx
mov    %eax,%ecx
call   1070 <LOG@plt>
mov    %r15d,%edi
call   1060 <get_idc_fg@plt>
mov    %eax,%ebx
mov    %r15d,%edi
call   1030 <get_idc_bg@plt>
mov    %r14,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
mov    %eax,%ecx
call   1070 <LOG@plt>
lea    0xdd6(%rip),%rsi
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <error_exit@plt>

LLVM IR (-O0):
@COLOR_RED = global i32 0
@COLOR_GREEN = global i32 0
@.str = [10 x i8] c"%d %d,%d\0A\00"
@.str.1 = [1 x i8] zeroinitializer
define void @test_colors() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = load i32, i32* @COLOR_RED
%6 = call i32 @find_alloc_colorpair(i32 %5, i32 -1)
store i32 %6, i32* %1
%7 = load i32, i32* @COLOR_RED
%8 = call i32 @find_alloc_colorpair(i32 %7, i32 -1)
store i32 %8, i32* %2
%9 = load i32, i32* @COLOR_GREEN
%10 = call i32 @find_alloc_colorpair(i32 %9, i32 -1)
store i32 %10, i32* %3
%11 = load i32, i32* @COLOR_RED
%12 = call i32 @find_alloc_colorpair(i32 %11, i32 -1)
store i32 %12, i32* %4
%13 = load i32, i32* %1
%14 = load i32, i32* %1
%15 = call i32 @get_idc_fg(i32 %14)
%16 = load i32, i32* %1
%17 = call i32 @get_idc_bg(i32 %16)
%18 = call i32 @LOG(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %15, i32 %17)
%19 = load i32, i32* %2
%20 = load i32, i32* %2
%21 = call i32 @get_idc_fg(i32 %20)
%22 = load i32, i32* %2
%23 = call i32 @get_idc_bg(i32 %22)
%24 = call i32 @LOG(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %21, i32 %23)
%25 = load i32, i32* %3
%26 = load i32, i32* %3
%27 = call i32 @get_idc_fg(i32 %26)
%28 = load i32, i32* %3
%29 = call i32 @get_idc_bg(i32 %28)
%30 = call i32 @LOG(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %25, i32 %27, i32 %29)
%31 = load i32, i32* %4
%32 = load i32, i32* %4
%33 = call i32 @get_idc_fg(i32 %32)
%34 = load i32, i32* %4
%35 = call i32 @get_idc_bg(i32 %34)
%36 = call i32 @LOG(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %31, i32 %33, i32 %35)
%37 = call i32 @error_exit(i32 0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@COLOR_RED = global i32 0
@COLOR_GREEN = global i32 0
@.str = [10 x i8] c"%d %d,%d\0A\00"
@.str.1 = [1 x i8] zeroinitializer
define void @test_colors() {
%1 = load i32, i32* @COLOR_RED
%2 = tail call i32 @find_alloc_colorpair(i32 %1, i32 -1)
%3 = load i32, i32* @COLOR_RED
%4 = tail call i32 @find_alloc_colorpair(i32 %3, i32 -1)
%5 = load i32, i32* @COLOR_GREEN
%6 = tail call i32 @find_alloc_colorpair(i32 %5, i32 -1)
%7 = load i32, i32* @COLOR_RED
%8 = tail call i32 @find_alloc_colorpair(i32 %7, i32 -1)
%9 = tail call i32 @get_idc_fg(i32 %2)
%10 = tail call i32 @get_idc_bg(i32 %2)
%11 = tail call i32 @LOG(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %9, i32 %10)
%12 = tail call i32 @get_idc_fg(i32 %4)
%13 = tail call i32 @get_idc_bg(i32 %4)
%14 = tail call i32 @LOG(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %12, i32 %13)
%15 = tail call i32 @get_idc_fg(i32 %6)
%16 = tail call i32 @get_idc_bg(i32 %6)
%17 = tail call i32 @LOG(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %15, i32 %16)
%18 = tail call i32 @get_idc_fg(i32 %8)
%19 = tail call i32 @get_idc_bg(i32 %8)
%20 = tail call i32 @LOG(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %18, i32 %19)
%21 = tail call i32 @error_exit(i32 0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
ret void
}