#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 *x = NULL;
  struct T *y = NULL;
  while (__nondet()) {
    y = malloc(sizeof(*y));
    y->next = x;
    x = y;
    y = malloc(sizeof(*y));
    y->next = x;
    x = y;
  }
  while (y != NULL) {
    x = y;
    y = y->next;
    free(x);
    x = y;
    y = y->next;
    free(x);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1040 <__nondet@plt>
cmp    $0x0,%rax
je     11a7 <main+0x77>
mov    $0x8,%edi
call   1050 <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   1050 <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)
jmp    114f <main+0x1f>
jmp    11ac <main+0x7c>
cmpq   $0x0,-0x18(%rbp)
je     11f4 <main+0xc4>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    11ac <main+0x7c>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <__nondet@plt>
test   %rax,%rax
je     119b <main+0x6b>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rbx,(%rax)
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %r14,(%rax)
xor    %eax,%eax
call   1040 <__nondet@plt>
test   %rax,%rax
jne    1150 <main+0x20>
nopl   0x0(%rax)
mov    (%rbx),%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    (%r14),%rbx
mov    %r14,%rdi
call   1030 <free@plt>
test   %rbx,%rbx
jne    1180 <main+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
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*
store i32 0, i32* %1
store %struct.T* null, %struct.T** %2
store %struct.T* null, %struct.T** %3
br label %4
4: ; preds = %7, %0
%5 = call i64 (...) @__nondet()
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %20
7: ; preds = %4
%8 = call %struct.T.0* @malloc(i32 8)
%9 = bitcast %struct.T.0* %8 to %struct.T*
store %struct.T* %9, %struct.T** %3
%10 = load %struct.T*, %struct.T** %2
%11 = load %struct.T*, %struct.T** %3
%12 = getelementptr inbounds %struct.T, %struct.T* %11, i32 0, i32 0
store %struct.T* %10, %struct.T** %12
%13 = load %struct.T*, %struct.T** %3
store %struct.T* %13, %struct.T** %2
%14 = call %struct.T.0* @malloc(i32 8)
%15 = bitcast %struct.T.0* %14 to %struct.T*
store %struct.T* %15, %struct.T** %3
%16 = load %struct.T*, %struct.T** %2
%17 = load %struct.T*, %struct.T** %3
%18 = getelementptr inbounds %struct.T, %struct.T* %17, i32 0, i32 0
store %struct.T* %16, %struct.T** %18
%19 = load %struct.T*, %struct.T** %3
store %struct.T* %19, %struct.T** %2
br label %4
20: ; preds = %4
br label %21
21: ; preds = %24, %20
%22 = load %struct.T*, %struct.T** %3
%23 = icmp ne %struct.T* %22, null
br i1 %23, label %24, label %39
24: ; preds = %21
%25 = load %struct.T*, %struct.T** %3
store %struct.T* %25, %struct.T** %2
%26 = load %struct.T*, %struct.T** %3
%27 = getelementptr inbounds %struct.T, %struct.T* %26, i32 0, i32 0
%28 = load %struct.T*, %struct.T** %27
store %struct.T* %28, %struct.T** %3
%29 = load %struct.T*, %struct.T** %2
%30 = bitcast %struct.T* %29 to %struct.T.1*
%31 = call i32 @free(%struct.T.1* %30)
%32 = load %struct.T*, %struct.T** %3
store %struct.T* %32, %struct.T** %2
%33 = load %struct.T*, %struct.T** %3
%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** %3
%36 = load %struct.T*, %struct.T** %2
%37 = bitcast %struct.T* %36 to %struct.T.1*
%38 = call i32 @free(%struct.T.1* %37)
br label %21
39: ; preds = %21
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 i64 (...) @__nondet()
%2 = icmp eq i64 %1, 0
br i1 %2, label %25, label %5
3: ; preds = %5
%4 = bitcast %struct.T.0* %9 to %struct.T*
br label %14
5: ; preds = %0, %5
%6 = phi %struct.T* [ %10, %5 ], [ null, %0 ]
%7 = tail call %struct.T.0* @malloc(i32 8)
%8 = bitcast %struct.T.0* %7 to %struct.T**
store %struct.T* %6, %struct.T** %8
%9 = tail call %struct.T.0* @malloc(i32 8)
%10 = bitcast %struct.T.0* %9 to %struct.T*
%11 = bitcast %struct.T.0* %9 to %struct.T.0**
store %struct.T.0* %7, %struct.T.0** %11
%12 = tail call i64 (...) @__nondet()
%13 = icmp eq i64 %12, 0
br i1 %13, label %3, label %5
14: ; preds = %3, %14
%15 = phi %struct.T* [ %21, %14 ], [ %4, %3 ]
%16 = getelementptr inbounds %struct.T, %struct.T* %15, i64 0, i32 0
%17 = load %struct.T*, %struct.T** %16
%18 = bitcast %struct.T* %15 to %struct.T.1*
%19 = tail call i32 @free(%struct.T.1* %18)
%20 = getelementptr inbounds %struct.T, %struct.T* %17, i64 0, i32 0
%21 = load %struct.T*, %struct.T** %20
%22 = bitcast %struct.T* %17 to %struct.T.1*
%23 = tail call i32 @free(%struct.T.1* %22)
%24 = icmp eq %struct.T* %21, null
br i1 %24, label %25, label %14
25: ; preds = %14, %0
ret i32 0
}