#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 */
struct T *malloc(int);
int main() {
  struct T {
    struct T *next;
  };
  struct T *x = NULL;
  struct T *y = NULL;
  int i;
  for (i = 1; i; ++i) {
    y = malloc(sizeof(*y));
    y->next = x;
    x = y;
  }
  struct T *z = NULL;
  while (x != NULL) {
    y = x;
    x = x->next;
    y->next = z;
    z = y;
  }
  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)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     116f <main+0x5f>
mov    $0x8,%edi
call   1030 <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    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1136 <main+0x26>
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11ad <main+0x9d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1177 <main+0x67>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x8,%edi
call   1030 <malloc@plt>
mov    %rbx,(%rax)
mov    %rax,%rbx
jmp    1120 <main+0x10>

LLVM IR (-O0):
%struct.T = type { %struct.T* }
%struct.T.0 = type opaque
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.T*
%3 = alloca %struct.T*
%4 = alloca i32
%5 = alloca %struct.T*
store i32 0, i32* %1
store %struct.T* null, %struct.T** %2
store %struct.T* null, %struct.T** %3
store i32 1, i32* %4
br label %6
6: ; preds = %16, %0
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %6
%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
br label %16
16: ; preds = %9
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %6
19: ; preds = %6
store %struct.T* null, %struct.T** %5
br label %20
20: ; preds = %23, %19
%21 = load %struct.T*, %struct.T** %2
%22 = icmp ne %struct.T* %21, null
br i1 %22, label %23, label %32
23: ; preds = %20
%24 = load %struct.T*, %struct.T** %2
store %struct.T* %24, %struct.T** %3
%25 = load %struct.T*, %struct.T** %2
%26 = getelementptr inbounds %struct.T, %struct.T* %25, i32 0, i32 0
%27 = load %struct.T*, %struct.T** %26
store %struct.T* %27, %struct.T** %2
%28 = load %struct.T*, %struct.T** %5
%29 = load %struct.T*, %struct.T** %3
%30 = getelementptr inbounds %struct.T, %struct.T* %29, i32 0, i32 0
store %struct.T* %28, %struct.T** %30
%31 = load %struct.T*, %struct.T** %3
store %struct.T* %31, %struct.T** %5
br label %20
32: ; preds = %20
ret i32 0
}

LLVM IR (-O2):
%struct.T = type { %struct.T* }
%struct.T.0 = type opaque
define i32 @main() {
br label %1
1: ; preds = %1, %0
%2 = phi %struct.T* [ null, %0 ], [ %4, %1 ]
%3 = tail call %struct.T.0* @malloc(i32 8)
%4 = bitcast %struct.T.0* %3 to %struct.T*
%5 = bitcast %struct.T.0* %3 to %struct.T**
store %struct.T* %2, %struct.T** %5
br label %1
}