#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);
int /*<<< orphan*/ mergeSecondInFirstAtAlt(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;
  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 \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 \n");
  }
  printList(head1);
  printList(head2);
  mergeSecondInFirstAtAlt(head1, &head2);
  printList(head1);
  printList(head2);
  destroyList(head1);
  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,-0x848(%rbp)
lea    -0x840(%rbp),%rdi
mov    0x2e26(%rip),%rax
mov    (%rax),%edx
mov    $0x800,%esi
call   1060 <fgets@plt>
lea    -0x840(%rbp),%rdi
lea    0xe24(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x848(%rbp)
cmpq   $0x0,-0x848(%rbp)
je     1239 <main+0xc9>
mov    -0x848(%rbp),%rdi
lea    0xe05(%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    0xde4(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x848(%rbp)
jmp    11e8 <main+0x78>
lea    -0x840(%rbp),%rdi
mov    0x2da1(%rip),%rax
mov    (%rax),%edx
mov    $0x800,%esi
call   1060 <fgets@plt>
lea    -0x840(%rbp),%rdi
lea    0xd9f(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x848(%rbp)
cmpq   $0x0,-0x848(%rbp)
je     12be <main+0x14e>
mov    -0x848(%rbp),%rdi
lea    0xd80(%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    0xd5f(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x848(%rbp)
jmp    126d <main+0xfd>
mov    -0x20(%rbp),%rdi
call   1090 <printList@plt>
mov    -0x30(%rbp),%rdi
call   1090 <printList@plt>
mov    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <mergeSecondInFirstAtAlt@plt>
mov    -0x20(%rbp),%rdi
call   1090 <printList@plt>
mov    -0x30(%rbp),%rdi
call   1090 <printList@plt>
mov    -0x20(%rbp),%rdi
call   1050 <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,0x10(%rsp)
movq   $0x0,0x28(%rsp)
movq   $0x0,0x18(%rsp)
movq   $0x0,0x20(%rsp)
mov    0x2e3c(%rip),%rbp
mov    0x0(%rbp),%edx
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x800,%esi
call   1060 <fgets@plt>
lea    0xe38(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strtok@plt>
test   %rax,%rax
je     122c <main+0xbc>
lea    0xe2d(%rip),%r14
lea    0xc(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0x28(%rsp),%r13
lea    0xe1a(%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   1060 <fgets@plt>
lea    0xdb8(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strtok@plt>
test   %rax,%rax
je     12ac <main+0x13c>
lea    0xdad(%rip),%r14
lea    0xc(%rsp),%r15
lea    0x18(%rsp),%r12
lea    0x20(%rsp),%r13
lea    0xd9a(%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    0x10(%rsp),%rdi
call   1090 <printList@plt>
mov    0x18(%rsp),%rdi
call   1090 <printList@plt>
mov    0x10(%rsp),%rdi
lea    0x18(%rsp),%rsi
call   1040 <mergeSecondInFirstAtAlt@plt>
mov    0x10(%rsp),%rdi
call   1090 <printList@plt>
mov    0x18(%rsp),%rdi
call   1090 <printList@plt>
mov    0x10(%rsp),%rdi
call   1050 <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 = [9 x i8] c"NULL >|\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [11 x i8] c"> | 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 [2048 x i8]
%12 = 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 i8* null, i8** %12
%13 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%14 = load i32, i32* @stdin
%15 = call i32 @fgets(i8* %13, i32 2048, i32 %14)
%16 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%17 = call i8* @strtok(i8* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %17, i8** %12
br label %18
18: ; preds = %21, %2
%19 = load i8*, i8** %12
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i8*, i8** %12
%23 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%24 = load i32, i32* %6
%25 = call i32 @insertNode(%struct.node** %7, %struct.node** %8, i32 %24)
%26 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i8* %26, i8** %12
br label %18
27: ; preds = %18
%28 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%29 = load i32, i32* @stdin
%30 = call i32 @fgets(i8* %28, i32 2048, i32 %29)
%31 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%32 = call i8* @strtok(i8* %31, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %32, i8** %12
br label %33
33: ; preds = %36, %27
%34 = load i8*, i8** %12
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %42
36: ; preds = %33
%37 = load i8*, i8** %12
%38 = call i32 @sscanf(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%39 = load i32, i32* %6
%40 = call i32 @insertNode(%struct.node** %9, %struct.node** %10, i32 %39)
%41 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i8* %41, i8** %12
br label %33
42: ; preds = %33
%43 = load %struct.node*, %struct.node** %7
%44 = call i32 @printList(%struct.node* %43)
%45 = load %struct.node*, %struct.node** %9
%46 = call i32 @printList(%struct.node* %45)
%47 = load %struct.node*, %struct.node** %7
%48 = call i32 @mergeSecondInFirstAtAlt(%struct.node* %47, %struct.node** %9)
%49 = load %struct.node*, %struct.node** %7
%50 = call i32 @printList(%struct.node* %49)
%51 = load %struct.node*, %struct.node** %9
%52 = call i32 @printList(%struct.node* %51)
%53 = load %struct.node*, %struct.node** %7
%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 = [9 x i8] c"NULL >|\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [11 x i8] c"> | 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 ([9 x i8], [9 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 ([11 x i8], [11 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 ([9 x i8], [9 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 ([11 x i8], [11 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 = call i32 @mergeSecondInFirstAtAlt(%struct.node* %43, %struct.node** %6)
%45 = load %struct.node*, %struct.node** %4
%46 = call i32 @printList(%struct.node* %45)
%47 = load %struct.node*, %struct.node** %6
%48 = call i32 @printList(%struct.node* %47)
%49 = load %struct.node*, %struct.node** %4
%50 = call i32 @destroyList(%struct.node* %49)
ret i32 0
}