#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 */
struct listmodel {
  int dummy;
};

/* Variables and functions */
int A_BOLD;
int COLOR_PAIR(int);
scalar_t__ listmodel_ismarked(struct listmodel *, size_t);
int attrs_for_index(struct listmodel *model, size_t index, size_t selected) {
  if (index == selected) {
    if (listmodel_ismarked(model, index))
      return A_BOLD | COLOR_PAIR(3);
    else
      return A_BOLD | COLOR_PAIR(1);
  } else {
    if (listmodel_ismarked(model, index))
      return COLOR_PAIR(2);
  }
  return 0;
}


x86 assembly (clang, -O0):
<attrs_for_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    11a3 <attrs_for_index+0x83>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <listmodel_ismarked@plt>
cmp    $0x0,%rax
je     117e <attrs_for_index+0x5e>
mov    0x2e80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    $0x3,%edi
call   1030 <COLOR_PAIR@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11d8 <attrs_for_index+0xb8>
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    $0x1,%edi
call   1030 <COLOR_PAIR@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11d8 <attrs_for_index+0xb8>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <listmodel_ismarked@plt>
cmp    $0x0,%rax
je     11cc <attrs_for_index+0xac>
mov    $0x2,%edi
call   1030 <COLOR_PAIR@plt>
mov    %eax,-0x4(%rbp)
jmp    11d8 <attrs_for_index+0xb8>
jmp    11d1 <attrs_for_index+0xb1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<attrs_for_index>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
call   1040 <listmodel_ismarked@plt>
cmp    %r14,%rbx
jne    1149 <attrs_for_index+0x29>
mov    0x2ea5(%rip),%rcx
mov    (%rcx),%ebx
test   %rax,%rax
je     115f <attrs_for_index+0x3f>
mov    $0x3,%edi
jmp    1164 <attrs_for_index+0x44>
test   %rax,%rax
je     116d <attrs_for_index+0x4d>
mov    $0x2,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <COLOR_PAIR@plt>
mov    $0x1,%edi
call   1030 <COLOR_PAIR@plt>
or     %ebx,%eax
jmp    116f <attrs_for_index+0x4f>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.listmodel = type { i32 }
@A_BOLD = global i32 0
define i32 @attrs_for_index(%struct.listmodel* %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca %struct.listmodel*
%6 = alloca i64
%7 = alloca i64
store %struct.listmodel* %0, %struct.listmodel** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%8 = load i64, i64* %6
%9 = load i64, i64* %7
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %24
11: ; preds = %3
%12 = load %struct.listmodel*, %struct.listmodel** %5
%13 = load i64, i64* %6
%14 = call i64 @listmodel_ismarked(%struct.listmodel* %12, i64 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load i32, i32* @A_BOLD
%18 = call i32 @COLOR_PAIR(i32 3)
%19 = or i32 %17, %18
store i32 %19, i32* %4
br label %33
20: ; preds = %11
%21 = load i32, i32* @A_BOLD
%22 = call i32 @COLOR_PAIR(i32 1)
%23 = or i32 %21, %22
store i32 %23, i32* %4
br label %33
24: ; preds = %3
%25 = load %struct.listmodel*, %struct.listmodel** %5
%26 = load i64, i64* %6
%27 = call i64 @listmodel_ismarked(%struct.listmodel* %25, i64 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 @COLOR_PAIR(i32 2)
store i32 %30, i32* %4
br label %33
31: ; preds = %24
br label %32
32: ; preds = %31
store i32 0, i32* %4
br label %33
33: ; preds = %32, %29, %20, %16
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
%struct.listmodel = type { i32 }
@A_BOLD = global i32 0
define i32 @attrs_for_index(%struct.listmodel* %0, i64 %1, i64 %2) {
%4 = icmp eq i64 %1, %2
%5 = tail call i64 @listmodel_ismarked(%struct.listmodel* %0, i64 %1)
%6 = icmp eq i64 %5, 0
br i1 %4, label %7, label %15
7: ; preds = %3
%8 = load i32, i32* @A_BOLD
br i1 %6, label %12, label %9
9: ; preds = %7
%10 = tail call i32 @COLOR_PAIR(i32 3)
%11 = or i32 %10, %8
br label %18
12: ; preds = %7
%13 = tail call i32 @COLOR_PAIR(i32 1)
%14 = or i32 %13, %8
br label %18
15: ; preds = %3
br i1 %6, label %18, label %16
16: ; preds = %15
%17 = tail call i32 @COLOR_PAIR(i32 2)
br label %18
18: ; preds = %15, %16, %12, %9
%19 = phi i32 [ %11, %9 ], [ %14, %12 ], [ %17, %16 ], [ 0, %15 ]
ret i32 %19
}