#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 */

/* Variables and functions */
unsigned int *merge_and_stuff(unsigned int *, unsigned int *);
unsigned *sort_and_stuff(unsigned *lst) {
  unsigned *tort, **ptort, *hare, *la, *lb;
  hare = tort = lst;
  while (hare != 0 && (((unsigned **)hare)[1]) != 0) {
    hare = (((unsigned **)(((unsigned **)hare)[1]))[1]);
    ptort = &(((unsigned **)tort)[1]);
    tort = (((unsigned **)tort)[1]);
  }
  if (tort == lst)
    return lst;
  *ptort = 0;
  la = sort_and_stuff(lst);
  lb = sort_and_stuff(tort);
  return merge_and_stuff(la, lb);
}


x86 assembly (clang, -O0):
<sort_and_stuff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x28(%rbp)
mov    %al,-0x39(%rbp)
je     1157 <sort_and_stuff+0x37>
mov    -0x28(%rbp),%rax
cmpq   $0x0,0x8(%rax)
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1167 <sort_and_stuff+0x47>
jmp    1194 <sort_and_stuff+0x74>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1138 <sort_and_stuff+0x18>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    11af <sort_and_stuff+0x8f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e5 <sort_and_stuff+0xc5>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <sort_and_stuff@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <sort_and_stuff@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1030 <merge_and_stuff@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sort_and_stuff>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     115f <sort_and_stuff+0x3f>
mov    0x8(%rdi),%rcx
test   %rcx,%rcx
je     118f <sort_and_stuff+0x6f>
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rax
mov    0x8(%rcx),%rcx
mov    0x8(%rbx),%rbx
add    $0x8,%rax
test   %rcx,%rcx
je     1161 <sort_and_stuff+0x41>
mov    0x8(%rcx),%rcx
test   %rcx,%rcx
jne    1140 <sort_and_stuff+0x20>
jmp    1161 <sort_and_stuff+0x41>
xor    %ebx,%ebx
cmp    %rdi,%rbx
je     1197 <sort_and_stuff+0x77>
movq   $0x0,(%rax)
call   1040 <sort_and_stuff@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <sort_and_stuff@plt>
mov    %r14,%rdi
mov    %rax,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <merge_and_stuff@plt>
mov    %rdi,%rbx
cmp    %rdi,%rbx
jne    1166 <sort_and_stuff+0x46>
mov    %rdi,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32* @sort_and_stuff(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
store i32* %0, i32** %3
%9 = load i32*, i32** %3
store i32* %9, i32** %4
store i32* %9, i32** %6
br label %10
10: ; preds = %21, %1
%11 = load i32*, i32** %6
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i32*, i32** %6
%15 = bitcast i32* %14 to i32**
%16 = getelementptr inbounds i32*, i32** %15, i64 1
%17 = load i32*, i32** %16
%18 = icmp ne i32* %17, null
br label %19
19: ; preds = %13, %10
%20 = phi i1 [ false, %10 ], [ %18, %13 ]
br i1 %20, label %21, label %36
21: ; preds = %19
%22 = load i32*, i32** %6
%23 = bitcast i32* %22 to i32**
%24 = getelementptr inbounds i32*, i32** %23, i64 1
%25 = load i32*, i32** %24
%26 = bitcast i32* %25 to i32**
%27 = getelementptr inbounds i32*, i32** %26, i64 1
%28 = load i32*, i32** %27
store i32* %28, i32** %6
%29 = load i32*, i32** %4
%30 = bitcast i32* %29 to i32**
%31 = getelementptr inbounds i32*, i32** %30, i64 1
store i32** %31, i32*** %5
%32 = load i32*, i32** %4
%33 = bitcast i32* %32 to i32**
%34 = getelementptr inbounds i32*, i32** %33, i64 1
%35 = load i32*, i32** %34
store i32* %35, i32** %4
br label %10
36: ; preds = %19
%37 = load i32*, i32** %4
%38 = load i32*, i32** %3
%39 = icmp eq i32* %37, %38
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = load i32*, i32** %3
store i32* %41, i32** %2
br label %51
42: ; preds = %36
%43 = load i32**, i32*** %5
store i32* null, i32** %43
%44 = load i32*, i32** %3
%45 = call i32* @sort_and_stuff(i32* %44)
store i32* %45, i32** %7
%46 = load i32*, i32** %4
%47 = call i32* @sort_and_stuff(i32* %46)
store i32* %47, i32** %8
%48 = load i32*, i32** %7
%49 = load i32*, i32** %8
%50 = call i32* @merge_and_stuff(i32* %48, i32* %49)
store i32* %50, i32** %2
br label %51
51: ; preds = %42, %40
%52 = load i32*, i32** %2
ret i32* %52
}

LLVM IR (-O2):
define i32* @sort_and_stuff(i32* %0) {
%2 = icmp eq i32* %0, null
br i1 %2, label %27, label %3
3: ; preds = %1
%4 = getelementptr inbounds i32, i32* %0, i64 2
%5 = bitcast i32* %4 to i32**
%6 = load i32*, i32** %5
%7 = icmp eq i32* %6, null
br i1 %7, label %27, label %13
8: ; preds = %13
%9 = getelementptr inbounds i32, i32* %18, i64 2
%10 = bitcast i32* %9 to i32**
%11 = load i32*, i32** %10
%12 = icmp eq i32* %11, null
br i1 %12, label %25, label %13
13: ; preds = %3, %8
%14 = phi i32* [ %11, %8 ], [ %6, %3 ]
%15 = phi i32* [ %21, %8 ], [ %0, %3 ]
%16 = getelementptr inbounds i32, i32* %14, i64 2
%17 = bitcast i32* %16 to i32**
%18 = load i32*, i32** %17
%19 = getelementptr inbounds i32, i32* %15, i64 2
%20 = bitcast i32* %19 to i32**
%21 = load i32*, i32** %20
%22 = icmp eq i32* %18, null
br i1 %22, label %23, label %8
23: ; preds = %13
%24 = bitcast i32* %19 to i32**
br label %27
25: ; preds = %8
%26 = bitcast i32* %19 to i32**
br label %27
27: ; preds = %25, %3, %23, %1
%28 = phi i32** [ undef, %1 ], [ %24, %23 ], [ undef, %3 ], [ %26, %25 ]
%29 = phi i32* [ null, %1 ], [ %21, %23 ], [ %0, %3 ], [ %21, %25 ]
%30 = icmp eq i32* %29, %0
br i1 %30, label %31, label %33
31: ; preds = %27, %33
%32 = phi i32* [ %36, %33 ], [ %0, %27 ]
ret i32* %32
33: ; preds = %27
store i32* null, i32** %28
%34 = tail call i32* @sort_and_stuff(i32* %0)
%35 = tail call i32* @sort_and_stuff(i32* %29)
%36 = tail call i32* @merge_and_stuff(i32* %34, i32* %35)
br label %31
}