#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 */
typedef int /*<<< orphan*/ __u8;
typedef int __u32;
typedef int /*<<< orphan*/ __s32;

/* Variables and functions */
void *MAP_FAILED;
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ PROT_READ;
int axisGetReadBufferCount(int /*<<< orphan*/);
int axisGetReadBufferSize(int /*<<< orphan*/);
int /*<<< orphan*/ free(int /*<<< orphan*/ **);
scalar_t__ malloc(int);
void *mmap(int /*<<< orphan*/, int, int /*<<< orphan*/, int /*<<< orphan*/,
           int /*<<< orphan*/, int);
__u8 **axisMapUser(__s32 fd, __u32 *count, __u32 *size) {
  void *temp;
  __u8 **ret;
  __u32 bCount;
  __u32 bSize;
  __u32 x;
  ;
  bCount = axisGetReadBufferCount(fd);
  bSize = axisGetReadBufferSize(fd);
  if (count != NULL)
    *count = bCount;
  if (size != NULL)
    *size = bSize;
  if ((ret = (__u8 **)malloc(sizeof(__u8 *) * bCount)) == 0)
    return (NULL);
  for (x = 0; x < bCount; x++) {
    if ((temp = mmap(0, bSize, PROT_READ, MAP_PRIVATE, fd, (bSize * x))) ==
        MAP_FAILED) {
      free(ret);
      return (NULL);
    }
    ret[x] = (__u8 *)temp;
  }
  return (ret);
}


x86 assembly (clang, -O0):
<axisMapUser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0xc(%rbp),%edi
call   1070 <axisGetReadBufferCount@plt>
mov    %eax,-0x34(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <axisGetReadBufferSize@plt>
mov    %eax,-0x38(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     118d <axisMapUser+0x3d>
mov    -0x34(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     11a1 <axisMapUser+0x51>
mov    -0x38(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movslq -0x34(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11cb <axisMapUser+0x7b>
movq   $0x0,-0x8(%rbp)
jmp    1257 <axisMapUser+0x107>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    124f <axisMapUser+0xff>
mov    -0x38(%rbp),%esi
mov    0x2e10(%rip),%rax
mov    (%rax),%edx
mov    0x2de7(%rip),%rax
mov    (%rax),%ecx
mov    -0xc(%rbp),%r8d
mov    -0x38(%rbp),%r9d
imul   -0x3c(%rbp),%r9d
xor    %edi,%edi
call   1040 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    0x2dbe(%rip),%rcx
cmp    (%rcx),%rax
jne    1231 <axisMapUser+0xe1>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1257 <axisMapUser+0x107>
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11d2 <axisMapUser+0x82>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<axisMapUser>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %edi,%r14d
call   1070 <axisGetReadBufferCount@plt>
mov    %eax,%r12d
mov    %r14d,%edi
call   1050 <axisGetReadBufferSize@plt>
mov    %eax,%ebp
test   %rbx,%rbx
je     117e <axisMapUser+0x2e>
mov    %r12d,(%rbx)
test   %r15,%r15
je     1186 <axisMapUser+0x36>
mov    %ebp,(%r15)
lea    0x0(,%r12,8),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11f6 <axisMapUser+0xa6>
mov    %rax,%r15
test   %r12d,%r12d
jle    11f9 <axisMapUser+0xa9>
mov    %r12d,%r12d
xor    %ebx,%ebx
xor    %r13d,%r13d
nopl   0x0(%rax,%rax,1)
mov    0x2e41(%rip),%rax
mov    (%rax),%edx
mov    0x2e18(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %ebp,%esi
mov    %r14d,%r8d
mov    %ebx,%r9d
call   1040 <mmap@plt>
mov    0x2df8(%rip),%rcx
cmp    (%rcx),%rax
je     11ee <axisMapUser+0x9e>
mov    %rax,(%r15,%r13,8)
add    $0x1,%r13
add    %ebp,%ebx
cmp    %r13,%r12
jne    11b0 <axisMapUser+0x60>
jmp    11f9 <axisMapUser+0xa9>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
define i32** @axisMapUser(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32**
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32**
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%13 = load i32, i32* %5
%14 = call i32 @axisGetReadBufferCount(i32 %13)
store i32 %14, i32* %10
%15 = load i32, i32* %5
%16 = call i32 @axisGetReadBufferSize(i32 %15)
store i32 %16, i32* %11
%17 = load i32*, i32** %6
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %3
%20 = load i32, i32* %10
%21 = load i32*, i32** %6
store i32 %20, i32* %21
br label %22
22: ; preds = %19, %3
%23 = load i32*, i32** %7
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* %11
%27 = load i32*, i32** %7
store i32 %26, i32* %27
br label %28
28: ; preds = %25, %22
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = mul i64 8, %30
%32 = trunc i64 %31 to i32
%33 = call i64 @malloc(i32 %32)
%34 = inttoptr i64 %33 to i32**
store i32** %34, i32*** %9
%35 = icmp eq i32** %34, null
br i1 %35, label %36, label %37
36: ; preds = %28
store i32** null, i32*** %4
br label %68
37: ; preds = %28
store i32 0, i32* %12
br label %38
38: ; preds = %63, %37
%39 = load i32, i32* %12
%40 = load i32, i32* %10
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %66
42: ; preds = %38
%43 = load i32, i32* %11
%44 = load i32, i32* @PROT_READ
%45 = load i32, i32* @MAP_PRIVATE
%46 = load i32, i32* %5
%47 = load i32, i32* %11
%48 = load i32, i32* %12
%49 = mul nsw i32 %47, %48
%50 = call i8* @mmap(i32 0, i32 %43, i32 %44, i32 %45, i32 %46, i32 %49)
store i8* %50, i8** %8
%51 = load i8*, i8** @MAP_FAILED
%52 = icmp eq i8* %50, %51
br i1 %52, label %53, label %56
53: ; preds = %42
%54 = load i32**, i32*** %9
%55 = call i32 @free(i32** %54)
store i32** null, i32*** %4
br label %68
56: ; preds = %42
%57 = load i8*, i8** %8
%58 = bitcast i8* %57 to i32*
%59 = load i32**, i32*** %9
%60 = load i32, i32* %12
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32*, i32** %59, i64 %61
store i32* %58, i32** %62
br label %63
63: ; preds = %56
%64 = load i32, i32* %12
%65 = add nsw i32 %64, 1
store i32 %65, i32* %12
br label %38
66: ; preds = %38
%67 = load i32**, i32*** %9
store i32** %67, i32*** %4
br label %68
68: ; preds = %66, %53, %36
%69 = load i32**, i32*** %4
ret i32** %69
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
define i32** @axisMapUser(i32 %0, i32* writeonly %1, i32* writeonly %2) {
%4 = tail call i32 @axisGetReadBufferCount(i32 %0)
%5 = tail call i32 @axisGetReadBufferSize(i32 %0)
%6 = icmp eq i32* %1, null
br i1 %6, label %8, label %7
7: ; preds = %3
store i32 %4, i32* %1
br label %8
8: ; preds = %7, %3
%9 = icmp eq i32* %2, null
br i1 %9, label %11, label %10
10: ; preds = %8
store i32 %5, i32* %2
br label %11
11: ; preds = %10, %8
%12 = shl i32 %4, 3
%13 = tail call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i32**
%15 = icmp eq i64 %13, 0
br i1 %15, label %36, label %16
16: ; preds = %11
%17 = icmp sgt i32 %4, 0
br i1 %17, label %18, label %36
18: ; preds = %16
%19 = zext i32 %4 to i64
br label %20
20: ; preds = %18, %31
%21 = phi i64 [ 0, %18 ], [ %34, %31 ]
%22 = load i32, i32* @PROT_READ
%23 = load i32, i32* @MAP_PRIVATE
%24 = trunc i64 %21 to i32
%25 = mul i32 %5, %24
%26 = tail call i8* @mmap(i32 0, i32 %5, i32 %22, i32 %23, i32 %0, i32 %25)
%27 = load i8*, i8** @MAP_FAILED
%28 = icmp eq i8* %26, %27
br i1 %28, label %29, label %31
29: ; preds = %20
%30 = tail call i32 @free(i32** %14)
br label %36
31: ; preds = %20
%32 = getelementptr inbounds i32*, i32** %14, i64 %21
%33 = bitcast i32** %32 to i8**
store i8* %26, i8** %33
%34 = add nuw nsw i64 %21, 1
%35 = icmp eq i64 %34, %19
br i1 %35, label %36, label %20
36: ; preds = %31, %16, %11, %29
%37 = phi i32** [ null, %29 ], [ null, %11 ], [ %14, %16 ], [ %14, %31 ]
ret i32** %37
}