// File: /workspace/github_c_makefile_star2_O3/ramirezsebas[P]TP-LISTINGS/./src/capitulo_4/4.12/job-queue3.c
// Function: merge
void merge(int* a, int low, int mid, int high) 
{ 
    int* left = malloc(sizeof(int) * (mid - low + 1)); 
    int* right = malloc(sizeof(int) * (high - mid)); 
  
    // n1 is size of left part and n2 is size 
    // of right part 
    int n1 = mid - low + 1, n2 = high - mid, i, j; 
  
    // storing values in left part 
    for (i = 0; i < n1; i++) 
        left[i] = a[i + low]; 
  
    // storing values in right part 
    for (i = 0; i < n2; i++) 
        right[i] = a[i + mid + 1]; 
  
    int k = low; 
    i = j = 0; 
  
    // merge left and right in ascending order 
    while (i < n1 && j < n2) { 
        if (left[i] <= right[j]) 
            a[k++] = left[i++]; 
        else
            a[k++] = right[j++]; 
    } 
  
    // insert remaining values from left 
    while (i < n1) { 
        a[k++] = left[i++]; 
    } 
  
    // insert remaining values from right 
    while (j < n2) { 
        a[k++] = right[j++]; 
    }

    free(left);
    free(right); 
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, %r13d
movl %edx, %r12d
movl %esi, %r15d
movq %rdi, -0x38(%rbp)
movl %edx, %r14d
subl %esi, %r14d
movslq %r14d, %rbx
leaq 0x4(,%rbx,4), %rdi
callq 0x10e0
movq %rax, %rcx
movq %r13, %rax
movq %r13, -0x58(%rbp)
movq %rcx, %r13
subl %r12d, %eax
movl %eax, -0x2c(%rbp)
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x10e0
movq %rax, %rdi
testl %ebx, %ebx
movq -0x38(%rbp), %rcx
movq %rax, -0x50(%rbp)
js 0x178a
movslq %r15d, %rax
leaq (%rcx,%rax,4), %rsi
leal 0x1(%r14), %edx
shlq $0x2, %rdx
movq %r13, %rdi
callq 0x10b0
movq -0x50(%rbp), %rdi
movl %r15d, -0x3c(%rbp)
movq %r13, -0x48(%rbp)
xorl %r13d, %r13d
movl %r12d, %r15d
notl %r15d
movl -0x2c(%rbp), %r10d
testl %r10d, %r10d
movl %r12d, -0x40(%rbp)
jle 0x1841
setle %bl
movslq %r12d, %rax
movq -0x38(%rbp), %rcx
leaq 0x4(%rcx,%rax,4), %rsi
movq -0x58(%rbp), %rax
addl %r15d, %eax
leaq 0x4(,%rax,4), %rdx
callq 0x10b0
movl -0x2c(%rbp), %r10d
movq -0x50(%rbp), %r9
testl %r14d, %r14d
sets %al
orb %bl, %al
movl $0x0, %ebx
movl -0x3c(%rbp), %r11d
movl %r11d, %r12d
movq -0x48(%rbp), %r8
jne 0x184e
movslq %r11d, %rax
movq -0x38(%rbp), %rcx
leaq (%rcx,%rax,4), %rax
xorl %ebx, %ebx
movl %r11d, %r12d
xorl %r13d, %r13d
movl %r13d, %ecx
movl %ebx, %edx
movl %r13d, %esi
movl (%r8,%rsi,4), %esi
movl %ebx, %edi
movl (%r9,%rdi,4), %edi
xorl %ebx, %ebx
xorl %r13d, %r13d
cmpl %edi, %esi
setg %bl
setle %r13b
cmovll %esi, %edi
addl %ecx, %r13d
addl %edx, %ebx
movl %edi, (%rax)
incl %r12d
cmpl %r14d, %r13d
jg 0x184e
addq $0x4, %rax
cmpl %r10d, %ebx
jl 0x1804
jmp 0x184e
xorl %ebx, %ebx
movl -0x3c(%rbp), %r11d
movl %r11d, %r12d
movq -0x48(%rbp), %r8
cmpl %r14d, %r13d
jle 0x1859
movq -0x38(%rbp), %r14
jmp 0x189b
movslq %r12d, %rax
movq -0x38(%rbp), %r14
leaq (%r14,%rax,4), %rdi
movslq %r13d, %rax
leaq (%r8,%rax,4), %rsi
addl %r13d, %r11d
movl -0x40(%rbp), %eax
subl %r11d, %eax
leaq 0x4(,%rax,4), %rdx
movl %r11d, %r13d
callq 0x10b0
addl %r13d, %r15d
xorl %eax, %eax
decl %eax
cmpl %eax, %r15d
jne 0x1889
subl %eax, %r12d
movq -0x48(%rbp), %r8
movl -0x2c(%rbp), %r10d
cmpl %r10d, %ebx
jge 0x18cb
movslq %r12d, %rax
leaq (%r14,%rax,4), %rdi
movslq %ebx, %rax
movq -0x50(%rbp), %rcx
leaq (%rcx,%rax,4), %rsi
notl %ebx
addl -0x58(%rbp), %ebx
subl -0x40(%rbp), %ebx
leaq 0x4(,%rbx,4), %rdx
callq 0x10b0
movq -0x48(%rbp), %r8
movq %r8, %rdi
callq 0x1030
movq -0x50(%rbp), %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1030