// File: /workspace/github_c_makefile_star2_O2/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 0x5321
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
leaq 0x50c0(%rip), %rax      # 0xa024
movslq (%rax,%rsi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movl 0x97fd(%rip), %ecx      # 0xe770
movslq %edi, %rax
imulq $0x48, %rax, %rdx
leaq 0x9c3f(%rip), %rsi      # 0xebc0
addq %rsi, %rdx
xorl %r8d, %r8d
testl %ecx, %ecx
cmovlel %r8d, %ecx
movq %rsi, %r9
movl %edi, %eax
cmpq %r8, %rcx
je 0x528a
movswl 0x2(%r9), %r10d
movswl 0x2(%rdx), %r11d
movl %r10d, %r14d
xorl %r11d, %r14d
movzwl 0x6(%r9), %ebx
movzwl 0x6(%rdx), %ebp
movl %ebp, %r15d
xorl %ebx, %r15d
orw %r14w, %r15w
je 0x4fde
movswl %bx, %ebx
movswl %bp, %ebp
addl %r10d, %ebx
addl %r11d, %ebp
cmpl %ebp, %ebx
cmovll %ebx, %ebp
cmpw %r11w, %r10w
cmovgl %r10d, %r11d
cmpl %r11d, %ebp
jle 0x4ffd
movzwl (%r9), %r10d
cmpw (%rdx), %r10w
jge 0x4ffd
cmpl %edi, %eax
je 0x4ffa
movslq %eax, %r11
imulq $0x48, %r11, %r11
cmpw (%r11,%rsi), %r10w
jl 0x4ffd
movl %r8d, %eax
incq %r8
addq $0x48, %r9
jmp 0x4f92
movl 0x9764(%rip), %ecx      # 0xe770
movslq %edi, %rax
imulq $0x48, %rax, %rsi
leaq 0x9ba6(%rip), %rdx      # 0xebc0
leaq (%rdx,%rsi), %r8
xorl %r9d, %r9d
testl %ecx, %ecx
cmovlel %r9d, %ecx
leaq 0x9b96(%rip), %r10      # 0xebc4
movl %edi, %eax
cmpq %r9, %rcx
je 0x50a5
movswl -0x4(%r10), %r11d
movswl (%r8), %ebx
movl %r11d, %r15d
xorl %ebx, %r15d
movzwl (%r10), %ebp
movzwl 0x4(%r8), %r14d
movl %r14d, %r12d
xorl %ebp, %r12d
orw %r15w, %r12w
je 0x507a
movswl %bp, %ebp
movswl %r14w, %r14d
addl %r11d, %ebp
addl %ebx, %r14d
cmpl %r14d, %ebp
cmovll %ebp, %r14d
cmpw %bx, %r11w
cmovgl %r11d, %ebx
cmpl %ebx, %r14d
jle 0x509c
movzwl -0x2(%r10), %r11d
cmpw 0x2(%r8), %r11w
jge 0x509c
cmpl %edi, %eax
je 0x5099
movslq %eax, %rbx
imulq $0x48, %rbx, %rbx
cmpw 0x2(%rbx,%rdx), %r11w
jl 0x509c
movl %r9d, %eax
incq %r9
addq $0x48, %r10
jmp 0x5030
cmpl %edi, %eax
jne 0x5318
addq %rdx, %rsi
addq $0x2, %rsi
leaq 0x9b07(%rip), %r8       # 0xebc2
xorl %r9d, %r9d
movl %edi, %eax
cmpq %r9, %rcx
je 0x5318
movzwl (%r8), %r10d
cmpw (%rsi), %r10w
jge 0x50e9
cmpl %edi, %eax
je 0x50e6
movslq %eax, %r11
imulq $0x48, %r11, %r11
cmpw 0x2(%r11,%rdx), %r10w
jl 0x50e9
movl %r9d, %eax
incq %r9
addq $0x48, %r8
jmp 0x50c0
movl 0x9678(%rip), %ecx      # 0xe770
movslq %edi, %rax
imulq $0x48, %rax, %rdx
leaq 0x9aba(%rip), %rsi      # 0xebc0
addq %rsi, %rdx
xorl %r8d, %r8d
testl %ecx, %ecx
cmovlel %r8d, %ecx
leaq 0x9aab(%rip), %r9       # 0xebc4
movl %edi, %eax
cmpq %r8, %rcx
je 0x5196
movswl -0x4(%r9), %r10d
movswl (%rdx), %r11d
movl %r10d, %r14d
xorl %r11d, %r14d
movzwl (%r9), %ebx
movzwl 0x4(%rdx), %ebp
movl %ebp, %r15d
xorl %ebx, %r15d
orw %r14w, %r15w
je 0x5161
movswl %bx, %ebx
movswl %bp, %ebp
addl %r10d, %ebx
addl %r11d, %ebp
cmpl %ebp, %ebx
cmovll %ebx, %ebp
cmpw %r11w, %r10w
cmovgl %r10d, %r11d
cmpl %r11d, %ebp
jle 0x518d
movswl -0x2(%r9), %r10d
movswl 0x2(%rdx), %r11d
movswl 0x6(%rdx), %ebx
addl %r11d, %ebx
cmpl %r10d, %ebx
jg 0x518d
cmpl %edi, %eax
je 0x518a
movslq %eax, %r11
imulq $0x48, %r11, %r11
cmpw 0x2(%r11,%rsi), %r10w
jg 0x518d
movl %r8d, %eax
incq %r8
addq $0x48, %r9
jmp 0x511b
cmpl %edi, %eax
jne 0x5318
leaq 0x9a1d(%rip), %r8       # 0xebc2
xorl %r9d, %r9d
movl %edi, %eax
cmpq %r9, %rcx
je 0x5318
movswl (%r8), %r10d
movswl 0x2(%rdx), %r11d
movswl 0x6(%rdx), %ebx
addl %r11d, %ebx
cmpl %r10d, %ebx
jg 0x51de
cmpl %edi, %eax
je 0x51db
movslq %eax, %r11
imulq $0x48, %r11, %r11
cmpw 0x2(%r11,%rsi), %r10w
jg 0x51de
movl %r9d, %eax
incq %r9
addq $0x48, %r8
jmp 0x51aa
movl 0x9583(%rip), %ecx      # 0xe770
movslq %edi, %rax
imulq $0x48, %rax, %rdx
leaq 0x99c5(%rip), %rsi      # 0xebc0
addq %rsi, %rdx
xorl %r8d, %r8d
testl %ecx, %ecx
cmovlel %r8d, %ecx
movq %rsi, %r9
movl %edi, %eax
cmpq %r8, %rcx
je 0x52ce
movswl 0x2(%r9), %r10d
movswl 0x2(%rdx), %r11d
movl %r10d, %r14d
xorl %r11d, %r14d
movzwl 0x6(%r9), %ebx
movzwl 0x6(%rdx), %ebp
movl %ebp, %r15d
xorl %ebx, %r15d
orw %r14w, %r15w
je 0x5258
movswl %bx, %ebx
movswl %bp, %ebp
addl %r10d, %ebx
addl %r11d, %ebp
cmpl %ebp, %ebx
cmovll %ebx, %ebp
cmpw %r11w, %r10w
cmovgl %r10d, %r11d
cmpl %r11d, %ebp
jle 0x5281
movswl (%r9), %r10d
movswl (%rdx), %r11d
movswl 0x4(%rdx), %ebx
addl %r11d, %ebx
cmpl %r10d, %ebx
jg 0x5281
cmpl %edi, %eax
je 0x527e
movslq %eax, %r11
imulq $0x48, %r11, %r11
cmpw (%r11,%rsi), %r10w
jg 0x5281
movl %r8d, %eax
incq %r8
addq $0x48, %r9
jmp 0x520c
cmpl %edi, %eax
jne 0x5318
leaq 0x9927(%rip), %rsi      # 0xebc0
xorl %r8d, %r8d
movq %rsi, %r9
movl %edi, %eax
cmpq %r8, %rcx
je 0x5318
movzwl (%r9), %r10d
cmpw (%rdx), %r10w
jge 0x52c5
cmpl %edi, %eax
je 0x52c2
movslq %eax, %r11
imulq $0x48, %r11, %r11
cmpw (%r11,%rsi), %r10w
jl 0x52c5
movl %r8d, %eax
incq %r8
addq $0x48, %r9
jmp 0x52a1
cmpl %edi, %eax
jne 0x5318
leaq 0x98e7(%rip), %rsi      # 0xebc0
xorl %r8d, %r8d
movq %rsi, %r9
movl %edi, %eax
cmpq %r8, %rcx
je 0x5318
movswl (%r9), %r10d
movswl (%rdx), %r11d
movswl 0x4(%rdx), %ebx
addl %r11d, %ebx
cmpl %r10d, %ebx
jg 0x530f
cmpl %edi, %eax
je 0x530c
movslq %eax, %r11
imulq $0x48, %r11, %r11
cmpw (%r11,%rsi), %r10w
jg 0x530f
movl %r8d, %eax
incq %r8
addq $0x48, %r9
jmp 0x52e1
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl %edi, %eax
retq