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

/* Variables and functions */
int /*<<< orphan*/ A_BOLD;
int /*<<< orphan*/ COLOR_PAIR(int);
int /*<<< orphan*/ attrset(int /*<<< orphan*/);
scalar_t__ has_colors();
int rand();
int next_j(int j) {
  if (j == 0)
    j = 4;
  else
    --j;
  if (has_colors()) {
    int z = rand() % 3;
    chtype color = COLOR_PAIR(z);
    if (z)
      color |= A_BOLD;
    attrset(color);
  }
  return j;
}


x86 assembly (clang, -O0):
<next_j>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1161 <next_j+0x21>
movl   $0x4,-0x4(%rbp)
jmp    116a <next_j+0x2a>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1030 <has_colors@plt>
cmp    $0x0,%rax
je     11b9 <next_j+0x79>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <COLOR_PAIR@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11b1 <next_j+0x71>
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <attrset@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_j>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <has_colors@plt>
test   %rax,%rax
je     119c <next_j+0x5c>
xor    %eax,%eax
call   1060 <rand@plt>
movslq %eax,%rbp
imul   $0x55555556,%rbp,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%ebx
mov    %ebp,%edi
sub    %ebx,%edi
call   1040 <COLOR_PAIR@plt>
cmp    %ebx,%ebp
je     1191 <next_j+0x51>
mov    0x2e52(%rip),%rcx
mov    (%rcx),%r14d
or     %eax,%r14d
mov    %r14d,%edi
call   1050 <attrset@plt>
sub    $0x1,%r15d
mov    $0x4,%eax
cmovae %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@A_BOLD = global i32 0
define i32 @next_j(i32 %0) {
%2 = tail call i64 (...) @has_colors()
%3 = icmp eq i64 %2, 0
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = tail call i32 (...) @rand()
%6 = srem i32 %5, 3
%7 = tail call i32 @COLOR_PAIR(i32 %6)
%8 = icmp eq i32 %6, 0
%9 = load i32, i32* @A_BOLD
%10 = select i1 %8, i32 0, i32 %9
%11 = or i32 %10, %7
%12 = tail call i32 @attrset(i32 %11)
br label %13
13: ; preds = %4, %1
%14 = icmp eq i32 %0, 0
%15 = add nsw i32 %0, -1
%16 = select i1 %14, i32 4, i32 %15
ret i32 %16
}