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

/* Variables and functions */
int /*<<< orphan*/ list_append(struct list *, struct list_it *);
struct list *list_create();
struct list_it *list_it(struct list *);
struct list_it *list_it_next(struct list_it *);
struct list *list_slice(struct list *list, struct list_it *first,
                        struct list_it *last) {
  struct list *new = list_create();
  struct list_it *it = first;
  if (it == NULL) {
    it = list_it(list);
  }
  if (last != NULL) {
    last = list_it_next(last);
  }
  while (it != last) {
    list_append(new, it);
    it = list_it_next(it);
  }
  return new;
}


x86 assembly (clang, -O0):
<list_slice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1030 <list_create@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    117f <list_slice+0x3f>
mov    -0x8(%rbp),%rdi
call   1050 <list_it@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1197 <list_slice+0x57>
mov    -0x18(%rbp),%rdi
call   1040 <list_it_next@plt>
mov    %rax,-0x18(%rbp)
jmp    119c <list_slice+0x5c>
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     11c9 <list_slice+0x89>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <list_append@plt>
mov    -0x28(%rbp),%rdi
call   1040 <list_it_next@plt>
mov    %rax,-0x28(%rbp)
jmp    119c <list_slice+0x5c>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_slice>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r12
xor    %eax,%eax
call   1030 <list_create@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     11aa <list_slice+0x6a>
test   %r15,%r15
je     11ba <list_slice+0x7a>
mov    %r15,%rdi
call   1040 <list_it_next@plt>
mov    %rax,%r15
cmp    %r15,%rbx
je     119b <list_slice+0x5b>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <list_append@plt>
mov    %rbx,%rdi
call   1040 <list_it_next@plt>
mov    %rax,%rbx
cmp    %r15,%rax
jne    1180 <list_slice+0x40>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r12,%rdi
call   1050 <list_it@plt>
mov    %rax,%rbx
test   %r15,%r15
jne    1165 <list_slice+0x25>
xor    %r15d,%r15d
cmp    %r15,%rbx
jne    1180 <list_slice+0x40>
jmp    119b <list_slice+0x5b>

LLVM IR (-O0):
%struct.list = type { i32 }
%struct.list_it = type { i32 }
define %struct.list* @list_slice(%struct.list* %0, %struct.list_it* %1, %struct.list_it* %2) {
%4 = alloca %struct.list*
%5 = alloca %struct.list_it*
%6 = alloca %struct.list_it*
%7 = alloca %struct.list*
%8 = alloca %struct.list_it*
store %struct.list* %0, %struct.list** %4
store %struct.list_it* %1, %struct.list_it** %5
store %struct.list_it* %2, %struct.list_it** %6
%9 = call %struct.list* (...) @list_create()
store %struct.list* %9, %struct.list** %7
%10 = load %struct.list_it*, %struct.list_it** %5
store %struct.list_it* %10, %struct.list_it** %8
%11 = load %struct.list_it*, %struct.list_it** %8
%12 = icmp eq %struct.list_it* %11, null
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = load %struct.list*, %struct.list** %4
%15 = call %struct.list_it* @list_it(%struct.list* %14)
store %struct.list_it* %15, %struct.list_it** %8
br label %16
16: ; preds = %13, %3
%17 = load %struct.list_it*, %struct.list_it** %6
%18 = icmp ne %struct.list_it* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load %struct.list_it*, %struct.list_it** %6
%21 = call %struct.list_it* @list_it_next(%struct.list_it* %20)
store %struct.list_it* %21, %struct.list_it** %6
br label %22
22: ; preds = %19, %16
br label %23
23: ; preds = %27, %22
%24 = load %struct.list_it*, %struct.list_it** %8
%25 = load %struct.list_it*, %struct.list_it** %6
%26 = icmp ne %struct.list_it* %24, %25
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load %struct.list*, %struct.list** %7
%29 = load %struct.list_it*, %struct.list_it** %8
%30 = call i32 @list_append(%struct.list* %28, %struct.list_it* %29)
%31 = load %struct.list_it*, %struct.list_it** %8
%32 = call %struct.list_it* @list_it_next(%struct.list_it* %31)
store %struct.list_it* %32, %struct.list_it** %8
br label %23
33: ; preds = %23
%34 = load %struct.list*, %struct.list** %7
ret %struct.list* %34
}

LLVM IR (-O2):
%struct.list = type { i32 }
%struct.list_it = type { i32 }
define %struct.list* @list_slice(%struct.list* %0, %struct.list_it* %1, %struct.list_it* %2) {
%4 = tail call %struct.list* (...) @list_create()
%5 = icmp eq %struct.list_it* %1, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call %struct.list_it* @list_it(%struct.list* %0)
br label %8
8: ; preds = %6, %3
%9 = phi %struct.list_it* [ %7, %6 ], [ %1, %3 ]
%10 = icmp eq %struct.list_it* %2, null
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call %struct.list_it* @list_it_next(%struct.list_it* %2)
br label %13
13: ; preds = %11, %8
%14 = phi %struct.list_it* [ %12, %11 ], [ null, %8 ]
%15 = icmp eq %struct.list_it* %9, %14
br i1 %15, label %21, label %16
16: ; preds = %13, %16
%17 = phi %struct.list_it* [ %19, %16 ], [ %9, %13 ]
%18 = tail call i32 @list_append(%struct.list* %4, %struct.list_it* %17)
%19 = tail call %struct.list_it* @list_it_next(%struct.list_it* %17)
%20 = icmp eq %struct.list_it* %19, %14
br i1 %20, label %21, label %16
21: ; preds = %16, %13
ret %struct.list* %4
}