#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 COLORS;
int find_alloc_colorpair(int, int);
int /*<<< orphan*/ set_idc(int /*<<< orphan*/, int, int);
int get_color_ncurses(int ncol_fg, int ncol_bg) {
  int pair = 0;
  if (ncol_fg == -1 && ncol_bg == -1)
    set_idc(0, 1, 1);
  else if (ncol_fg == ncol_bg) {
    ncol_bg++;
    ncol_bg %= COLORS;
  }
  pair = find_alloc_colorpair(ncol_fg, ncol_bg);
  return pair;
}


x86 assembly (clang, -O0):
<get_color_ncurses>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    115c <get_color_ncurses+0x3c>
cmpl   $0xffffffff,-0x8(%rbp)
jne    115c <get_color_ncurses+0x3c>
xor    %edi,%edi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <set_idc@plt>
jmp    1188 <get_color_ncurses+0x68>
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    1183 <get_color_ncurses+0x63>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    0x2e68(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
jmp    1188 <get_color_ncurses+0x68>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <find_alloc_colorpair@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_color_ncurses>:
push   %rbx
mov    %edi,%ebx
mov    %esi,%eax
and    %edi,%eax
cmp    $0xffffffff,%eax
je     1143 <get_color_ncurses+0x23>
cmp    %esi,%ebx
jne    1159 <get_color_ncurses+0x39>
add    $0x1,%esi
mov    0x2ea6(%rip),%rcx
mov    %esi,%eax
cltd
idivl  (%rcx)
mov    %edx,%esi
jmp    1159 <get_color_ncurses+0x39>
xor    %edi,%edi
mov    $0x1,%esi
mov    $0x1,%edx
call   1040 <set_idc@plt>
mov    $0xffffffff,%esi
mov    %ebx,%edi
pop    %rbx
jmp    1030 <find_alloc_colorpair@plt>

LLVM IR (-O0):
@COLORS = global i32 0
define i32 @get_color_ncurses(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @set_idc(i32 0, i32 1, i32 1)
br label %24
13: ; preds = %8, %2
%14 = load i32, i32* %3
%15 = load i32, i32* %4
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
%20 = load i32, i32* @COLORS
%21 = load i32, i32* %4
%22 = srem i32 %21, %20
store i32 %22, i32* %4
br label %23
23: ; preds = %17, %13
br label %24
24: ; preds = %23, %11
%25 = load i32, i32* %3
%26 = load i32, i32* %4
%27 = call i32 @find_alloc_colorpair(i32 %25, i32 %26)
store i32 %27, i32* %5
%28 = load i32, i32* %5
ret i32 %28
}

LLVM IR (-O2):
@COLORS = global i32 0
define i32 @get_color_ncurses(i32 %0, i32 %1) {
%3 = and i32 %1, %0
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @set_idc(i32 0, i32 1, i32 1)
br label %13
7: ; preds = %2
%8 = icmp eq i32 %0, %1
br i1 %8, label %9, label %13
9: ; preds = %7
%10 = add nsw i32 %1, 1
%11 = load i32, i32* @COLORS
%12 = srem i32 %10, %11
br label %13
13: ; preds = %7, %9, %5
%14 = phi i32 [ -1, %5 ], [ %12, %9 ], [ %1, %7 ]
%15 = tail call i32 @find_alloc_colorpair(i32 %0, i32 %14)
ret i32 %15
}