// File: /workspace/github_c_makefile_star2_O1/ComplexNetworks-DCC-FCUP[P]gtrieScanner/Random.cpp
// Function: Random::markovChainPerEdge(Graph*, int, int)
void Random::markovChainPerEdge(Graph *g, int num, int tries) {
  int i, j, k, n, edges, nodes = g->numNodes();
  int a, b, c, d, aux;
  vector<int> *v, *u;
  vector<int>:: iterator ii;

  a=b=c=d=0;
  for (n=0; n<num; n++)
    for (i=0; i<nodes; i++) {
      v = g->outEdges(i);
      edges = v->size();
      a = i;
      for (j=0; j<edges; j++) {
	b = (*v)[j];
	for (k=0; k<tries; k++) {
	  c = getInteger(0, nodes-1);
	  if (a==c || b==c || g->hasEdge(c,b)) continue;
	  aux = g->nodeOutEdges(c); 
	  if (aux==0) continue;
	  u = g->outEdges(c);
	  d = getInteger(1, aux);
	  d = (*u)[d-1];
	  if (a==d || b==d || g->hasEdge(a,d)) continue;
	  break;
	}
	if (k<tries) { // Found an edge to swap!
	  fflush(stdout);
	  g->rmEdge(a,b);  g->rmEdge(c,d);
	  g->addEdge(a,d); g->addEdge(c,b);
	  if (g->type() == UNDIRECTED) {
	    g->rmEdge(b,a);  g->rmEdge(d,c);
	    g->addEdge(d,a); g->addEdge(b,c);
	  }
	}
      }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %edx, %ebx
movl %esi, %ebp
movq %rdi, %r14
movq (%rdi), %rax
callq *0x40(%rax)
movl %eax, 0x14(%rsp)
movl %ebp, 0x28(%rsp)
testl %ebp, %ebp
jle 0xb4eb
testl %ebx, %ebx
setg 0xf(%rsp)
cvtsi2sdl 0x14(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
movl %ebx, %eax
negl %eax
movq %rax, 0x48(%rsp)
movq $0x0, 0x20(%rsp)
xorl %r13d, %r13d
xorl %eax, %eax
movl %ebx, 0x18(%rsp)
movl %eax, 0x2c(%rsp)
cmpl $0x0, 0x14(%rsp)
jle 0xb4db
xorl %r12d, %r12d
movq (%r14), %rax
movq %r14, %rdi
movl %r12d, %esi
callq *0xb8(%rax)
movq 0x8(%rax), %rcx
movq %rax, 0x38(%rsp)
subq (%rax), %rcx
shrq $0x2, %rcx
testl %ecx, %ecx
jle 0xb4cd
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
movl %r12d, 0x1c(%rsp)
movq %rcx, 0x30(%rsp)
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq %rdx, 0x40(%rsp)
movl (%rax,%rdx,4), %eax
movl %eax, 0x10(%rsp)
testl %ebx, %ebx
jle 0xb3f9
movl $0x1, %ebp
movb 0xf(%rsp), %r15b
callq 0x2100
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x6a81(%rip), %xmm0     # 0x11d90
mulsd 0x50(%rsp), %xmm0
addsd 0x5cf3(%rip), %xmm0     # 0x11010
cvttsd2si %xmm0, %r13d
cmpl %r13d, %r12d
je 0xb3d4
movl 0x10(%rsp), %edx
cmpl %r13d, %edx
je 0xb3d4
movq (%r14), %rax
movq %r14, %rdi
movl %r13d, %esi
callq *0x50(%rax)
testb %al, %al
jne 0xb3d4
movq (%r14), %rax
movq %r14, %rdi
movl %r13d, %esi
callq *0x60(%rax)
testl %eax, %eax
je 0xb3d4
movl %eax, %r12d
movq (%r14), %rax
movq %r14, %rdi
movl %r13d, %esi
callq *0xb8(%rax)
movq %rax, %rbx
callq 0x2100
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x6a0a(%rip), %xmm0     # 0x11d90
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
mulsd %xmm0, %xmm1
addsd 0x695e(%rip), %xmm1     # 0x11cf8
cvttsd2si %xmm1, %eax
movq (%rbx), %rcx
cltq
movl -0x4(%rcx,%rax,4), %edx
movl 0x1c(%rsp), %esi
cmpl %edx, %esi
movq %rdx, 0x20(%rsp)
je 0xb3d0
cmpl %edx, 0x10(%rsp)
je 0xb3d0
movq (%r14), %rax
movq %r14, %rdi
callq *0x50(%rax)
testb %al, %al
movl 0x18(%rsp), %ebx
jne 0xb3d4
jmp 0xb4c3
movl 0x18(%rsp), %ebx
cmpl %ebx, %ebp
setl %r15b
movq 0x48(%rsp), %rax
addl %ebp, %eax
incl %eax
movl %ebp, %ecx
incl %ecx
movl %ecx, %ebp
cmpl $0x1, %eax
movl 0x1c(%rsp), %r12d
jne 0xb2fa
jmp 0xb3fe
movb 0xf(%rsp), %r15b
testb $0x1, %r15b
je 0xb4ab
movq 0xcbb1(%rip), %rax      # 0x17fc0
movq (%rax), %rdi
callq 0x2240
movq (%r14), %rax
movq %r14, %rdi
movl %r12d, %esi
movl 0x10(%rsp), %ebp
movl %ebp, %edx
callq *0x38(%rax)
movq (%r14), %rax
movq %r14, %rdi
movl %r13d, %esi
movq 0x20(%rsp), %r15
movl %r15d, %edx
callq *0x38(%rax)
movq (%r14), %rax
movq %r14, %rdi
movl %r12d, %esi
movl %r15d, %edx
callq *0x30(%rax)
movq (%r14), %rax
movq %r14, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq *0x30(%rax)
movq (%r14), %rax
movq %r14, %rdi
callq *0x20(%rax)
cmpl $0x1, %eax
jne 0xb4ab
movq (%r14), %rax
movq %r14, %rdi
movl 0x10(%rsp), %ebp
movl %ebp, %esi
movl %r12d, %edx
callq *0x38(%rax)
movq (%r14), %rax
movq %r14, %rdi
movq 0x20(%rsp), %r15
movl %r15d, %esi
movl %r13d, %edx
callq *0x38(%rax)
movq (%r14), %rax
movq %r14, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq *0x30(%rax)
movq (%r14), %rax
movq %r14, %rdi
movl %ebp, %esi
movl %r13d, %edx
callq *0x30(%rax)
movq 0x40(%rsp), %rdx
incq %rdx
movq 0x30(%rsp), %rcx
cmpq %rcx, %rdx
jne 0xb2d4
jmp 0xb4cd
movl 0x1c(%rsp), %r12d
jmp 0xb3fe
incl %r12d
cmpl 0x14(%rsp), %r12d
jne 0xb29b
movl 0x2c(%rsp), %eax
incl %eax
cmpl 0x28(%rsp), %eax
jne 0xb289
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop