// File: /workspace/github_c_makefile_star2_O1/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, -0x48(%rbp)
movl %edx, %r14d
subl %esi, %r14d
movslq %r14d, %rbx
leaq 0x4(,%rbx,4), %rdi
callq 0x10e0
movq %rax, -0x38(%rbp)
movq %r13, -0x50(%rbp)
subl %r12d, %r13d
movslq %r13d, %rdi
shlq $0x2, %rdi
callq 0x10e0
movq %rax, %r10
movl %r15d, -0x2c(%rbp)
movslq %r15d, %r15
testl %ebx, %ebx
movq -0x48(%rbp), %rax
movq %r10, -0x40(%rbp)
js 0x179b
leaq (%rax,%r15,4), %rsi
leal 0x1(%r14), %edx
shlq $0x2, %rdx
movq -0x38(%rbp), %rdi
callq 0x10b0
movq -0x40(%rbp), %r10
movq %r15, -0x58(%rbp)
movl %r12d, %r15d
notl %r15d
testl %r13d, %r13d
jle 0x17d4
movslq %r12d, %rax
movq -0x48(%rbp), %rcx
leaq (%rcx,%rax,4), %rsi
addq $0x4, %rsi
movq -0x50(%rbp), %rax
addl %r15d, %eax
leaq 0x4(,%rax,4), %rdx
movq %r10, %rdi
callq 0x10b0
movq -0x40(%rbp), %r10
movl %r12d, -0x30(%rbp)
testl %r14d, %r14d
sets %cl
testl %r13d, %r13d
setle %dl
xorl %eax, %eax
orb %cl, %dl
movl $0x0, %ebx
movl -0x2c(%rbp), %r12d
movq -0x38(%rbp), %r9
movq -0x48(%rbp), %r11
jne 0x1844
movq -0x58(%rbp), %rax
leaq (%r11,%rax,4), %rcx
xorl %ebx, %ebx
movl -0x2c(%rbp), %r12d
xorl %eax, %eax
movl %eax, %edx
movl %ebx, %esi
movl %eax, %eax
movl (%r9,%rax,4), %edi
movl %ebx, %eax
movl (%r10,%rax,4), %r8d
xorl %ebx, %ebx
xorl %eax, %eax
cmpl %r8d, %edi
setg %bl
setle %al
cmovll %edi, %r8d
addl %edx, %eax
addl %esi, %ebx
movl %r8d, (%rcx)
incl %r12d
cmpl %r14d, %eax
jg 0x1844
addq $0x4, %rcx
cmpl %r13d, %ebx
jl 0x180b
cmpl %r14d, %eax
jg 0x1888
movslq %r12d, %rcx
leaq (%r11,%rcx,4), %rdi
movslq %eax, %rcx
leaq (%r9,%rcx,4), %rsi
movl -0x2c(%rbp), %r14d
addl %eax, %r14d
movl -0x30(%rbp), %eax
subl %r14d, %eax
leaq 0x4(,%rax,4), %rdx
callq 0x10b0
addl %r14d, %r15d
xorl %eax, %eax
decl %eax
cmpl %eax, %r15d
jne 0x1876
subl %eax, %r12d
movq -0x38(%rbp), %r9
movq -0x48(%rbp), %r11
cmpl %r13d, %ebx
jge 0x18b8
movslq %r12d, %rax
leaq (%r11,%rax,4), %rdi
movslq %ebx, %rax
movq -0x40(%rbp), %rcx
leaq (%rcx,%rax,4), %rsi
notl %ebx
addl -0x50(%rbp), %ebx
subl -0x30(%rbp), %ebx
leaq 0x4(,%rbx,4), %rdx
callq 0x10b0
movq -0x38(%rbp), %r9
movq %r9, %rdi
callq 0x1030
movq -0x40(%rbp), %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1030