#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 node {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ destroyList(struct node *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ insertNode(struct node **, struct node **, int);
struct node *mergeTwoSortedRecursive(struct node *, struct node *);
int /*<<< orphan*/ printList(struct node *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stdin;
char *strtok(char *, char *);
int main(int argc, char *argv[]) {
  int value;
  struct node *head1 = NULL;
  struct node *tail1 = NULL;
  struct node *head2 = NULL;
  struct node *tail2 = NULL;
  struct node *resultHead = NULL;
  char buffer[2048];
  char *p = NULL;
  fgets(buffer, 2048, stdin);
  p = strtok(buffer, "NULL > | \n");
  while (p != NULL) {
    sscanf(p, "%d", &value);
    insertNode(&head1, &tail1, value);
    p = strtok(NULL, "NULL null | > \n");
  }
  fgets(buffer, 2048, stdin);
  p = strtok(buffer, "NULL > | \n");
  while (p != NULL) {
    sscanf(p, "%d", &value);
    insertNode(&head2, &tail2, value);
    p = strtok(NULL, "NULL null | > \n");
  }
  printList(head1);
  printList(head2);
  resultHead = mergeTwoSortedRecursive(head1, head2);
  printList(resultHead);
  destroyList(resultHead);
  head1 = NULL;
  tail1 = NULL;
  head2 = NULL;
  tail2 = NULL;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x848(%rbp)
lea    -0x840(%rbp),%rdi
mov    0x2e1e(%rip),%rax
mov    (%rax),%edx
mov    $0x800,%esi
call   1050 <fgets@plt>
lea    -0x840(%rbp),%rdi
lea    0xe1c(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x848(%rbp)
cmpq   $0x0,-0x848(%rbp)
je     1241 <main+0xd1>
mov    -0x848(%rbp),%rdi
lea    0xdff(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1070 <sscanf@plt>
mov    -0x14(%rbp),%edx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <insertNode@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdde(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x848(%rbp)
jmp    11f0 <main+0x80>
lea    -0x840(%rbp),%rdi
mov    0x2d99(%rip),%rax
mov    (%rax),%edx
mov    $0x800,%esi
call   1050 <fgets@plt>
lea    -0x840(%rbp),%rdi
lea    0xd97(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x848(%rbp)
cmpq   $0x0,-0x848(%rbp)
je     12c6 <main+0x156>
mov    -0x848(%rbp),%rdi
lea    0xd7a(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1070 <sscanf@plt>
mov    -0x14(%rbp),%edx
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1030 <insertNode@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd59(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x848(%rbp)
jmp    1275 <main+0x105>
mov    -0x20(%rbp),%rdi
call   1090 <printList@plt>
mov    -0x30(%rbp),%rdi
call   1090 <printList@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <mergeTwoSortedRecursive@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1090 <printList@plt>
mov    -0x40(%rbp),%rdi
call   1040 <destroyList@plt>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
xor    %eax,%eax
add    $0x850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x838,%rsp
movq   $0x0,0x18(%rsp)
movq   $0x0,0x28(%rsp)
movq   $0x0,0x10(%rsp)
movq   $0x0,0x20(%rsp)
mov    0x2e3c(%rip),%rbp
mov    0x0(%rbp),%edx
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x800,%esi
call   1050 <fgets@plt>
lea    0xe38(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strtok@plt>
test   %rax,%rax
je     122c <main+0xbc>
lea    0xe2f(%rip),%r14
lea    0xc(%rsp),%r15
lea    0x18(%rsp),%r12
lea    0x28(%rsp),%r13
lea    0xe1c(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1070 <sscanf@plt>
mov    0xc(%rsp),%edx
mov    %r12,%rdi
mov    %r13,%rsi
call   1030 <insertNode@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1080 <strtok@plt>
test   %rax,%rax
jne    1200 <main+0x90>
mov    0x0(%rbp),%edx
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x800,%esi
call   1050 <fgets@plt>
lea    0xdb8(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strtok@plt>
test   %rax,%rax
je     12ac <main+0x13c>
lea    0xdaf(%rip),%r14
lea    0xc(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0x20(%rsp),%r13
lea    0xd9c(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1070 <sscanf@plt>
mov    0xc(%rsp),%edx
mov    %r12,%rdi
mov    %r13,%rsi
call   1030 <insertNode@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1080 <strtok@plt>
test   %rax,%rax
jne    1280 <main+0x110>
mov    0x18(%rsp),%rdi
call   1090 <printList@plt>
mov    0x10(%rsp),%rdi
call   1090 <printList@plt>
mov    0x18(%rsp),%rdi
mov    0x10(%rsp),%rsi
call   1060 <mergeTwoSortedRecursive@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <printList@plt>
mov    %rbx,%rdi
call   1040 <destroyList@plt>
xor    %eax,%eax
add    $0x838,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.node = type { i32 }
@stdin = global i32 0
@.str = [11 x i8] c"NULL > | \0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"NULL null | > \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.node*
%8 = alloca %struct.node*
%9 = alloca %struct.node*
%10 = alloca %struct.node*
%11 = alloca %struct.node*
%12 = alloca [2048 x i8]
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store %struct.node* null, %struct.node** %7
store %struct.node* null, %struct.node** %8
store %struct.node* null, %struct.node** %9
store %struct.node* null, %struct.node** %10
store %struct.node* null, %struct.node** %11
store i8* null, i8** %13
%14 = getelementptr inbounds [2048 x i8], [2048 x i8]* %12, i64 0, i64 0
%15 = load i32, i32* @stdin
%16 = call i32 @fgets(i8* %14, i32 2048, i32 %15)
%17 = getelementptr inbounds [2048 x i8], [2048 x i8]* %12, i64 0, i64 0
%18 = call i8* @strtok(i8* %17, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %18, i8** %13
br label %19
19: ; preds = %22, %2
%20 = load i8*, i8** %13
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load i8*, i8** %13
%24 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%25 = load i32, i32* %6
%26 = call i32 @insertNode(%struct.node** %7, %struct.node** %8, i32 %25)
%27 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i8* %27, i8** %13
br label %19
28: ; preds = %19
%29 = getelementptr inbounds [2048 x i8], [2048 x i8]* %12, i64 0, i64 0
%30 = load i32, i32* @stdin
%31 = call i32 @fgets(i8* %29, i32 2048, i32 %30)
%32 = getelementptr inbounds [2048 x i8], [2048 x i8]* %12, i64 0, i64 0
%33 = call i8* @strtok(i8* %32, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %33, i8** %13
br label %34
34: ; preds = %37, %28
%35 = load i8*, i8** %13
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %43
37: ; preds = %34
%38 = load i8*, i8** %13
%39 = call i32 @sscanf(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%40 = load i32, i32* %6
%41 = call i32 @insertNode(%struct.node** %9, %struct.node** %10, i32 %40)
%42 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i8* %42, i8** %13
br label %34
43: ; preds = %34
%44 = load %struct.node*, %struct.node** %7
%45 = call i32 @printList(%struct.node* %44)
%46 = load %struct.node*, %struct.node** %9
%47 = call i32 @printList(%struct.node* %46)
%48 = load %struct.node*, %struct.node** %7
%49 = load %struct.node*, %struct.node** %9
%50 = call %struct.node* @mergeTwoSortedRecursive(%struct.node* %48, %struct.node* %49)
store %struct.node* %50, %struct.node** %11
%51 = load %struct.node*, %struct.node** %11
%52 = call i32 @printList(%struct.node* %51)
%53 = load %struct.node*, %struct.node** %11
%54 = call i32 @destroyList(%struct.node* %53)
store %struct.node* null, %struct.node** %7
store %struct.node* null, %struct.node** %8
store %struct.node* null, %struct.node** %9
store %struct.node* null, %struct.node** %10
ret i32 0
}

LLVM IR (-O2):
%struct.node = type { i32 }
@stdin = global i32 0
@.str = [11 x i8] c"NULL > | \0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"NULL null | > \0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca %struct.node*
%5 = alloca %struct.node*
%6 = alloca %struct.node*
%7 = alloca %struct.node*
%8 = alloca [2048 x i8]
%9 = bitcast i32* %3 to i8*
%10 = bitcast %struct.node** %4 to i8*
store %struct.node* null, %struct.node** %4
%11 = bitcast %struct.node** %5 to i8*
store %struct.node* null, %struct.node** %5
%12 = bitcast %struct.node** %6 to i8*
store %struct.node* null, %struct.node** %6
%13 = bitcast %struct.node** %7 to i8*
store %struct.node* null, %struct.node** %7
%14 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%15 = load i32, i32* @stdin
%16 = call i32 @fgets(i8* %14, i32 2048, i32 %15)
%17 = call i8* @strtok(i8* %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i8* %17, null
br i1 %18, label %26, label %19
19: ; preds = %2, %19
%20 = phi i8* [ %24, %19 ], [ %17, %2 ]
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%22 = load i32, i32* %3
%23 = call i32 @insertNode(%struct.node** %4, %struct.node** %5, i32 %22)
%24 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %19
26: ; preds = %19, %2
%27 = load i32, i32* @stdin
%28 = call i32 @fgets(i8* %14, i32 2048, i32 %27)
%29 = call i8* @strtok(i8* %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%30 = icmp eq i8* %29, null
br i1 %30, label %38, label %31
31: ; preds = %26, %31
%32 = phi i8* [ %36, %31 ], [ %29, %26 ]
%33 = call i32 @sscanf(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%34 = load i32, i32* %3
%35 = call i32 @insertNode(%struct.node** %6, %struct.node** %7, i32 %34)
%36 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %31
38: ; preds = %31, %26
%39 = load %struct.node*, %struct.node** %4
%40 = call i32 @printList(%struct.node* %39)
%41 = load %struct.node*, %struct.node** %6
%42 = call i32 @printList(%struct.node* %41)
%43 = load %struct.node*, %struct.node** %4
%44 = load %struct.node*, %struct.node** %6
%45 = call %struct.node* @mergeTwoSortedRecursive(%struct.node* %43, %struct.node* %44)
%46 = call i32 @printList(%struct.node* %45)
%47 = call i32 @destroyList(%struct.node* %45)
ret i32 0
}