#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*/ memcpy(void *, void const *, size_t);
void gsum(const void *items, size_t len, size_t width,
          void (*sum)(const void *, const void *, void *OutResult),
          void *OutResult) {
  memcpy(OutResult, items, width);
  for (size_t i = 1u; i < len; ++i) {
    const void *pItem = (char *)items + i * width;
    sum(pItem, OutResult, OutResult);
  }
}


x86 assembly (clang, -O0):
<gsum>:
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)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <memcpy@plt>
movq   $0x1,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    118a <gsum+0x7a>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
imul   -0x18(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   *%rax
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1145 <gsum+0x35>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gsum>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %r8,%r12
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%rbx
mov    %r8,%rdi
mov    %rbx,%rsi
call   1030 <memcpy@plt>
cmp    $0x2,%r13
jb     1155 <gsum+0x45>
add    $0xffffffffffffffff,%r13
add    %r15,%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r12,%rdx
call   *%r14
add    %r15,%rbx
add    $0xffffffffffffffff,%r13
jne    1140 <gsum+0x30>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @gsum(i8* %0, i64 %1, i64 %2, void (i8*, i8*, i8*)* %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca void (i8*, i8*, i8*)*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store void (i8*, i8*, i8*)* %3, void (i8*, i8*, i8*)** %9
store i8* %4, i8** %10
%13 = load i8*, i8** %10
%14 = load i8*, i8** %6
%15 = load i64, i64* %8
%16 = call i32 @memcpy(i8* %13, i8* %14, i64 %15)
store i64 1, i64* %11
br label %17
17: ; preds = %31, %5
%18 = load i64, i64* %11
%19 = load i64, i64* %7
%20 = icmp ult i64 %18, %19
br i1 %20, label %21, label %34
21: ; preds = %17
%22 = load i8*, i8** %6
%23 = load i64, i64* %11
%24 = load i64, i64* %8
%25 = mul i64 %23, %24
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8* %26, i8** %12
%27 = load void (i8*, i8*, i8*)*, void (i8*, i8*, i8*)** %9
%28 = load i8*, i8** %12
%29 = load i8*, i8** %10
%30 = load i8*, i8** %10
br label %31
31: ; preds = %21
%32 = load i64, i64* %11
%33 = add i64 %32, 1
store i64 %33, i64* %11
br label %17
34: ; preds = %17
ret void
}

LLVM IR (-O2):
define void @gsum(i8* %0, i64 %1, i64 %2, void (i8*, i8*, i8*)* nocapture %3, i8* %4) {
%6 = tail call i32 @memcpy(i8* %4, i8* %0, i64 %2)
%7 = icmp ugt i64 %1, 1
br i1 %7, label %9, label %8
8: ; preds = %9, %5
ret void
9: ; preds = %5, %9
%10 = phi i64 [ %13, %9 ], [ 1, %5 ]
%11 = mul i64 %10, %2
%12 = getelementptr inbounds i8, i8* %0, i64 %11
tail call void %3(i8* %12, i8* %4, i8* %4)
%13 = add nuw i64 %10, 1
%14 = icmp eq i64 %13, %1
br i1 %14, label %8, label %9
}