#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 */
int /*<<< orphan*/ free(struct T *);
struct T *malloc(int);
int main() {
  struct T {
    struct T *next;
  };
  struct T *x = NULL;
  struct T *y = NULL;
  y = malloc(sizeof(*y));
  y->next = x;
  x = y;
  y = malloc(sizeof(*y));
  y->next = x;
  x = y;
  struct T *sorted = NULL;
  struct T *pred = NULL;
  struct T *z = NULL;
  while (x) {
    y = x;
    x = x->next;
    pred = NULL;
    z = sorted;
    while (z) {
      pred = z;
      z = z->next;
    }
    y->next = z;
    if (pred)
      pred->next = y;
    else
      sorted = y;
  }
  while (sorted != NULL) {
    x = sorted;
    sorted = sorted->next;
    free(x);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     121d <main+0xfd>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11ea <main+0xca>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    11c7 <main+0xa7>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x28(%rbp)
je     1210 <main+0xf0>
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
jmp    1218 <main+0xf8>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1199 <main+0x79>
jmp    1222 <main+0x102>
cmpq   $0x0,-0x20(%rbp)
je     124e <main+0x12e>
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    1222 <main+0x102>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
movq   $0x0,(%rax)
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rbx,(%rax)
xor    %edi,%edi
jmp    1162 <main+0x42>
cs nopw 0x0(%rax,%rax,1)
movq   $0x0,(%rax)
mov    %rax,%rdi
mov    %rcx,%rax
test   %rcx,%rcx
je     1187 <main+0x67>
mov    (%rax),%rcx
mov    %rdi,%rdx
test   %rdi,%rdi
je     1150 <main+0x30>
nopl   (%rax)
mov    %rdx,%rsi
mov    (%rdx),%rdx
test   %rdx,%rdx
jne    1170 <main+0x50>
movq   $0x0,(%rax)
mov    %rax,(%rsi)
jmp    115a <main+0x3a>
test   %rdi,%rdi
je     11a0 <main+0x80>
nopl   0x0(%rax)
mov    (%rdi),%rbx
call   1030 <free@plt>
mov    %rbx,%rdi
test   %rbx,%rbx
jne    1190 <main+0x70>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.T = type { %struct.T* }
%struct.T.0 = type opaque
%struct.T.1 = type opaque
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.T*
%3 = alloca %struct.T*
%4 = alloca %struct.T*
%5 = alloca %struct.T*
%6 = alloca %struct.T*
store i32 0, i32* %1
store %struct.T* null, %struct.T** %2
store %struct.T* null, %struct.T** %3
%7 = call %struct.T.0* @malloc(i32 8)
%8 = bitcast %struct.T.0* %7 to %struct.T*
store %struct.T* %8, %struct.T** %3
%9 = load %struct.T*, %struct.T** %2
%10 = load %struct.T*, %struct.T** %3
%11 = getelementptr inbounds %struct.T, %struct.T* %10, i32 0, i32 0
store %struct.T* %9, %struct.T** %11
%12 = load %struct.T*, %struct.T** %3
store %struct.T* %12, %struct.T** %2
%13 = call %struct.T.0* @malloc(i32 8)
%14 = bitcast %struct.T.0* %13 to %struct.T*
store %struct.T* %14, %struct.T** %3
%15 = load %struct.T*, %struct.T** %2
%16 = load %struct.T*, %struct.T** %3
%17 = getelementptr inbounds %struct.T, %struct.T* %16, i32 0, i32 0
store %struct.T* %15, %struct.T** %17
%18 = load %struct.T*, %struct.T** %3
store %struct.T* %18, %struct.T** %2
store %struct.T* null, %struct.T** %4
store %struct.T* null, %struct.T** %5
store %struct.T* null, %struct.T** %6
br label %19
19: ; preds = %48, %0
%20 = load %struct.T*, %struct.T** %2
%21 = icmp ne %struct.T* %20, null
br i1 %21, label %22, label %49
22: ; preds = %19
%23 = load %struct.T*, %struct.T** %2
store %struct.T* %23, %struct.T** %3
%24 = load %struct.T*, %struct.T** %2
%25 = getelementptr inbounds %struct.T, %struct.T* %24, i32 0, i32 0
%26 = load %struct.T*, %struct.T** %25
store %struct.T* %26, %struct.T** %2
store %struct.T* null, %struct.T** %5
%27 = load %struct.T*, %struct.T** %4
store %struct.T* %27, %struct.T** %6
br label %28
28: ; preds = %31, %22
%29 = load %struct.T*, %struct.T** %6
%30 = icmp ne %struct.T* %29, null
br i1 %30, label %31, label %36
31: ; preds = %28
%32 = load %struct.T*, %struct.T** %6
store %struct.T* %32, %struct.T** %5
%33 = load %struct.T*, %struct.T** %6
%34 = getelementptr inbounds %struct.T, %struct.T* %33, i32 0, i32 0
%35 = load %struct.T*, %struct.T** %34
store %struct.T* %35, %struct.T** %6
br label %28
36: ; preds = %28
%37 = load %struct.T*, %struct.T** %6
%38 = load %struct.T*, %struct.T** %3
%39 = getelementptr inbounds %struct.T, %struct.T* %38, i32 0, i32 0
store %struct.T* %37, %struct.T** %39
%40 = load %struct.T*, %struct.T** %5
%41 = icmp ne %struct.T* %40, null
br i1 %41, label %42, label %46
42: ; preds = %36
%43 = load %struct.T*, %struct.T** %3
%44 = load %struct.T*, %struct.T** %5
%45 = getelementptr inbounds %struct.T, %struct.T* %44, i32 0, i32 0
store %struct.T* %43, %struct.T** %45
br label %48
46: ; preds = %36
%47 = load %struct.T*, %struct.T** %3
store %struct.T* %47, %struct.T** %4
br label %48
48: ; preds = %46, %42
br label %19
49: ; preds = %19
br label %50
50: ; preds = %53, %49
%51 = load %struct.T*, %struct.T** %4
%52 = icmp ne %struct.T* %51, null
br i1 %52, label %53, label %61
53: ; preds = %50
%54 = load %struct.T*, %struct.T** %4
store %struct.T* %54, %struct.T** %2
%55 = load %struct.T*, %struct.T** %4
%56 = getelementptr inbounds %struct.T, %struct.T* %55, i32 0, i32 0
%57 = load %struct.T*, %struct.T** %56
store %struct.T* %57, %struct.T** %4
%58 = load %struct.T*, %struct.T** %2
%59 = bitcast %struct.T* %58 to %struct.T.1*
%60 = call i32 @free(%struct.T.1* %59)
br label %50
61: ; preds = %50
ret i32 0
}

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