#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 *merge2(struct ListNode *, struct ListNode *);
struct ListNode *mergeKLists(struct ListNode **lists, int listsSize) {
  if (!listsSize)
    return (((struct ListNode *)0));
  if (listsSize == 1)
    return (lists[0]);
  int m;
  struct ListNode *h1, *h2;
  m = listsSize >> 1;
  h1 = mergeKLists(lists, m);
  h2 = mergeKLists(lists + m, listsSize - m);
  return (merge2(h1, h2));
}


x86 assembly (clang, -O0):
<mergeKLists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1146 <mergeKLists+0x26>
movq   $0x0,-0x8(%rbp)
jmp    11a8 <mergeKLists+0x88>
cmpl   $0x1,-0x14(%rbp)
jne    1160 <mergeKLists+0x40>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11a8 <mergeKLists+0x88>
mov    -0x14(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <mergeKLists@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x14(%rbp),%esi
sub    -0x18(%rbp),%esi
call   1030 <mergeKLists@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <merge2@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergeKLists>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
je     113a <mergeKLists+0x1a>
mov    %esi,%ebx
mov    %rdi,%r14
cmp    $0x1,%esi
jne    1147 <mergeKLists+0x27>
mov    (%r14),%rax
jmp    113c <mergeKLists+0x1c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebx,%ebp
sar    %ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <mergeKLists@plt>
mov    %rax,%r15
movslq %ebp,%rax
lea    (%r14,%rax,8),%rdi
sub    %eax,%ebx
mov    %ebx,%esi
call   1030 <mergeKLists@plt>
mov    %r15,%rdi
mov    %rax,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <merge2@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
%7 = alloca %struct.ListNode*
%8 = alloca %struct.ListNode*
store %struct.ListNode** %0, %struct.ListNode*** %4
store i32 %1, i32* %5
%9 = load i32, i32* %5
%10 = icmp ne i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %2
store %struct.ListNode* null, %struct.ListNode** %3
br label %36
12: ; preds = %2
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load %struct.ListNode**, %struct.ListNode*** %4
%17 = getelementptr inbounds %struct.ListNode*, %struct.ListNode** %16, i64 0
%18 = load %struct.ListNode*, %struct.ListNode** %17
store %struct.ListNode* %18, %struct.ListNode** %3
br label %36
19: ; preds = %12
%20 = load i32, i32* %5
%21 = ashr i32 %20, 1
store i32 %21, i32* %6
%22 = load %struct.ListNode**, %struct.ListNode*** %4
%23 = load i32, i32* %6
%24 = call %struct.ListNode* @mergeKLists(%struct.ListNode** %22, i32 %23)
store %struct.ListNode* %24, %struct.ListNode** %7
%25 = load %struct.ListNode**, %struct.ListNode*** %4
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds %struct.ListNode*, %struct.ListNode** %25, i64 %27
%29 = load i32, i32* %5
%30 = load i32, i32* %6
%31 = sub nsw i32 %29, %30
%32 = call %struct.ListNode* @mergeKLists(%struct.ListNode** %28, i32 %31)
store %struct.ListNode* %32, %struct.ListNode** %8
%33 = load %struct.ListNode*, %struct.ListNode** %7
%34 = load %struct.ListNode*, %struct.ListNode** %8
%35 = call %struct.ListNode* @merge2(%struct.ListNode* %33, %struct.ListNode* %34)
store %struct.ListNode* %35, %struct.ListNode** %3
br label %36
36: ; preds = %19, %15, %11
%37 = load %struct.ListNode*, %struct.ListNode** %3
ret %struct.ListNode* %37
}

LLVM IR (-O2):
%struct.ListNode = type { i32 }
define %struct.ListNode* @mergeKLists(%struct.ListNode** %0, i32 %1) {
switch i32 %1, label %7 [
i32 0, label %5
i32 1, label %3
]
3: ; preds = %2
%4 = load %struct.ListNode*, %struct.ListNode** %0
br label %5
5: ; preds = %3, %2, %7
%6 = phi %struct.ListNode* [ %14, %7 ], [ %4, %3 ], [ null, %2 ]
ret %struct.ListNode* %6
7: ; preds = %2
%8 = ashr i32 %1, 1
%9 = tail call %struct.ListNode* @mergeKLists(%struct.ListNode** %0, i32 %8)
%10 = sext i32 %8 to i64
%11 = getelementptr inbounds %struct.ListNode*, %struct.ListNode** %0, i64 %10
%12 = sub nsw i32 %1, %8
%13 = tail call %struct.ListNode* @mergeKLists(%struct.ListNode** %11, i32 %12)
%14 = tail call %struct.ListNode* @merge2(%struct.ListNode* %9, %struct.ListNode* %13)
br label %5
}