// File: /workspace/github_c_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
decl %esi
cmpl $0x3, %esi
ja 0x5d53
leaq 0x46d1(%rip), %rax      # 0xa024
movslq (%rax,%rsi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movslq 0x8e0d(%rip), %rcx      # 0xe770
testq %rcx, %rcx
jle 0x5d53
movslq %edi, %rax
leaq (%rax,%rax,8), %rdx
leaq 0x9246(%rip), %rsi      # 0xebc0
leaq (%rsi,%rdx,8), %r8
movswl 0x2(%r8), %r9d
movswl 0x6(%r8), %r10d
movl %r10d, %r11d
addl %r9d, %r11d
xorl %ebx, %ebx
movq %rsi, %r14
movl %edi, %eax
movswl 0x2(%r14), %ebp
movl %ebp, %r12d
xorl %r9d, %r12d
movzwl 0x6(%r14), %r15d
movl %r15d, %r13d
xorl %r10d, %r13d
orw %r12w, %r13w
je 0x59cf
movswl %r15w, %r15d
addl %ebp, %r15d
cmpl %r11d, %r15d
cmovgel %r11d, %r15d
cmpw %r9w, %bp
cmovlel %r9d, %ebp
movswl %bp, %ebp
cmpl %ebp, %r15d
jle 0x59ed
movzwl (%r14), %ebp
cmpw (%r8), %bp
jge 0x59ed
cmpl %edi, %eax
je 0x59eb
movslq %eax, %r15
leaq (%r15,%r15,8), %r15
cmpw (%rsi,%r15,8), %bp
jl 0x59ed
movl %ebx, %eax
incq %rbx
addq $0x48, %r14
cmpq %rbx, %rcx
jne 0x5995
testl %ecx, %ecx
setle %sil
cmpl %edi, %eax
setne %r8b
orb %sil, %r8b
jne 0x5d55
leaq 0x91ab(%rip), %rsi      # 0xebc0
movzwl (%rsi,%rdx,8), %edx
xorl %r8d, %r8d
movq %rsi, %r9
movl %edi, %eax
movzwl (%r9), %r10d
cmpw %dx, %r10w
jge 0x5a40
cmpl %edi, %eax
je 0x5a3d
movslq %eax, %r11
leaq (%r11,%r11,8), %r11
cmpw (%rsi,%r11,8), %r10w
jl 0x5a40
movl %r8d, %eax
incq %r8
addq $0x48, %r9
cmpq %r8, %rcx
jne 0x5a21
jmp 0x5d55
movslq 0x8d18(%rip), %rcx      # 0xe770
testq %rcx, %rcx
jle 0x5d53
movslq %edi, %rax
leaq (%rax,%rax,8), %rsi
leaq 0x9151(%rip), %rdx      # 0xebc0
leaq (%rdx,%rsi,8), %r8
movswl (%r8), %r9d
movswl 0x4(%r8), %r10d
movl %r10d, %r11d
addl %r9d, %r11d
leaq 0x913b(%rip), %rbx      # 0xebc4
xorl %r14d, %r14d
movl %edi, %eax
movswl -0x4(%rbx), %ebp
movl %ebp, %r12d
xorl %r9d, %r12d
movzwl (%rbx), %r15d
movl %r15d, %r13d
xorl %r10d, %r13d
orw %r12w, %r13w
je 0x5ac6
movswl %r15w, %r15d
addl %ebp, %r15d
cmpl %r11d, %r15d
cmovgel %r11d, %r15d
cmpw %r9w, %bp
cmovlel %r9d, %ebp
movswl %bp, %ebp
cmpl %ebp, %r15d
jle 0x5ae7
movzwl -0x2(%rbx), %ebp
cmpw 0x2(%r8), %bp
jge 0x5ae7
cmpl %edi, %eax
je 0x5ae4
movslq %eax, %r15
leaq (%r15,%r15,8), %r15
cmpw 0x2(%rdx,%r15,8), %bp
jl 0x5ae7
movl %r14d, %eax
incq %r14
addq $0x48, %rbx
cmpq %r14, %rcx
jne 0x5a8e
testl %ecx, %ecx
setle %r8b
cmpl %edi, %eax
setne %r9b
orb %r8b, %r9b
jne 0x5d55
movzwl 0x2(%rdx,%rsi,8), %esi
leaq 0x90ae(%rip), %r8       # 0xebc2
xorl %r9d, %r9d
movl %edi, %eax
movzwl (%r8), %r10d
cmpw %si, %r10w
jge 0x5b39
cmpl %edi, %eax
je 0x5b36
movslq %eax, %r11
leaq (%r11,%r11,8), %r11
cmpw 0x2(%rdx,%r11,8), %r10w
jl 0x5b39
movl %r9d, %eax
incq %r9
addq $0x48, %r8
cmpq %r9, %rcx
jne 0x5b19
jmp 0x5d55
movslq 0x8c1f(%rip), %rcx      # 0xe770
testq %rcx, %rcx
jle 0x5d53
movslq %edi, %rax
leaq (%rax,%rax,8), %rsi
leaq 0x9058(%rip), %rdx      # 0xebc0
leaq (%rdx,%rsi,8), %r8
movswl (%r8), %r9d
movswl 0x4(%r8), %r10d
movl %r10d, %r11d
addl %r9d, %r11d
leaq 0x9042(%rip), %rbx      # 0xebc4
xorl %r14d, %r14d
movl %edi, %eax
movswl -0x4(%rbx), %ebp
movl %ebp, %r12d
xorl %r9d, %r12d
movzwl (%rbx), %r15d
movl %r15d, %r13d
xorl %r10d, %r13d
orw %r12w, %r13w
je 0x5bbf
movswl %r15w, %r15d
addl %ebp, %r15d
cmpl %r11d, %r15d
cmovgel %r11d, %r15d
cmpw %r9w, %bp
cmovlel %r9d, %ebp
movswl %bp, %ebp
cmpl %ebp, %r15d
jle 0x5beb
movswl -0x2(%rbx), %ebp
movswl 0x2(%r8), %r15d
movswl 0x6(%r8), %r12d
addl %r15d, %r12d
cmpl %ebp, %r12d
jg 0x5beb
cmpl %edi, %eax
je 0x5be8
movslq %eax, %r15
leaq (%r15,%r15,8), %r15
cmpw 0x2(%rdx,%r15,8), %bp
jg 0x5beb
movl %r14d, %eax
incq %r14
addq $0x48, %rbx
cmpq %r14, %rcx
jne 0x5b87
testl %ecx, %ecx
setle %r8b
cmpl %edi, %eax
setne %r9b
orb %r8b, %r9b
jne 0x5d55
movswl 0x2(%rdx,%rsi,8), %eax
movswl 0x6(%rdx,%rsi,8), %esi
addl %eax, %esi
leaq 0x8fa3(%rip), %r8       # 0xebc2
xorl %r9d, %r9d
movl %edi, %eax
movswl (%r8), %r10d
cmpl %r10d, %esi
jg 0x5c43
cmpl %edi, %eax
je 0x5c40
movslq %eax, %r11
leaq (%r11,%r11,8), %r11
cmpw 0x2(%rdx,%r11,8), %r10w
jg 0x5c43
movl %r9d, %eax
incq %r9
addq $0x48, %r8
cmpq %r9, %rcx
jne 0x5c24
jmp 0x5d55
movslq 0x8b15(%rip), %rcx      # 0xe770
testq %rcx, %rcx
jle 0x5d53
movslq %edi, %rax
leaq (%rax,%rax,8), %rdx
leaq 0x8f4e(%rip), %rsi      # 0xebc0
leaq (%rsi,%rdx,8), %r8
movswl 0x2(%r8), %r9d
movswl 0x6(%r8), %r10d
movl %r10d, %r11d
addl %r9d, %r11d
xorl %ebx, %ebx
movq %rsi, %r14
movl %edi, %eax
movswl 0x2(%r14), %ebp
movl %ebp, %r12d
xorl %r9d, %r12d
movzwl 0x6(%r14), %r15d
movl %r15d, %r13d
xorl %r10d, %r13d
orw %r12w, %r13w
je 0x5cc7
movswl %r15w, %r15d
addl %ebp, %r15d
cmpl %r11d, %r15d
cmovgel %r11d, %r15d
cmpw %r9w, %bp
cmovlel %r9d, %ebp
movswl %bp, %ebp
cmpl %ebp, %r15d
jle 0x5cf0
movswl (%r14), %ebp
movswl (%r8), %r15d
movswl 0x4(%r8), %r12d
addl %r15d, %r12d
cmpl %ebp, %r12d
jg 0x5cf0
cmpl %edi, %eax
je 0x5cee
movslq %eax, %r15
leaq (%r15,%r15,8), %r15
cmpw (%rsi,%r15,8), %bp
jg 0x5cf0
movl %ebx, %eax
incq %rbx
addq $0x48, %r14
cmpq %rbx, %rcx
jne 0x5c8d
testl %ecx, %ecx
setle %sil
cmpl %edi, %eax
setne %r8b
orb %sil, %r8b
jne 0x5d55
leaq 0x8eac(%rip), %rsi      # 0xebc0
movswl (%rsi,%rdx,8), %eax
movswl 0x4(%rsi,%rdx,8), %edx
addl %eax, %edx
xorl %r8d, %r8d
movq %rsi, %r9
movl %edi, %eax
movswl (%r9), %r10d
cmpl %r10d, %edx
jg 0x5d45
cmpl %edi, %eax
je 0x5d42
movslq %eax, %r11
leaq (%r11,%r11,8), %r11
cmpw (%rsi,%r11,8), %r10w
jg 0x5d45
movl %r8d, %eax
incq %r8
addq $0x48, %r9
cmpq %r8, %rcx
jne 0x5d27
jmp 0x5d55
movl %edi, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq