#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 *mergeTwoLists(struct ListNode *, struct ListNode *);
struct ListNode *mergeKLists(struct ListNode **lists, int listsSize) {
  struct ListNode *result = lists[0];
  int i = 1;
  for (i = 1; i < listsSize; i++) {
    result = mergeTwoLists(result, lists[i]);
  }
  return result;
}


x86 assembly (clang, -O0):
<mergeKLists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    116b <mergeKLists+0x5b>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <mergeTwoLists@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1138 <mergeKLists+0x28>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergeKLists>:
push   %r15
push   %r14
push   %rbx
mov    (%rdi),%rax
cmp    $0x2,%esi
jl     1145 <mergeKLists+0x35>
mov    %rdi,%r14
mov    %esi,%r15d
mov    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rsi
mov    %rax,%rdi
call   1030 <mergeTwoLists@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <mergeKLists+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.ListNode = type { i32 }
define %struct.ListNode* @mergeKLists(%struct.ListNode** %0, i32 %1) {
%3 = alloca %struct.ListNode**
%4 = alloca i32
%5 = alloca %struct.ListNode*
%6 = alloca i32
store %struct.ListNode** %0, %struct.ListNode*** %3
store i32 %1, i32* %4
%7 = load %struct.ListNode**, %struct.ListNode*** %3
%8 = getelementptr inbounds %struct.ListNode*, %struct.ListNode** %7, i64 0
%9 = load %struct.ListNode*, %struct.ListNode** %8
store %struct.ListNode* %9, %struct.ListNode** %5
store i32 1, i32* %6
store i32 1, i32* %6
br label %10
10: ; preds = %22, %2
%11 = load i32, i32* %6
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = load %struct.ListNode*, %struct.ListNode** %5
%16 = load %struct.ListNode**, %struct.ListNode*** %3
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds %struct.ListNode*, %struct.ListNode** %16, i64 %18
%20 = load %struct.ListNode*, %struct.ListNode** %19
%21 = call %struct.ListNode* @mergeTwoLists(%struct.ListNode* %15, %struct.ListNode* %20)
store %struct.ListNode* %21, %struct.ListNode** %5
br label %22
22: ; preds = %14
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
br label %10
25: ; preds = %10
%26 = load %struct.ListNode*, %struct.ListNode** %5
ret %struct.ListNode* %26
}

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