#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 */
void *list_get(struct list const *, int);
int list_size(struct list const *);
void list_each_r(const struct list *l, void (*fun)(void *, void *),
                 void *args) {
  int si = list_size(l);
  for (int i = 1; i <= si; ++i) {
    fun(list_get(l, i), args);
  }
}


x86 assembly (clang, -O0):
<list_each_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <list_size@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     1182 <list_each_r+0x62>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1030 <list_get@plt>
mov    %rax,%rdi
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rsi
call   *%rax
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1147 <list_each_r+0x27>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_each_r>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1040 <list_size@plt>
test   %eax,%eax
jle    1176 <list_each_r+0x56>
mov    %eax,%r13d
neg    %r13d
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %ebx,%esi
call   1030 <list_get@plt>
mov    %rax,%rdi
mov    %r14,%rsi
call   *%r15
lea    (%rbx,%r13,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
jne    1150 <list_each_r+0x30>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.list = type { i32 }
define void @list_each_r(%struct.list* %0, void (i8*, i8*)* %1, i8* %2) {
%4 = alloca %struct.list*
%5 = alloca void (i8*, i8*)*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store %struct.list* %0, %struct.list** %4
store void (i8*, i8*)* %1, void (i8*, i8*)** %5
store i8* %2, i8** %6
%9 = load %struct.list*, %struct.list** %4
%10 = call i32 @list_size(%struct.list* %9)
store i32 %10, i32* %7
store i32 1, i32* %8
br label %11
11: ; preds = %21, %3
%12 = load i32, i32* %8
%13 = load i32, i32* %7
%14 = icmp sle i32 %12, %13
br i1 %14, label %15, label %24
15: ; preds = %11
%16 = load void (i8*, i8*)*, void (i8*, i8*)** %5
%17 = load %struct.list*, %struct.list** %4
%18 = load i32, i32* %8
%19 = call i8* @list_get(%struct.list* %17, i32 %18)
%20 = load i8*, i8** %6
br label %21
21: ; preds = %15
%22 = load i32, i32* %8
%23 = add nsw i32 %22, 1
store i32 %23, i32* %8
br label %11
24: ; preds = %11
ret void
}

LLVM IR (-O2):
%struct.list = type { i32 }
define void @list_each_r(%struct.list* %0, void (i8*, i8*)* nocapture %1, i8* %2) {
%4 = tail call i32 @list_size(%struct.list* %0)
%5 = icmp slt i32 %4, 1
br i1 %5, label %6, label %7
6: ; preds = %7, %3
ret void
7: ; preds = %3, %7
%8 = phi i32 [ %10, %7 ], [ 1, %3 ]
%9 = tail call i8* @list_get(%struct.list* %0, i32 %8)
tail call void %1(i8* %9, i8* %2)
%10 = add nuw i32 %8, 1
%11 = icmp eq i32 %8, %4
br i1 %11, label %6, label %7
}