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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1040 <__nondet@plt>
cmp    $0x0,%rax
je     11a9 <main+0x79>
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,0x8(%rax)
cmpq   $0x0,-0x10(%rbp)
je     119c <main+0x6c>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    114f <main+0x1f>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     128e <main+0x15e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x30(%rbp)
mov    %al,-0x31(%rbp)
je     1210 <main+0xe0>
mov    $0x0,%al
call   1040 <__nondet@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1220 <main+0xf0>
jmp    1238 <main+0x108>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    11ef <main+0xbf>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x30(%rbp)
je     125a <main+0x12a>
mov    -0x18(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
cmpq   $0x0,-0x28(%rbp)
je     1281 <main+0x151>
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
jmp    1289 <main+0x159>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11c1 <main+0x91>
jmp    1293 <main+0x163>
cmpq   $0x0,-0x20(%rbp)
je     12bf <main+0x18f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    1293 <main+0x163>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
xor    %eax,%eax
call   1040 <__nondet@plt>
test   %rax,%rax
je     1233 <main+0x103>
xor    %ebx,%ebx
jmp    115f <main+0x2f>
nopl   (%rax)
xor    %eax,%eax
call   1040 <__nondet@plt>
mov    %r12,%rbx
test   %rax,%rax
je     1182 <main+0x52>
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
mov    %rbx,(%rax)
movq   $0x0,0x8(%rax)
test   %rbx,%rbx
je     1150 <main+0x20>
mov    %r12,0x8(%rbx)
jmp    1150 <main+0x20>
xor    %r14d,%r14d
jmp    119c <main+0x6c>
nopw   0x0(%rax,%rax,1)
mov    %r12,0x0(%r13)
mov    %r15,%r12
test   %r15,%r15
je     120d <main+0xdd>
mov    (%r12),%r15
test   %r14,%r14
je     11e0 <main+0xb0>
xor    %eax,%eax
call   1040 <__nondet@plt>
mov    %r14,%rbx
test   %rax,%rax
je     11f0 <main+0xc0>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%r13
mov    (%rbx),%rbx
test   %rbx,%rbx
je     11e3 <main+0xb3>
xor    %eax,%eax
call   1040 <__nondet@plt>
test   %rax,%rax
jne    11c0 <main+0x90>
jmp    11f6 <main+0xc6>
nopl   0x0(%rax)
xor    %r13d,%r13d
movq   $0x0,(%r12)
jmp    11fe <main+0xce>
nopl   (%rax)
mov    %r14,%rbx
xor    %r13d,%r13d
mov    %rbx,(%r12)
mov    %r12,0x8(%rbx)
mov    %r13,0x8(%r12)
test   %r13,%r13
jne    1190 <main+0x60>
mov    %r12,%r14
jmp    1194 <main+0x64>
test   %r14,%r14
je     1233 <main+0x103>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14),%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%r14
test   %rbx,%rbx
jne    1220 <main+0xf0>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.T = type { %struct.T*, %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
br label %7
7: ; preds = %24, %0
%8 = call i64 (...) @__nondet()
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %26
10: ; preds = %7
%11 = call %struct.T.0* @malloc(i32 16)
%12 = bitcast %struct.T.0* %11 to %struct.T*
store %struct.T* %12, %struct.T** %3
%13 = load %struct.T*, %struct.T** %2
%14 = load %struct.T*, %struct.T** %3
%15 = getelementptr inbounds %struct.T, %struct.T* %14, i32 0, i32 0
store %struct.T* %13, %struct.T** %15
%16 = load %struct.T*, %struct.T** %3
%17 = getelementptr inbounds %struct.T, %struct.T* %16, i32 0, i32 1
store %struct.T* null, %struct.T** %17
%18 = load %struct.T*, %struct.T** %2
%19 = icmp ne %struct.T* %18, null
br i1 %19, label %20, label %24
20: ; preds = %10
%21 = load %struct.T*, %struct.T** %3
%22 = load %struct.T*, %struct.T** %2
%23 = getelementptr inbounds %struct.T, %struct.T* %22, i32 0, i32 1
store %struct.T* %21, %struct.T** %23
br label %24
24: ; preds = %20, %10
%25 = load %struct.T*, %struct.T** %3
store %struct.T* %25, %struct.T** %2
br label %7
26: ; preds = %7
store %struct.T* null, %struct.T** %4
store %struct.T* null, %struct.T** %5
store %struct.T* null, %struct.T** %6
br label %27
27: ; preds = %71, %26
%28 = load %struct.T*, %struct.T** %2
%29 = icmp ne %struct.T* %28, null
br i1 %29, label %30, label %72
30: ; preds = %27
%31 = load %struct.T*, %struct.T** %2
store %struct.T* %31, %struct.T** %3
%32 = load %struct.T*, %struct.T** %2
%33 = getelementptr inbounds %struct.T, %struct.T* %32, i32 0, i32 0
%34 = load %struct.T*, %struct.T** %33
store %struct.T* %34, %struct.T** %2
%35 = load %struct.T*, %struct.T** %4
store %struct.T* %35, %struct.T** %6
store %struct.T* null, %struct.T** %5
br label %36
36: ; preds = %44, %30
%37 = load %struct.T*, %struct.T** %6
%38 = icmp ne %struct.T* %37, null
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = call i64 (...) @__nondet()
%41 = icmp ne i64 %40, 0
br label %42
42: ; preds = %39, %36
%43 = phi i1 [ false, %36 ], [ %41, %39 ]
br i1 %43, label %44, label %49
44: ; preds = %42
%45 = load %struct.T*, %struct.T** %6
store %struct.T* %45, %struct.T** %5
%46 = load %struct.T*, %struct.T** %6
%47 = getelementptr inbounds %struct.T, %struct.T* %46, i32 0, i32 0
%48 = load %struct.T*, %struct.T** %47
store %struct.T* %48, %struct.T** %6
br label %36
49: ; preds = %42
%50 = load %struct.T*, %struct.T** %6
%51 = load %struct.T*, %struct.T** %3
%52 = getelementptr inbounds %struct.T, %struct.T* %51, i32 0, i32 0
store %struct.T* %50, %struct.T** %52
%53 = load %struct.T*, %struct.T** %6
%54 = icmp ne %struct.T* %53, null
br i1 %54, label %55, label %59
55: ; preds = %49
%56 = load %struct.T*, %struct.T** %3
%57 = load %struct.T*, %struct.T** %6
%58 = getelementptr inbounds %struct.T, %struct.T* %57, i32 0, i32 1
store %struct.T* %56, %struct.T** %58
br label %59
59: ; preds = %55, %49
%60 = load %struct.T*, %struct.T** %5
%61 = load %struct.T*, %struct.T** %3
%62 = getelementptr inbounds %struct.T, %struct.T* %61, i32 0, i32 1
store %struct.T* %60, %struct.T** %62
%63 = load %struct.T*, %struct.T** %5
%64 = icmp ne %struct.T* %63, null
br i1 %64, label %65, label %69
65: ; preds = %59
%66 = load %struct.T*, %struct.T** %3
%67 = load %struct.T*, %struct.T** %5
%68 = getelementptr inbounds %struct.T, %struct.T* %67, i32 0, i32 0
store %struct.T* %66, %struct.T** %68
br label %71
69: ; preds = %59
%70 = load %struct.T*, %struct.T** %3
store %struct.T* %70, %struct.T** %4
br label %71
71: ; preds = %69, %65
br label %27
72: ; preds = %27
br label %73
73: ; preds = %76, %72
%74 = load %struct.T*, %struct.T** %4
%75 = icmp ne %struct.T* %74, null
br i1 %75, label %76, label %84
76: ; preds = %73
%77 = load %struct.T*, %struct.T** %4
store %struct.T* %77, %struct.T** %3
%78 = load %struct.T*, %struct.T** %4
%79 = getelementptr inbounds %struct.T, %struct.T* %78, i32 0, i32 0
%80 = load %struct.T*, %struct.T** %79
store %struct.T* %80, %struct.T** %4
%81 = load %struct.T*, %struct.T** %3
%82 = bitcast %struct.T* %81 to %struct.T.1*
%83 = call i32 @free(%struct.T.1* %82)
br label %73
84: ; preds = %73
ret i32 0
}

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