#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 quicklist {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ ql_advance(struct quicklist **, int *, int);
void *ql_get(struct quicklist *, int);
void ql_map_reduce(struct quicklist *ql,
                   void (*mapfunc)(void *entry, void *data),
                   void (*reducefunc)(void *data, void *result), void *data,
                   void *result) {
  int qi;
  for (qi = 0; ql; ql_advance(&ql, &qi, 1)) {
    mapfunc(ql_get(ql, qi), data);
    reducefunc(data, result);
  }
}


x86 assembly (clang, -O0):
<ql_map_reduce>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1194 <ql_map_reduce+0x74>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1030 <ql_get@plt>
mov    %rax,%rdi
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%rsi
call   *%rax
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   *%rax
lea    -0x8(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
mov    $0x1,%edx
call   1040 <ql_advance@plt>
jmp    1143 <ql_map_reduce+0x23>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ql_map_reduce>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,0x10(%rsp)
movl   $0x0,0xc(%rsp)
test   %rdi,%rdi
je     11d5 <ql_map_reduce+0xb5>
mov    %r8,%r14
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rsi,%r12
xor    %esi,%esi
call   1030 <ql_get@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
call   *%r12
mov    %rbx,%rdi
mov    %r14,%rsi
call   *%r15
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rsi
mov    $0x1,%edx
call   1040 <ql_advance@plt>
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     11d5 <ql_map_reduce+0xb5>
lea    0x10(%rsp),%r13
lea    0xc(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0xc(%rsp),%esi
call   1030 <ql_get@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
call   *%r12
mov    %rbx,%rdi
mov    %r14,%rsi
call   *%r15
mov    %r13,%rdi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1040 <ql_advance@plt>
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
jne    11a0 <ql_map_reduce+0x80>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.quicklist = type { i32 }
define void @ql_map_reduce(%struct.quicklist* %0, void (i8*, i8*)* %1, void (i8*, i8*)* %2, i8* %3, i8* %4) {
%6 = alloca %struct.quicklist*
%7 = alloca void (i8*, i8*)*
%8 = alloca void (i8*, i8*)*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store %struct.quicklist* %0, %struct.quicklist** %6
store void (i8*, i8*)* %1, void (i8*, i8*)** %7
store void (i8*, i8*)* %2, void (i8*, i8*)** %8
store i8* %3, i8** %9
store i8* %4, i8** %10
store i32 0, i32* %11
br label %12
12: ; preds = %24, %5
%13 = load %struct.quicklist*, %struct.quicklist** %6
%14 = icmp ne %struct.quicklist* %13, null
br i1 %14, label %15, label %26
15: ; preds = %12
%16 = load void (i8*, i8*)*, void (i8*, i8*)** %7
%17 = load %struct.quicklist*, %struct.quicklist** %6
%18 = load i32, i32* %11
%19 = call i8* @ql_get(%struct.quicklist* %17, i32 %18)
%20 = load i8*, i8** %9
%21 = load void (i8*, i8*)*, void (i8*, i8*)** %8
%22 = load i8*, i8** %9
%23 = load i8*, i8** %10
br label %24
24: ; preds = %15
%25 = call i32 @ql_advance(%struct.quicklist** %6, i32* %11, i32 1)
br label %12
26: ; preds = %12
ret void
}

LLVM IR (-O2):
%struct.quicklist = type { i32 }
define void @ql_map_reduce(%struct.quicklist* %0, void (i8*, i8*)* nocapture %1, void (i8*, i8*)* nocapture %2, i8* %3, i8* %4) {
%6 = alloca %struct.quicklist*
%7 = alloca i32
store %struct.quicklist* %0, %struct.quicklist** %6
%8 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%9 = icmp eq %struct.quicklist* %0, null
br i1 %9, label %22, label %10
10: ; preds = %5
%11 = call i8* @ql_get(%struct.quicklist* %0, i32 0)
%12 = call i32 @ql_advance(%struct.quicklist** %6, i32* %7, i32 1)
%13 = load %struct.quicklist*, %struct.quicklist** %6
%14 = icmp eq %struct.quicklist* %13, null
br i1 %14, label %22, label %15
15: ; preds = %10, %15
%16 = phi %struct.quicklist* [ %20, %15 ], [ %13, %10 ]
%17 = load i32, i32* %7
%18 = call i8* @ql_get(%struct.quicklist* %16, i32 %17)
%19 = call i32 @ql_advance(%struct.quicklist** %6, i32* %7, i32 1)
%20 = load %struct.quicklist*, %struct.quicklist** %6
%21 = icmp eq %struct.quicklist* %20, null
br i1 %21, label %22, label %15
22: ; preds = %15, %10, %5
ret void
}