#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 *get_kth(struct list *, int, int);
struct list *list_constructor_va(int, int, int, int, int, int);
int list_length(struct list *);
int /*<<< orphan*/ list_print(struct list *);
int /*<<< orphan*/ swap(struct list **, struct list **);
int main(int argc, const char *argv[]) {
  struct list *head = NULL;
  struct list *p1 = NULL;
  struct list *p2 = NULL;
  int len;
  head = list_constructor_va(5, 5, 4, 3, 2, 1);
  list_print(head);
  len = list_length(head);
  p1 = get_kth(head, 4, len);
  p2 = get_kth(head, 2, len);
  swap(&p1, &p2);
  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)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    $0x5,%esi
mov    $0x4,%edx
mov    $0x3,%ecx
mov    $0x2,%r8d
mov    $0x1,%r9d
mov    %esi,%edi
call   1050 <list_constructor_va@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <list_print@plt>
mov    -0x18(%rbp),%rdi
call   1060 <list_length@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    $0x4,%esi
call   1040 <get_kth@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    $0x2,%esi
call   1040 <get_kth@plt>
mov    %rax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <swap@plt>
mov    -0x18(%rbp),%rdi
call   1030 <list_print@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    $0x5,%edi
mov    $0x5,%esi
mov    $0x4,%edx
mov    $0x3,%ecx
mov    $0x2,%r8d
mov    $0x1,%r9d
call   1050 <list_constructor_va@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <list_print@plt>
mov    %rbx,%rdi
call   1060 <list_length@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %eax,%edx
call   1040 <get_kth@plt>
mov    %rax,0x10(%rsp)
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %ebp,%edx
call   1040 <get_kth@plt>
mov    %rax,0x8(%rsp)
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1070 <swap@plt>
mov    %rbx,%rdi
call   1030 <list_print@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.list = type { i32 }
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*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store %struct.list* null, %struct.list** %6
store %struct.list* null, %struct.list** %7
store %struct.list* null, %struct.list** %8
%10 = call %struct.list* @list_constructor_va(i32 5, i32 5, i32 4, i32 3, i32 2, i32 1)
store %struct.list* %10, %struct.list** %6
%11 = load %struct.list*, %struct.list** %6
%12 = call i32 @list_print(%struct.list* %11)
%13 = load %struct.list*, %struct.list** %6
%14 = call i32 @list_length(%struct.list* %13)
store i32 %14, i32* %9
%15 = load %struct.list*, %struct.list** %6
%16 = load i32, i32* %9
%17 = call %struct.list* @get_kth(%struct.list* %15, i32 4, i32 %16)
store %struct.list* %17, %struct.list** %7
%18 = load %struct.list*, %struct.list** %6
%19 = load i32, i32* %9
%20 = call %struct.list* @get_kth(%struct.list* %18, i32 2, i32 %19)
store %struct.list* %20, %struct.list** %8
%21 = call i32 @swap(%struct.list** %7, %struct.list** %8)
%22 = load %struct.list*, %struct.list** %6
%23 = call i32 @list_print(%struct.list* %22)
ret i32 0
}

LLVM IR (-O2):
%struct.list = type { i32 }
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.list*
%4 = alloca %struct.list*
%5 = bitcast %struct.list** %3 to i8*
%6 = bitcast %struct.list** %4 to i8*
%7 = tail call %struct.list* @list_constructor_va(i32 5, i32 5, i32 4, i32 3, i32 2, i32 1)
%8 = tail call i32 @list_print(%struct.list* %7)
%9 = tail call i32 @list_length(%struct.list* %7)
%10 = tail call %struct.list* @get_kth(%struct.list* %7, i32 4, i32 %9)
store %struct.list* %10, %struct.list** %3
%11 = tail call %struct.list* @get_kth(%struct.list* %7, i32 2, i32 %9)
store %struct.list* %11, %struct.list** %4
%12 = call i32 @swap(%struct.list** %3, %struct.list** %4)
%13 = call i32 @list_print(%struct.list* %7)
ret i32 0
}