#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 */
scalar_t__ get_buf_offset(int /*<<< orphan*/);
scalar_t__ get_mini_offset(int);
int /*<<< orphan*/ get_minisection_sector(int);
int *get_mtab(int);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, scalar_t__, int);
char *realloc(char *, int);
char *read_stream_mini(int start, int size) {
  char *lbuf = malloc(4);
  int lsize = 0;
  int *mtab = NULL;
  int sector;
  sector = start;
  while (lsize < size) {
    lbuf = realloc(lbuf, lsize + 64);
    memcpy(lbuf + lsize,
           get_buf_offset(get_minisection_sector(sector)) +
               get_mini_offset(sector),
           64);
    lsize += 64;
    mtab = get_mtab(sector);
    sector = mtab[sector];
  }
  return lbuf;
}


x86 assembly (clang, -O0):
<read_stream_mini>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1227 <read_stream_mini+0xb7>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x40,%esi
call   1090 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
call   1040 <get_minisection_sector@plt>
mov    %eax,%edi
call   1060 <get_buf_offset@plt>
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <get_mini_offset@plt>
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdi
add    %rax,%rsi
mov    $0x40,%edx
call   1070 <memcpy@plt>
mov    -0x14(%rbp),%eax
add    $0x40,%eax
mov    %eax,-0x14(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <get_mtab@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x24(%rbp)
jmp    11a1 <read_stream_mini+0x31>
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_stream_mini>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%r12d
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
test   %ebx,%ebx
jle    11f9 <read_stream_mini+0x89>
mov    %ebx,%r13d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
lea    0x40(%rbx),%r15
mov    %r14,%rdi
mov    %r15d,%esi
call   1090 <realloc@plt>
mov    %rax,%r14
add    %rax,%rbx
mov    %r12d,%edi
call   1040 <get_minisection_sector@plt>
mov    %eax,%edi
call   1060 <get_buf_offset@plt>
mov    %rax,%rbp
mov    %r12d,%edi
call   1030 <get_mini_offset@plt>
add    %rax,%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x40,%edx
call   1070 <memcpy@plt>
mov    %r12d,%edi
call   1050 <get_mtab@plt>
movslq %r12d,%rcx
mov    (%rax,%rcx,4),%r12d
mov    %r15,%rbx
cmp    %r13,%r15
jb     11a0 <read_stream_mini+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @read_stream_mini(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%9 = call i8* @malloc(i32 4)
store i8* %9, i8** %5
store i32 0, i32* %6
store i32* null, i32** %7
%10 = load i32, i32* %3
store i32 %10, i32* %8
br label %11
11: ; preds = %15, %2
%12 = load i32, i32* %6
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %40
15: ; preds = %11
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 64
%19 = call i8* @realloc(i8* %16, i32 %18)
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i32, i32* %8
%25 = call i32 @get_minisection_sector(i32 %24)
%26 = call i64 @get_buf_offset(i32 %25)
%27 = load i32, i32* %8
%28 = call i64 @get_mini_offset(i32 %27)
%29 = add nsw i64 %26, %28
%30 = call i32 @memcpy(i8* %23, i64 %29, i32 64)
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 64
store i32 %32, i32* %6
%33 = load i32, i32* %8
%34 = call i32* @get_mtab(i32 %33)
store i32* %34, i32** %7
%35 = load i32*, i32** %7
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = load i32, i32* %38
store i32 %39, i32* %8
br label %11
40: ; preds = %11
%41 = load i8*, i8** %5
ret i8* %41
}

LLVM IR (-O2):
define i8* @read_stream_mini(i32 %0, i32 %1) {
%3 = tail call dereferenceable_or_null(4) i8* @malloc(i32 4)
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %25
5: ; preds = %2
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %11, %7 ]
%9 = phi i32 [ %0, %5 ], [ %23, %7 ]
%10 = phi i8* [ %3, %5 ], [ %13, %7 ]
%11 = add nuw nsw i64 %8, 64
%12 = trunc i64 %11 to i32
%13 = tail call i8* @realloc(i8* %10, i32 %12)
%14 = getelementptr inbounds i8, i8* %13, i64 %8
%15 = tail call i32 @get_minisection_sector(i32 %9)
%16 = tail call i64 @get_buf_offset(i32 %15)
%17 = tail call i64 @get_mini_offset(i32 %9)
%18 = add nsw i64 %17, %16
%19 = tail call i32 @memcpy(i8* %14, i64 %18, i32 64)
%20 = tail call i32* @get_mtab(i32 %9)
%21 = sext i32 %9 to i64
%22 = getelementptr inbounds i32, i32* %20, i64 %21
%23 = load i32, i32* %22
%24 = icmp ult i64 %11, %6
br i1 %24, label %7, label %25
25: ; preds = %7, %2
%26 = phi i8* [ %3, %2 ], [ %13, %7 ]
ret i8* %26
}