void *loadall(struct arreader *a, int (*rf)(void *data, int len), int size) {
  char *ret = calloc(size + 1, 1);
  if (ret == 0 || size != rf(ret, size))
    die(a, "can't loadall");
  return ret;
}


x86 assembly (clang, -O0):
<loadall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rdi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1175 <loadall+0x55>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   *%rax
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
je     1187 <loadall+0x67>
mov    -0x8(%rbp),%rdi
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1040 <die@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loadall>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,%r14
lea    0x1(%r15),%eax
movslq %eax,%rdi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1158 <loadall+0x38>
mov    %rbx,%rdi
mov    %r15d,%esi
call   *%r12
cmp    %r15d,%eax
je     1169 <loadall+0x49>
lea    0xea1(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <die@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.arreader = type opaque
@.str = [14 x i8] c"can't loadall\00"
define i8* @loadall(%struct.arreader* %0, i32 (i8*, i32)* %1, i32 %2) {
%4 = alloca %struct.arreader*
%5 = alloca i32 (i8*, i32)*
%6 = alloca i32
%7 = alloca i8*
store %struct.arreader* %0, %struct.arreader** %4
store i32 (i8*, i32)* %1, i32 (i8*, i32)** %5
store i32 %2, i32* %6
%8 = load i32, i32* %6
%9 = add nsw i32 %8, 1
%10 = sext i32 %9 to i64
%11 = call i8* @calloc(i64 %10, i64 1)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = icmp eq i8* %12, null
br i1 %13, label %21, label %14
14: ; preds = %3
%15 = load i32, i32* %6
%16 = load i32 (i8*, i32)*, i32 (i8*, i32)** %5
%17 = load i8*, i8** %7
%18 = load i32, i32* %6
%19 = call i32 %16(i8* %17, i32 %18)
%20 = icmp ne i32 %15, %19
br i1 %20, label %21, label %24
21: ; preds = %14, %3
%22 = load %struct.arreader*, %struct.arreader** %4
%23 = call i32 (%struct.arreader*, i8*, ...) bitcast (i32 (...)* @die to i32 (%struct.arreader*, i8*, ...)*)(%struct.arreader* %22, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %21, %14
%25 = load i8*, i8** %7
ret i8* %25
}

LLVM IR (-O2):
%struct.arreader = type opaque
@.str = [14 x i8] c"can't loadall\00"
define i8* @loadall(%struct.arreader* %0, i32 (i8*, i32)* nocapture %1, i32 %2) {
%4 = add nsw i32 %2, 1
%5 = sext i32 %4 to i64
%6 = tail call i8* @calloc(i64 %5, i64 1)
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = tail call i32 %1(i8* %6, i32 %2)
%10 = icmp eq i32 %9, %2
br i1 %10, label %13, label %11
11: ; preds = %8, %3
%12 = tail call i32 (%struct.arreader*, i8*, ...) bitcast (i32 (...)* @die to i32 (%struct.arreader*, i8*, ...)*)(%struct.arreader* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %8
ret i8* %6
}