#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct ListNode {
  int dummy;
};

/* Variables and functions */
struct ListNode *binaryMerge(struct ListNode *, struct ListNode *, int);
struct ListNode *mergeKListsDC(struct ListNode **, int, int);
struct ListNode *mergeKLists(struct ListNode **lists, int listsSize) {
  if (listsSize < 2) {
    return lists[0];
  }
  int mid = 0;
  if (listsSize == 2) {
    return binaryMerge(lists[0], lists[1], 1);
  } else {
    mid = listsSize / 2;
    return binaryMerge(mergeKListsDC(lists, 0, mid),
                       mergeKListsDC(lists, mid + 1, listsSize - 1), 1);
  }
}


x86 assembly (clang, -O0):
<mergeKLists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    1149 <mergeKLists+0x29>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11c6 <mergeKLists+0xa6>
movl   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x14(%rbp)
jne    117c <mergeKLists+0x5c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x1,%edx
call   1030 <binaryMerge@plt>
mov    %rax,-0x8(%rbp)
jmp    11c6 <mergeKLists+0xa6>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
xor    %esi,%esi
call   1040 <mergeKListsDC@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
add    $0x1,%esi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
call   1040 <mergeKListsDC@plt>
mov    -0x20(%rbp),%rdi
mov    %rax,%rsi
mov    $0x1,%edx
call   1030 <binaryMerge@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergeKLists>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
cmp    $0x1,%esi
jg     113d <mergeKLists+0x1d>
mov    (%rbx),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %esi,%ebp
cmp    $0x2,%esi
jne    114d <mergeKLists+0x2d>
mov    (%rbx),%rdi
mov    0x8(%rbx),%rsi
jmp    117d <mergeKLists+0x5d>
mov    %ebp,%r14d
shr    %r14d
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1040 <mergeKListsDC@plt>
mov    %rax,%r15
add    $0x1,%r14d
add    $0xffffffff,%ebp
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1040 <mergeKListsDC@plt>
mov    %r15,%rdi
mov    %rax,%rsi
mov    $0x1,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <binaryMerge@plt>

LLVM IR (-O0):
%struct.ListNode = type { i32 }
define %struct.ListNode* @mergeKLists(%struct.ListNode** %0, i32 %1) {
%3 = alloca %struct.ListNode*
%4 = alloca %struct.ListNode**
%5 = alloca i32
%6 = alloca i32
store %struct.ListNode** %0, %struct.ListNode*** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load %struct.ListNode**, %struct.ListNode*** %4
%11 = getelementptr inbounds %struct.ListNode*, %struct.ListNode** %10, i64 0
%12 = load %struct.ListNode*, %struct.ListNode** %11
store %struct.ListNode* %12, %struct.ListNode** %3
br label %37
13: ; preds = %2
store i32 0, i32* %6
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, 2
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = load %struct.ListNode**, %struct.ListNode*** %4
%18 = getelementptr inbounds %struct.ListNode*, %struct.ListNode** %17, i64 0
%19 = load %struct.ListNode*, %struct.ListNode** %18
%20 = load %struct.ListNode**, %struct.ListNode*** %4
%21 = getelementptr inbounds %struct.ListNode*, %struct.ListNode** %20, i64 1
%22 = load %struct.ListNode*, %struct.ListNode** %21
%23 = call %struct.ListNode* @binaryMerge(%struct.ListNode* %19, %struct.ListNode* %22, i32 1)
store %struct.ListNode* %23, %struct.ListNode** %3
br label %37
24: ; preds = %13
%25 = load i32, i32* %5
%26 = sdiv i32 %25, 2
store i32 %26, i32* %6
%27 = load %struct.ListNode**, %struct.ListNode*** %4
%28 = load i32, i32* %6
%29 = call %struct.ListNode* @mergeKListsDC(%struct.ListNode** %27, i32 0, i32 %28)
%30 = load %struct.ListNode**, %struct.ListNode*** %4
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
%33 = load i32, i32* %5
%34 = sub nsw i32 %33, 1
%35 = call %struct.ListNode* @mergeKListsDC(%struct.ListNode** %30, i32 %32, i32 %34)
%36 = call %struct.ListNode* @binaryMerge(%struct.ListNode* %29, %struct.ListNode* %35, i32 1)
store %struct.ListNode* %36, %struct.ListNode** %3
br label %37
37: ; preds = %24, %16, %9
%38 = load %struct.ListNode*, %struct.ListNode** %3
ret %struct.ListNode* %38
}

LLVM IR (-O2):
%struct.ListNode = type { i32 }
define %struct.ListNode* @mergeKLists(%struct.ListNode** %0, i32 %1) {
%3 = icmp slt i32 %1, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = load %struct.ListNode*, %struct.ListNode** %0
br label %20
6: ; preds = %2
%7 = icmp eq i32 %1, 2
br i1 %7, label %8, label %13
8: ; preds = %6
%9 = load %struct.ListNode*, %struct.ListNode** %0
%10 = getelementptr inbounds %struct.ListNode*, %struct.ListNode** %0, i64 1
%11 = load %struct.ListNode*, %struct.ListNode** %10
%12 = tail call %struct.ListNode* @binaryMerge(%struct.ListNode* %9, %struct.ListNode* %11, i32 1)
br label %20
13: ; preds = %6
%14 = lshr i32 %1, 1
%15 = tail call %struct.ListNode* @mergeKListsDC(%struct.ListNode** %0, i32 0, i32 %14)
%16 = add nuw nsw i32 %14, 1
%17 = add nsw i32 %1, -1
%18 = tail call %struct.ListNode* @mergeKListsDC(%struct.ListNode** %0, i32 %16, i32 %17)
%19 = tail call %struct.ListNode* @binaryMerge(%struct.ListNode* %15, %struct.ListNode* %18, i32 1)
br label %20
20: ; preds = %8, %13, %4
%21 = phi %struct.ListNode* [ %5, %4 ], [ %12, %8 ], [ %19, %13 ]
ret %struct.ListNode* %21
}