#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 *merge(struct ListNode **lists, int beg, int end) {
  if (beg > end)
    return NULL;
  if (beg == end)
    return lists[beg];
  int mid = (beg + end) / 2;
  struct ListNode *left = merge(lists, beg, mid);
  struct ListNode *right = merge(lists, mid + 1, end);
  return mergeTwoLists(left, right);
}


x86 assembly (clang, -O0):
<merge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    114b <merge+0x2b>
movq   $0x0,-0x8(%rbp)
jmp    11b7 <merge+0x97>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    116c <merge+0x4c>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
jmp    11b7 <merge+0x97>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1030 <merge@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    -0x18(%rbp),%edx
call   1030 <merge@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <mergeTwoLists@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    %edx,%esi
jle    112f <merge+0xf>
xor    %eax,%eax
jmp    113b <merge+0x1b>
mov    %rdi,%r14
jne    1146 <merge+0x26>
movslq %esi,%rax
mov    (%r14,%rax,8),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %edx,%ebx
lea    (%rbx,%rsi,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %r14,%rdi
mov    %ebp,%edx
call   1030 <merge@plt>
mov    %rax,%r15
add    $0x1,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <merge@plt>
mov    %r15,%rdi
mov    %rax,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <mergeTwoLists@plt>

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

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