// File: /workspace/github_c_makefile_star2_O0/bluecmd[P]fst-example/gtkwave/fstapi.c
// Function: fstDetermineBreakSize
static void fstDetermineBreakSize(struct fstWriterContext *xc)
{
#if defined(__linux__) || defined(FST_MACOSX)
int was_set = 0;

#ifdef __linux__
FILE *f = fopen("/proc/meminfo", "rb");

if(f)
        {
        char buf[257];
        char *s;
        while(!feof(f))
                {
                buf[0] = 0;
                s = fgets(buf, 256, f);
                if(s && *s)
                        {
                        if(!strncmp(s, "MemTotal:", 9))
                                {
                                size_t v = atol(s+10);
                                v *= 1024; /* convert to bytes */
                                v /= 8; /* chop down to 1/8 physical memory */
                                if(v > FST_BREAK_SIZE)
                                        {
                                        if(v > FST_BREAK_SIZE_MAX)
                                                {
                                                v = FST_BREAK_SIZE_MAX;
                                                }

                                        xc->fst_huge_break_size = v;
                                        was_set = 1;
                                        break;
                                        }
                                }
                        }
                }

        fclose(f);
        }

if(!was_set)
        {
        xc->fst_huge_break_size = FST_BREAK_SIZE;
        }
#else
int mib[2];
int64_t v;
size_t length;

mib[0] = CTL_HW;
mib[1] = HW_MEMSIZE;
length = sizeof(int64_t);
if(!sysctl(mib, 2, &v, &length, NULL, 0))
        {
        v /= 8;

        if(v > (int64_t)FST_BREAK_SIZE)
                {
                if(v > (int64_t)FST_BREAK_SIZE_MAX)
                        {
                        v = FST_BREAK_SIZE_MAX;
                        }

                xc->fst_huge_break_size = v;
                was_set = 1;
                }
        }

if(!was_set)
        {
        xc->fst_huge_break_size = FST_BREAK_SIZE;
        }
#endif
#else
xc->fst_huge_break_size = FST_BREAK_SIZE;
#endif

xc->fst_break_size = xc->fst_orig_break_size = FST_BREAK_SIZE;
xc->fst_break_add_size = xc->fst_orig_break_add_size = FST_BREAK_ADD_SIZE;
xc->next_huge_break = FST_ACTIVATE_HUGE_BREAK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
leaq 0x26a5c(%rip), %rdi     # 0x2b469
leaq 0x26807(%rip), %rsi     # 0x2b21b
callq 0x2330
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x4b34
jmp 0x4a2a
movq -0x18(%rbp), %rdi
callq 0x2230
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x4a44
jmp 0x4b2b
movb $0x0, -0x120(%rbp)
leaq -0x120(%rbp), %rdi
movq -0x18(%rbp), %rdx
movl $0x100, %esi            # imm = 0x100
callq 0x21e0
movq %rax, -0x128(%rbp)
cmpq $0x0, -0x128(%rbp)
je 0x4b26
movq -0x128(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x4b26
movq -0x128(%rbp), %rdi
leaq 0x269e1(%rip), %rsi     # 0x2b477
movl $0x9, %edx
callq 0x2080
cmpl $0x0, %eax
jne 0x4b24
movq -0x128(%rbp), %rdi
addq $0xa, %rdi
callq 0x2310
movq %rax, -0x130(%rbp)
movq -0x130(%rbp), %rax
shlq $0xa, %rax
movq %rax, -0x130(%rbp)
movq -0x130(%rbp), %rax
shrq $0x3, %rax
movq %rax, -0x130(%rbp)
cmpq $0x8000000, -0x130(%rbp) # imm = 0x8000000
jbe 0x4b22
movl $0x80000000, %eax       # imm = 0x80000000
cmpq %rax, -0x130(%rbp)
jbe 0x4b07
movl $0x80000000, %eax       # imm = 0x80000000
movq %rax, -0x130(%rbp)
movq -0x130(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x110(%rax)
movl $0x1, -0xc(%rbp)
jmp 0x4b2b
jmp 0x4b24
jmp 0x4b26
jmp 0x4a2a
movq -0x18(%rbp), %rdi
callq 0x2110
cmpl $0x0, -0xc(%rbp)
jne 0x4b49
movq -0x8(%rbp), %rax
movq $0x8000000, 0x110(%rax) # imm = 0x8000000
movq -0x8(%rbp), %rax
movq $0x8000000, 0xf0(%rax) # imm = 0x8000000
movq -0x8(%rbp), %rax
movq $0x8000000, 0x100(%rax) # imm = 0x8000000
movq -0x8(%rbp), %rax
movq $0x400000, 0xf8(%rax) # imm = 0x400000
movq -0x8(%rbp), %rax
movq $0x400000, 0x108(%rax) # imm = 0x400000
movq -0x8(%rbp), %rax
movl $0xf4240, 0x118(%rax)   # imm = 0xF4240
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopl (%rax)