// File: /workspace/github_c_makefile_star2_O1/seanpringle[P]xoat/./monitor.c
// Function: monitor_choose_by_direction
int monitor_choose_by_direction(int cmon, int dir)
{
  int mon = cmon;
  int i; Monitor *m;
  if (dir == LEFT)
  {
    for_monitors(i, m)
      if (OVERLAP(m->y, m->h, monitors[cmon].y, monitors[cmon].h) && m->x < monitors[cmon].x && (mon == cmon || m->x >= monitors[mon].x))
        mon = i;
    if (mon == cmon) for_monitors(i, m)
      if (m->x < monitors[cmon].x && (mon == cmon || m->x >= monitors[mon].x))
        mon = i;
  }
  else
  if (dir == RIGHT)
  {
    for_monitors(i, m)
      if (OVERLAP(m->y, m->h, monitors[cmon].y, monitors[cmon].h) && m->x >= monitors[cmon].x + monitors[cmon].w && (mon == cmon || m->x <= monitors[mon].x))
        mon = i;
    if (mon == cmon) for_monitors(i, m)
      if (m->x >= monitors[cmon].x + monitors[cmon].w && (mon == cmon || m->x <= monitors[mon].x))
        mon = i;
  }
  else
  if (dir == UP)
  {
    for_monitors(i, m)
      if (OVERLAP(m->x, m->w, monitors[cmon].x, monitors[cmon].w) && m->y < monitors[cmon].y && (mon == cmon || m->y >= monitors[mon].y))
        mon = i;
    if (mon == cmon) for_monitors(i, m)
      if (m->y < monitors[cmon].y && (mon == cmon || m->y >= monitors[mon].y))
        mon = i;
  }
  else
  if (dir == DOWN)
  {
    for_monitors(i, m)
      if (OVERLAP(m->x, m->w, monitors[cmon].x, monitors[cmon].w) && m->y >= monitors[cmon].y + monitors[cmon].h && (mon == cmon || m->y <= monitors[mon].y))
        mon = i;
    if (mon == cmon) for_monitors(i, m)
      if (m->y >= monitors[cmon].y + monitors[cmon].h && (mon == cmon || m->y <= monitors[mon].y))
        mon = i;
  }
  return mon;
}

// Assembly:
decl %esi
cmpl $0x3, %esi
ja 0x5d78
pushq %rbp
pushq %r14
pushq %rbx
leaq 0x46a4(%rip), %rax      # 0xa024
movslq (%rax,%rsi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movslq 0x8de0(%rip), %rcx      # 0xe770
movl %edi, %eax
testq %rcx, %rcx
jle 0x5a1f
movslq %edi, %rax
leaq (%rax,%rax,8), %rax
leaq 0x9217(%rip), %rdx      # 0xebc0
leaq (%rdx,%rax,8), %rsi
movswl 0x2(%rsi), %r8d
leaq 0x920d(%rip), %r9       # 0xebc6
xorl %r10d, %r10d
movl %edi, %eax
movswl -0x4(%r9), %r11d
cmpw %r8w, %r11w
jne 0x59d3
movzwl (%r9), %ebx
cmpw 0x6(%rsi), %bx
je 0x59f3
movswl (%r9), %ebx
addl %r11d, %ebx
movswl 0x6(%rsi), %ebp
addl %r8d, %ebp
cmpl %ebp, %ebx
cmovll %ebx, %ebp
cmpw %r8w, %r11w
cmovlel %r8d, %r11d
cmpl %r11d, %ebp
jle 0x5a13
movzwl -0x6(%r9), %r11d
cmpw (%rsi), %r11w
jge 0x5a13
cmpl %edi, %eax
je 0x5a10
movslq %eax, %rbx
leaq (%rbx,%rbx,8), %rbx
cmpw (%rdx,%rbx,8), %r11w
jl 0x5a13
movl %r10d, %eax
incq %r10
addq $0x48, %r9
cmpq %r10, %rcx
jne 0x59be
cmpl %edi, %eax
setne %dl
testl %ecx, %ecx
setle %sil
orb %dl, %sil
jne 0x5d73
movslq %edi, %rdx
leaq (%rdx,%rdx,8), %rsi
leaq 0x917f(%rip), %rdx      # 0xebc0
movzwl (%rdx,%rsi,8), %esi
xorl %r8d, %r8d
movq %rdx, %r9
movzwl (%r9), %r10d
cmpw %si, %r10w
jge 0x5a6a
cmpl %edi, %eax
je 0x5a67
movslq %eax, %r11
leaq (%r11,%r11,8), %r11
cmpw (%rdx,%r11,8), %r10w
jl 0x5a6a
movl %r8d, %eax
incq %r8
addq $0x48, %r9
cmpq %r8, %rcx
jne 0x5a4b
jmp 0x5d73
movslq 0x8cee(%rip), %rcx      # 0xe770
movl %edi, %eax
testq %rcx, %rcx
jle 0x5b12
movslq %edi, %rax
leaq (%rax,%rax,8), %rax
leaq 0x9125(%rip), %rdx      # 0xebc0
leaq (%rdx,%rax,8), %rsi
movswl (%rsi), %r8d
leaq 0x911a(%rip), %r9       # 0xebc4
xorl %r10d, %r10d
movl %edi, %eax
movswl -0x4(%r9), %r11d
cmpw %r8w, %r11w
jne 0x5ac4
movzwl (%r9), %ebx
cmpw 0x4(%rsi), %bx
je 0x5ae4
movswl (%r9), %ebx
addl %r11d, %ebx
movswl 0x4(%rsi), %ebp
addl %r8d, %ebp
cmpl %ebp, %ebx
cmovll %ebx, %ebp
cmpw %r8w, %r11w
cmovlel %r8d, %r11d
cmpl %r11d, %ebp
jle 0x5b06
movzwl -0x2(%r9), %r11d
cmpw 0x2(%rsi), %r11w
jge 0x5b06
cmpl %edi, %eax
je 0x5b03
movslq %eax, %rbx
leaq (%rbx,%rbx,8), %rbx
cmpw 0x2(%rdx,%rbx,8), %r11w
jl 0x5b06
movl %r10d, %eax
incq %r10
addq $0x48, %r9
cmpq %r10, %rcx
jne 0x5aaf
cmpl %edi, %eax
setne %dl
testl %ecx, %ecx
setle %sil
orb %dl, %sil
jne 0x5d73
movslq %edi, %rdx
leaq (%rdx,%rdx,8), %rsi
leaq 0x908c(%rip), %rdx      # 0xebc0
movzwl 0x2(%rdx,%rsi,8), %esi
leaq 0x9082(%rip), %r8       # 0xebc2
xorl %r9d, %r9d
movzwl (%r8), %r10d
cmpw %si, %r10w
jge 0x5b63
cmpl %edi, %eax
je 0x5b60
movslq %eax, %r11
leaq (%r11,%r11,8), %r11
cmpw 0x2(%rdx,%r11,8), %r10w
jl 0x5b63
movl %r9d, %eax
incq %r9
addq $0x48, %r8
cmpq %r9, %rcx
jne 0x5b43
jmp 0x5d73
movslq 0x8bf5(%rip), %rcx      # 0xe770
movslq %edi, %rsi
leaq 0x903b(%rip), %rdx      # 0xebc0
movl %edi, %eax
testq %rcx, %rcx
jle 0x5c19
leaq (%rsi,%rsi,8), %rax
leaq (%rdx,%rax,8), %r8
movswl (%r8), %r9d
leaq 0x9021(%rip), %r10      # 0xebc4
xorl %r11d, %r11d
movl %edi, %eax
movswl -0x4(%r10), %ebx
cmpw %r9w, %bx
jne 0x5bbe
movzwl (%r10), %ebp
cmpw 0x4(%r8), %bp
je 0x5be0
movswl (%r10), %ebp
addl %ebx, %ebp
movswl 0x4(%r8), %r14d
addl %r9d, %r14d
cmpl %r14d, %ebp
cmovll %ebp, %r14d
cmpw %r9w, %bx
cmovlel %r9d, %ebx
cmpl %ebx, %r14d
jle 0x5c0d
movswl -0x2(%r10), %ebx
movswl 0x2(%r8), %ebp
movswl 0x6(%r8), %r14d
addl %ebp, %r14d
cmpl %ebx, %r14d
jg 0x5c0d
cmpl %edi, %eax
je 0x5c0a
movslq %eax, %r14
leaq (%r14,%r14,8), %r14
cmpw 0x2(%rdx,%r14,8), %bx
jg 0x5c0d
movl %r11d, %eax
incq %r11
addq $0x48, %r10
cmpq %r11, %rcx
jne 0x5ba8
cmpl %edi, %eax
setne %r8b
testl %ecx, %ecx
setle %r9b
orb %r8b, %r9b
jne 0x5d73
leaq (%rsi,%rsi,8), %rsi
movswl 0x2(%rdx,%rsi,8), %r8d
movswl 0x6(%rdx,%rsi,8), %esi
addl %r8d, %esi
leaq 0x8f7b(%rip), %r8       # 0xebc2
xorl %r9d, %r9d
movswl (%r8), %r10d
cmpl %r10d, %esi
jg 0x5c69
cmpl %edi, %eax
je 0x5c66
movslq %eax, %r11
leaq (%r11,%r11,8), %r11
cmpw 0x2(%rdx,%r11,8), %r10w
jg 0x5c69
movl %r9d, %eax
incq %r9
addq $0x48, %r8
cmpq %r9, %rcx
jne 0x5c4a
jmp 0x5d73
movslq 0x8aef(%rip), %rcx      # 0xe770
movl %edi, %eax
testq %rcx, %rcx
jle 0x5d18
movslq %edi, %rax
leaq (%rax,%rax,8), %rax
leaq 0x8f26(%rip), %rdx      # 0xebc0
leaq (%rdx,%rax,8), %rsi
movswl 0x2(%rsi), %r8d
leaq 0x8f1c(%rip), %r9       # 0xebc6
xorl %r10d, %r10d
movl %edi, %eax
movswl -0x4(%r9), %r11d
cmpw %r8w, %r11w
jne 0x5cc4
movzwl (%r9), %ebx
cmpw 0x6(%rsi), %bx
je 0x5ce4
movswl (%r9), %ebx
addl %r11d, %ebx
movswl 0x6(%rsi), %ebp
addl %r8d, %ebp
cmpl %ebp, %ebx
cmovll %ebx, %ebp
cmpw %r8w, %r11w
cmovlel %r8d, %r11d
cmpl %r11d, %ebp
jle 0x5d0c
movswl -0x6(%r9), %r11d
movswl (%rsi), %ebx
movswl 0x4(%rsi), %ebp
addl %ebx, %ebp
cmpl %r11d, %ebp
jg 0x5d0c
cmpl %edi, %eax
je 0x5d09
movslq %eax, %rbx
leaq (%rbx,%rbx,8), %rbx
cmpw (%rdx,%rbx,8), %r11w
jg 0x5d0c
movl %r10d, %eax
incq %r10
addq $0x48, %r9
cmpq %r10, %rcx
jne 0x5caf
cmpl %edi, %eax
setne %dl
testl %ecx, %ecx
setle %sil
orb %dl, %sil
jne 0x5d73
movslq %edi, %rdx
leaq (%rdx,%rdx,8), %rsi
leaq 0x8e8a(%rip), %rdx      # 0xebc0
movswl (%rdx,%rsi,8), %r8d
movswl 0x4(%rdx,%rsi,8), %esi
addl %r8d, %esi
xorl %r8d, %r8d
movq %rdx, %r9
movswl (%r9), %r10d
cmpl %r10d, %esi
jg 0x5d67
cmpl %edi, %eax
je 0x5d64
movslq %eax, %r11
leaq (%r11,%r11,8), %r11
cmpw (%rdx,%r11,8), %r10w
jg 0x5d67
movl %r8d, %eax
incq %r8
addq $0x48, %r9
cmpq %r8, %rcx
jne 0x5d49
popq %rbx
popq %r14
popq %rbp
retq
movl %edi, %eax
retq