// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: memjrnlRead
static int memjrnlRead(
  sqlite3_file *pJfd,    /* The journal file from which to read */
  void *zBuf,            /* Put the results here */
  int iAmt,              /* Number of bytes to read */
  sqlite_int64 iOfst     /* Begin reading at this offset */
){
  MemJournal *p = (MemJournal *)pJfd;
  u8 *zOut = zBuf;
  int nRead = iAmt;
  int iChunkOffset;
  FileChunk *pChunk;

  /* SQLite never tries to read past the end of a rollback journal file */
  assert( iOfst+iAmt<=p->endpoint.iOffset );

  if( p->readpoint.iOffset!=iOfst || iOfst==0 ){
    sqlite3_int64 iOff = 0;
    for(pChunk=p->pFirst; 
        ALWAYS(pChunk) && (iOff+JOURNAL_CHUNKSIZE)<=iOfst;
        pChunk=pChunk->pNext
    ){
      iOff += JOURNAL_CHUNKSIZE;
    }
  }else{
    pChunk = p->readpoint.pChunk;
  }

  iChunkOffset = (int)(iOfst%JOURNAL_CHUNKSIZE);
  do {
    int iSpace = JOURNAL_CHUNKSIZE - iChunkOffset;
    int nCopy = MIN(nRead, (JOURNAL_CHUNKSIZE - iChunkOffset));
    memcpy(zOut, &pChunk->zChunk[iChunkOffset], nCopy);
    zOut += nCopy;
    nRead -= iSpace;
    iChunkOffset = 0;
  } while( nRead>=0 && (pChunk=pChunk->pNext)!=0 && nRead>0 );
  p->readpoint.iOffset = iOfst+iAmt;
  p->readpoint.pChunk = pChunk;

  return SQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
cmpq -0x20(%rbp), %rax
jne 0x21d22
cmpq $0x0, -0x20(%rbp)
jne 0x21d7c
movq $0x0, -0x48(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x40(%rbp)
movb %al, -0x51(%rbp)
je 0x21d56
movq -0x48(%rbp), %rax
addq $0x3f8, %rax            # imm = 0x3F8
cmpq -0x20(%rbp), %rax
setle %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x21d5f
jmp 0x21d7a
movq -0x48(%rbp), %rax
addq $0x3f8, %rax            # imm = 0x3F8
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x21d36
jmp 0x21d88
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movl $0x3f8, %ecx            # imm = 0x3F8
cqto
idivq %rcx
movl %edx, %eax
movl %eax, -0x38(%rbp)
movl $0x3f8, %eax            # imm = 0x3F8
subl -0x38(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x34(%rbp), %eax
movl $0x3f8, %ecx            # imm = 0x3F8
subl -0x38(%rbp), %ecx
cmpl %ecx, %eax
jge 0x21dbd
movl -0x34(%rbp), %eax
movl %eax, -0x58(%rbp)
jmp 0x21dc8
movl $0x3f8, %eax            # imm = 0x3F8
subl -0x38(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x30(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq $0x8, %rsi
movslq -0x38(%rbp), %rax
addq %rax, %rsi
movslq -0x50(%rbp), %rdx
callq 0x82f0
movl -0x50(%rbp), %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl -0x4c(%rbp), %ecx
movl -0x34(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x34(%rbp)
movb %al, -0x59(%rbp)
jl 0x21e38
movq -0x40(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x40(%rbp)
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x59(%rbp)
je 0x21e38
cmpl $0x0, -0x34(%rbp)
setg %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0x21d9b
movq -0x20(%rbp), %rcx
movslq -0x14(%rbp), %rax
addq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x40(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x28(%rax)
xorl %eax, %eax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)