#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 */
struct list {
  int dummy;
};

/* Variables and functions */
struct list *list_constructor_tail(int);
int /*<<< orphan*/ list_print(struct list *);
struct list *list_reverse(struct list *);
int /*<<< orphan*/ list_reverse_inplace(struct list **);
int /*<<< orphan*/ printf(char *);
int main(int argc, const char *argv[]) {
  struct list *head, *rev, *rev2;
  head = list_constructor_tail(10);
  printf("Original list\n");
  list_print(head);
  printf("-----------------------------\n");
  rev = list_reverse(head);
  printf("Reverted list\n");
  list_print(rev);
  list_print(head);
  printf("-----------------------------\n");
  list_reverse_inplace(&head);
  printf("Inplace Reverted list\n");
  list_print(head);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0xa,%edi
call   1070 <list_constructor_tail@plt>
mov    %rax,-0x18(%rbp)
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <list_print@plt>
lea    0xe7f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <list_reverse@plt>
mov    %rax,-0x20(%rbp)
lea    0xe8d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <list_print@plt>
mov    -0x18(%rbp),%rdi
call   1040 <list_print@plt>
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
lea    -0x18(%rbp),%rdi
call   1060 <list_reverse_inplace@plt>
lea    0xe52(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <list_print@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0xa,%edi
call   1070 <list_constructor_tail@plt>
mov    %rax,%rbx
mov    %rax,0x8(%rsp)
lea    0xe8e(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <list_print@plt>
lea    0xe88(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <list_reverse@plt>
mov    %rax,%r15
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1040 <list_print@plt>
mov    %rbx,%rdi
call   1040 <list_print@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rdi
call   1060 <list_reverse_inplace@plt>
lea    0xe5e(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rdi
call   1040 <list_print@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.list = type { i32 }
@.str = [15 x i8] c"Original list\0A\00"
@.str.1 = [31 x i8] c"-----------------------------\0A\00"
@.str.2 = [15 x i8] c"Reverted list\0A\00"
@.str.3 = [23 x i8] c"Inplace Reverted list\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.list*
%7 = alloca %struct.list*
%8 = alloca %struct.list*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call %struct.list* @list_constructor_tail(i32 10)
store %struct.list* %9, %struct.list** %6
%10 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%11 = load %struct.list*, %struct.list** %6
%12 = call i32 @list_print(%struct.list* %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%14 = load %struct.list*, %struct.list** %6
%15 = call %struct.list* @list_reverse(%struct.list* %14)
store %struct.list* %15, %struct.list** %7
%16 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%17 = load %struct.list*, %struct.list** %7
%18 = call i32 @list_print(%struct.list* %17)
%19 = load %struct.list*, %struct.list** %6
%20 = call i32 @list_print(%struct.list* %19)
%21 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @list_reverse_inplace(%struct.list** %6)
%23 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%24 = load %struct.list*, %struct.list** %6
%25 = call i32 @list_print(%struct.list* %24)
ret i32 0
}

LLVM IR (-O2):
%struct.list = type { i32 }
@str = [14 x i8] c"Original list\00"
@str.5 = [14 x i8] c"Reverted list\00"
@str.6 = [30 x i8] c"-----------------------------\00"
@str.7 = [22 x i8] c"Inplace Reverted list\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.list*
%4 = bitcast %struct.list** %3 to i8*
%5 = tail call %struct.list* @list_constructor_tail(i32 10)
store %struct.list* %5, %struct.list** %3
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @list_print(%struct.list* %5)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.6, i64 0, i64 0))
%9 = tail call %struct.list* @list_reverse(%struct.list* %5)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0))
%11 = tail call i32 @list_print(%struct.list* %9)
%12 = tail call i32 @list_print(%struct.list* %5)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.6, i64 0, i64 0))
%14 = call i32 @list_reverse_inplace(%struct.list** %3)
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.7, i64 0, i64 0))
%16 = load %struct.list*, %struct.list** %3
%17 = call i32 @list_print(%struct.list* %16)
ret i32 0
}