#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;
  y = x;
  while (y != NULL)
    y = y->next;
  y = x;
  x = y;
  y = y->next;
  free(x);
  if (y) {
    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    $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)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a4 <main+0x84>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1189 <main+0x69>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
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>
cmpq   $0x0,-0x18(%rbp)
je     11ef <main+0xcf>
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>
xor    %eax,%eax
add    $0x20,%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)
mov    %rax,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
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*
store i32 0, i32* %1
store %struct.T* null, %struct.T** %2
store %struct.T* null, %struct.T** %3
%4 = call %struct.T.0* @malloc(i32 8)
%5 = bitcast %struct.T.0* %4 to %struct.T*
store %struct.T* %5, %struct.T** %3
%6 = load %struct.T*, %struct.T** %2
%7 = load %struct.T*, %struct.T** %3
%8 = getelementptr inbounds %struct.T, %struct.T* %7, i32 0, i32 0
store %struct.T* %6, %struct.T** %8
%9 = load %struct.T*, %struct.T** %3
store %struct.T* %9, %struct.T** %2
%10 = call %struct.T.0* @malloc(i32 8)
%11 = bitcast %struct.T.0* %10 to %struct.T*
store %struct.T* %11, %struct.T** %3
%12 = load %struct.T*, %struct.T** %2
%13 = load %struct.T*, %struct.T** %3
%14 = getelementptr inbounds %struct.T, %struct.T* %13, i32 0, i32 0
store %struct.T* %12, %struct.T** %14
%15 = load %struct.T*, %struct.T** %3
store %struct.T* %15, %struct.T** %2
%16 = load %struct.T*, %struct.T** %2
store %struct.T* %16, %struct.T** %3
br label %17
17: ; preds = %20, %0
%18 = load %struct.T*, %struct.T** %3
%19 = icmp ne %struct.T* %18, null
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load %struct.T*, %struct.T** %3
%22 = getelementptr inbounds %struct.T, %struct.T* %21, i32 0, i32 0
%23 = load %struct.T*, %struct.T** %22
store %struct.T* %23, %struct.T** %3
br label %17
24: ; preds = %17
%25 = load %struct.T*, %struct.T** %2
store %struct.T* %25, %struct.T** %3
%26 = load %struct.T*, %struct.T** %3
store %struct.T* %26, %struct.T** %2
%27 = load %struct.T*, %struct.T** %3
%28 = getelementptr inbounds %struct.T, %struct.T* %27, i32 0, i32 0
%29 = load %struct.T*, %struct.T** %28
store %struct.T* %29, %struct.T** %3
%30 = load %struct.T*, %struct.T** %2
%31 = bitcast %struct.T* %30 to %struct.T.1*
%32 = call i32 @free(%struct.T.1* %31)
%33 = load %struct.T*, %struct.T** %3
%34 = icmp ne %struct.T* %33, null
br i1 %34, label %35, label %43
35: ; preds = %24
%36 = load %struct.T*, %struct.T** %3
store %struct.T* %36, %struct.T** %2
%37 = load %struct.T*, %struct.T** %3
%38 = getelementptr inbounds %struct.T, %struct.T* %37, i32 0, i32 0
%39 = load %struct.T*, %struct.T** %38
store %struct.T* %39, %struct.T** %3
%40 = load %struct.T*, %struct.T** %2
%41 = bitcast %struct.T* %40 to %struct.T.1*
%42 = call i32 @free(%struct.T.1* %41)
br label %43
43: ; preds = %35, %24
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.1*
%6 = tail call i32 @free(%struct.T.1* %5)
%7 = bitcast %struct.T.0* %1 to %struct.T.1*
%8 = tail call i32 @free(%struct.T.1* %7)
ret i32 0
}