#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*/ assert(int /*<<< orphan*/);
void *round_robin_selection(int num_items, void *items, int item_size,
                            void **current) {
  void *last_on_list;
  assert(current != NULL);
  last_on_list = items + (num_items - 1) * item_size;
  if (!(*current) || (*current == last_on_list))
    *current = items;
  else
    *current += item_size;
  return *current;
}


x86 assembly (clang, -O0):
<round_robin_selection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
imul   -0x14(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     116f <round_robin_selection+0x5f>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
cmp    -0x28(%rbp),%rax
jne    117f <round_robin_selection+0x6f>
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
jmp    1192 <round_robin_selection+0x82>
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
movslq %edx,%rdx
add    %rdx,%rcx
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<round_robin_selection>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %edi,%edi
test   %rcx,%rcx
setne  %dil
call   1030 <assert@plt>
mov    (%r14),%rax
test   %rax,%rax
je     1153 <round_robin_selection+0x43>
add    $0xffffffff,%ebp
imul   %r15d,%ebp
movslq %ebp,%rcx
add    %rbx,%rcx
cmp    %rcx,%rax
je     1153 <round_robin_selection+0x43>
movslq %r15d,%rcx
add    %rcx,%rax
mov    %rax,%rbx
mov    %rbx,(%r14)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @round_robin_selection(i32 %0, i8* %1, i32 %2, i8** %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8** %3, i8*** %8
%10 = load i8**, i8*** %8
%11 = icmp ne i8** %10, null
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i8*, i8** %6
%15 = load i32, i32* %5
%16 = sub nsw i32 %15, 1
%17 = load i32, i32* %7
%18 = mul nsw i32 %16, %17
%19 = sext i32 %18 to i64
%20 = getelementptr i8, i8* %14, i64 %19
store i8* %20, i8** %9
%21 = load i8**, i8*** %8
%22 = load i8*, i8** %21
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %29
24: ; preds = %4
%25 = load i8**, i8*** %8
%26 = load i8*, i8** %25
%27 = load i8*, i8** %9
%28 = icmp eq i8* %26, %27
br i1 %28, label %29, label %32
29: ; preds = %24, %4
%30 = load i8*, i8** %6
%31 = load i8**, i8*** %8
store i8* %30, i8** %31
br label %38
32: ; preds = %24
%33 = load i32, i32* %7
%34 = load i8**, i8*** %8
%35 = load i8*, i8** %34
%36 = sext i32 %33 to i64
%37 = getelementptr i8, i8* %35, i64 %36
store i8* %37, i8** %34
br label %38
38: ; preds = %32, %29
%39 = load i8**, i8*** %8
%40 = load i8*, i8** %39
ret i8* %40
}

LLVM IR (-O2):
define i8* @round_robin_selection(i32 %0, i8* %1, i32 %2, i8** %3) {
%5 = icmp ne i8** %3, null
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %19, label %10
10: ; preds = %4
%11 = add nsw i32 %0, -1
%12 = mul nsw i32 %11, %2
%13 = sext i32 %12 to i64
%14 = getelementptr i8, i8* %1, i64 %13
%15 = icmp eq i8* %8, %14
br i1 %15, label %19, label %16
16: ; preds = %10
%17 = sext i32 %2 to i64
%18 = getelementptr i8, i8* %8, i64 %17
br label %19
19: ; preds = %4, %10, %16
%20 = phi i8* [ %18, %16 ], [ %1, %10 ], [ %1, %4 ]
store i8* %20, i8** %3
ret i8* %20
}