#include <fcntl.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>

typedef struct
{
    long time;
    double open;
    double high;
    double low;
    double close;
    double volume;
} Minute;

typedef struct
{
    int nbrMinutes;
    Minute *minutes;
} Data;

typedef struct
{
    long seed;
    long res;
} Worker;

__global__ void bake(Data data, Worker *workers)
{
    int workerNbr = threadIdx.x + blockIdx.x * blockDim.x;
    workers[workerNbr].res = (workerNbr * 5 / 2 + 50 / 3 * 5) % 52 == 0 ? 1 : 0;
    // for (int i = 0; i < data.nbrMinutes * 0.1; i++)
    // {
    //     if (data.minutes[i].open > workers[workerNbr].seed)
    //     {

    //     }
    // }
}

Data loadMinutes(char *path)
{
    Data data;
    int fd = open(path, O_RDONLY);
    struct stat buf;
    fstat(fd, &buf);
    off_t size = buf.st_size;
    cudaMallocManaged(&data.minutes, size);
    int rd = read(fd, data.minutes, size);
    if (rd <= 0)
    {
        printf("ERROR LOAD FILE\n");
        exit(0);
    }
    data.nbrMinutes = size / sizeof(Minute);
    return data;
}

void printMinute(Minute *minute)
{
    printf("%ld OPEN: %-10.5lf HIGH: %-10.5lf LOW: %-10.5lf CLOSE: %-10.5lf VOLUME: %-10.5lf\n",
           minute->time, minute->open, minute->high, minute->low,
           minute->close, minute->volume);
}

void searchPike(Data data)
{
    printf("%d\n", data.nbrMinutes);
    int founds = 0;
    for (int i = 40; i < data.nbrMinutes - 40; i++)
    {
        double chien = data.minutes[i].open / data.minutes[i + 20].open;
        if (chien > 1.025 || chien < 0.975)
        {
            printf("%lf %d\n", chien, founds);
            founds += 1;
        }
    }
}

int main()
{
    Data data = loadMinutes("./data");
    // searchPike(data);

    int nbrX = 4096 * 8;
    int nbrY = 1024;
    int nbrThreads = nbrX * nbrY;

    // Worker *ramWorkers;
    // malloc(ramWorkers, nbrThreads * sizeof(Worker));

    Worker *workers;

    cudaMalloc(&workers, nbrThreads * sizeof(Worker));
    // workers = (Worker *)malloc(nbrThreads * sizeof(Worker));


    // cudaMallocManaged(&workers, nbrThreads * sizeof(Worker));
    for (long i = 0; 1; i++)
    {
        bake<<<nbrX, nbrY>>>(data, workers);
        cudaDeviceSynchronize();
        cudaError_t error = cudaGetLastError();
        if (error != cudaSuccess)
        {
            printf("CUDA error: %s\n", cudaGetErrorString(error));
            exit(-1);
        }
        if (i % 10 == 0)
        {
            printf("DONE %ld - %ld B\n", i, i * nbrX * nbrY / 1000000000);
        }
        if (i * nbrX * nbrY / 1000000000 >= 100){
            // break;
        }
    }

    // for (long i = 0; 1; i++)
    // {
    //     long chien = i * 5 / 2 + 50 / 3 * 5;
    //     // workers[i % 2 == 0 ? 0 : 1] = chien;
    //     workers[1].res = chien % 52 == 0 ? 1 : 0;

    //     if (i % 1000000 == 0)
    //     {
    //         printf("DONE %ldM\n", i / 1000000);
    //     }
    // }

    // printMinute(&data.minutes[0]);
    return 0;
}
	.file	"tmpxft_00207e27_00000000-6_main.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2050:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2050:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"ERROR LOAD FILE\n"
	.text
	.globl	_Z11loadMinutesPc
	.type	_Z11loadMinutesPc, @function
_Z11loadMinutesPc:
.LFB2044:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	xorl	%esi, %esi
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	subq	$184, %rsp
	.cfi_def_cfa_offset 208
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	call	__open_2@PLT
	leaq	24(%rsp), %rsi
	movl	%eax, %edi
	movl	%eax, %ebp
	call	fstat@PLT
	movq	72(%rsp), %rbx
	leaq	16(%rsp), %rdi
	movl	$1, %edx
	movq	%rbx, %rsi
	call	cudaMallocManaged@PLT
	movq	16(%rsp), %rsi
	orq	$-1, %rcx
	movl	%ebp, %edi
	movq	%rbx, %rdx
	call	__read_chk@PLT
	testl	%eax, %eax
	jg	.L3
	movl	$2, %edi
	leaq	.LC0(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%edi, %edi
	call	exit@PLT
.L3:
	movl	$48, %ecx
	movq	%rbx, %rax
	xorl	%edx, %edx
	divq	%rcx
	movq	16(%rsp), %rdx
	movl	%eax, 8(%rsp)
	movq	8(%rsp), %rax
	movq	168(%rsp), %rcx
	subq	%fs:40, %rcx
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$184, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2044:
	.size	_Z11loadMinutesPc, .-_Z11loadMinutesPc
	.section	.rodata.str1.1
.LC1:
	.string	"%ld OPEN: %-10.5lf HIGH: %-10.5lf LOW: %-10.5lf CLOSE: %-10.5lf VOLUME: %-10.5lf\n"
	.text
	.globl	_Z11printMinuteP6Minute
	.type	_Z11printMinuteP6Minute, @function
_Z11printMinuteP6Minute:
.LFB2045:
	.cfi_startproc
	endbr64
	movsd	8(%rdi), %xmm0
	movsd	40(%rdi), %xmm4
	movb	$5, %al
	leaq	.LC1(%rip), %rsi
	movsd	32(%rdi), %xmm3
	movsd	24(%rdi), %xmm2
	movsd	16(%rdi), %xmm1
	movq	(%rdi), %rdx
	movl	$2, %edi
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2045:
	.size	_Z11printMinuteP6Minute, .-_Z11printMinuteP6Minute
	.section	.rodata.str1.1
.LC2:
	.string	"%d\n"
.LC5:
	.string	"%lf %d\n"
	.text
	.globl	_Z10searchPike4Data
	.type	_Z10searchPike4Data, @function
_Z10searchPike4Data:
.LFB2046:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	xorl	%eax, %eax
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movl	$40, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movl	%edi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rsi, %rbx
	leaq	.LC2(%rip), %rsi
	pushq	%rdx
	.cfi_def_cfa_offset 48
	movl	%edi, %edx
	movl	$2, %edi
	addq	$1928, %rbx
	call	__printf_chk@PLT
.L9:
	leal	-40(%rbp), %eax
	cmpl	%r12d, %eax
	jle	.L15
	movsd	(%rbx), %xmm0
	divsd	960(%rbx), %xmm0
	comisd	.LC3(%rip), %xmm0
	ja	.L10
	movsd	.LC4(%rip), %xmm1
	comisd	%xmm0, %xmm1
	jbe	.L11
.L10:
	movl	%r13d, %edx
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	call	__printf_chk@PLT
	incl	%r13d
.L11:
	incl	%r12d
	addq	$48, %rbx
	jmp	.L9
.L15:
	popq	%rax
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2046:
	.size	_Z10searchPike4Data, .-_Z10searchPike4Data
	.globl	_Z34__device_stub__Z4bake4DataP6WorkerR4DataP6Worker
	.type	_Z34__device_stub__Z4bake4DataP6WorkerR4DataP6Worker, @function
_Z34__device_stub__Z4bake4DataP6WorkerR4DataP6Worker:
.LFB2072:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rsi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movq	%rdi, 88(%rsp)
	leaq	40(%rsp), %rdi
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movl	$1, 48(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L16
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z4bake4DataP6Worker(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L16:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L18
	call	__stack_chk_fail@PLT
.L18:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2072:
	.size	_Z34__device_stub__Z4bake4DataP6WorkerR4DataP6Worker, .-_Z34__device_stub__Z4bake4DataP6WorkerR4DataP6Worker
	.globl	_Z4bake4DataP6Worker
	.type	_Z4bake4DataP6Worker, @function
_Z4bake4DataP6Worker:
.LFB2073:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movq	%rdi, (%rsp)
	movq	%rsp, %rdi
	movq	%rsi, 8(%rsp)
	movq	%rdx, %rsi
	call	_Z34__device_stub__Z4bake4DataP6WorkerR4DataP6Worker
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2073:
	.size	_Z4bake4DataP6Worker, .-_Z4bake4DataP6Worker
	.section	.rodata.str1.1
.LC6:
	.string	"./data"
.LC7:
	.string	"CUDA error: %s\n"
.LC8:
	.string	"DONE %ld - %ld B\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2047:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC6(%rip), %rdi
	movabsq	$4294968320, %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	xorl	%ebx, %ebx
	subq	$72, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	call	_Z11loadMinutesPc
	leaq	8(%rsp), %rdi
	movl	$536870912, %esi
	movq	%rdx, %rbp
	movq	%rax, %r12
	call	cudaMalloc@PLT
.L26:
	movl	$131073, %edi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%r13, %rdx
	salq	$15, %rdi
	movl	$1, %ecx
	movl	$1, %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L23
	movq	8(%rsp), %rsi
	leaq	40(%rsp), %rdi
	movq	%r12, 40(%rsp)
	movq	%rbp, 48(%rsp)
	call	_Z34__device_stub__Z4bake4DataP6WorkerR4DataP6Worker
.L23:
	call	cudaDeviceSynchronize@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L24
	call	cudaGetErrorString@PLT
	movl	$2, %edi
	leaq	.LC7(%rip), %rsi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	orl	$-1, %edi
	call	exit@PLT
.L24:
	movq	%rbx, %rax
	movl	$10, %ecx
	cqto
	idivq	%rcx
	testq	%rdx, %rdx
	jne	.L25
	movq	%rbx, %rax
	movl	$1000000000, %ecx
	movl	$2, %edi
	salq	$25, %rax
	leaq	.LC8(%rip), %rsi
	cqto
	idivq	%rcx
	movq	%rbx, %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L25:
	incq	%rbx
	jmp	.L26
	.cfi_endproc
.LFE2047:
	.size	main, .-main
	.section	.rodata.str1.1
.LC9:
	.string	"_Z4bake4DataP6Worker"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2075:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC9(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z4bake4DataP6Worker(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2075:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC3:
	.long	1717986918
	.long	1072719462
	.align 8
.LC4:
	.long	858993459
	.long	1072640819
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <fcntl.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>

typedef struct
{
    long time;
    double open;
    double high;
    double low;
    double close;
    double volume;
} Minute;

typedef struct
{
    int nbrMinutes;
    Minute *minutes;
} Data;

typedef struct
{
    long seed;
    long res;
} Worker;

__global__ void bake(Data data, Worker *workers)
{
    int workerNbr = threadIdx.x + blockIdx.x * blockDim.x;
    workers[workerNbr].res = (workerNbr * 5 / 2 + 50 / 3 * 5) % 52 == 0 ? 1 : 0;
    // for (int i = 0; i < data.nbrMinutes * 0.1; i++)
    // {
    //     if (data.minutes[i].open > workers[workerNbr].seed)
    //     {

    //     }
    // }
}

Data loadMinutes(char *path)
{
    Data data;
    int fd = open(path, O_RDONLY);
    struct stat buf;
    fstat(fd, &buf);
    off_t size = buf.st_size;
    hipMallocManaged(&data.minutes, size);
    int rd = read(fd, data.minutes, size);
    if (rd <= 0)
    {
        printf("ERROR LOAD FILE\n");
        exit(0);
    }
    data.nbrMinutes = size / sizeof(Minute);
    return data;
}

void printMinute(Minute *minute)
{
    printf("%ld OPEN: %-10.5lf HIGH: %-10.5lf LOW: %-10.5lf CLOSE: %-10.5lf VOLUME: %-10.5lf\n",
           minute->time, minute->open, minute->high, minute->low,
           minute->close, minute->volume);
}

void searchPike(Data data)
{
    printf("%d\n", data.nbrMinutes);
    int founds = 0;
    for (int i = 40; i < data.nbrMinutes - 40; i++)
    {
        double chien = data.minutes[i].open / data.minutes[i + 20].open;
        if (chien > 1.025 || chien < 0.975)
        {
            printf("%lf %d\n", chien, founds);
            founds += 1;
        }
    }
}

int main()
{
    Data data = loadMinutes("./data");
    // searchPike(data);

    int nbrX = 4096 * 8;
    int nbrY = 1024;
    int nbrThreads = nbrX * nbrY;

    // Worker *ramWorkers;
    // malloc(ramWorkers, nbrThreads * sizeof(Worker));

    Worker *workers;

    hipMalloc(&workers, nbrThreads * sizeof(Worker));
    // workers = (Worker *)malloc(nbrThreads * sizeof(Worker));


    // cudaMallocManaged(&workers, nbrThreads * sizeof(Worker));
    for (long i = 0; 1; i++)
    {
        bake<<<nbrX, nbrY>>>(data, workers);
        hipDeviceSynchronize();
        hipError_t error = hipGetLastError();
        if (error != hipSuccess)
        {
            printf("CUDA error: %s\n", hipGetErrorString(error));
            exit(-1);
        }
        if (i % 10 == 0)
        {
            printf("DONE %ld - %ld B\n", i, i * nbrX * nbrY / 1000000000);
        }
        if (i * nbrX * nbrY / 1000000000 >= 100){
            // break;
        }
    }

    // for (long i = 0; 1; i++)
    // {
    //     long chien = i * 5 / 2 + 50 / 3 * 5;
    //     // workers[i % 2 == 0 ? 0 : 1] = chien;
    //     workers[1].res = chien % 52 == 0 ? 1 : 0;

    //     if (i % 1000000 == 0)
    //     {
    //         printf("DONE %ldM\n", i / 1000000);
    //     }
    // }

    // printMinute(&data.minutes[0]);
    return 0;
}
	.text
	.file	"main.hip"
	.globl	_Z19__device_stub__bake4DataP6Worker # -- Begin function _Z19__device_stub__bake4DataP6Worker
	.type	_Z19__device_stub__bake4DataP6Worker,@function
_Z19__device_stub__bake4DataP6Worker:   # @_Z19__device_stub__bake4DataP6Worker
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$96, %rsp
	.cfi_def_cfa_offset 144
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	80(%rsp), %rax
	movl	%edi, (%rax)
	movq	%rsi, 8(%rax)
	leaq	24(%rsp), %rcx
	movq	%rdx, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z4bake4DataP6Worker, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$112, %rsp
	.cfi_adjust_cfa_offset -112
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z19__device_stub__bake4DataP6Worker, .Lfunc_end0-_Z19__device_stub__bake4DataP6Worker
	.cfi_endproc
                                        # -- End function
	.globl	_Z11loadMinutesPc               # -- Begin function _Z11loadMinutesPc
	.type	_Z11loadMinutesPc,@function
_Z11loadMinutesPc:                      # @_Z11loadMinutesPc
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$160, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	xorl	%esi, %esi
	xorl	%eax, %eax
	callq	open
	movl	%eax, %ebp
	leaq	16(%rsp), %rbx
	movl	%eax, %edi
	movq	%rbx, %rsi
	callq	fstat
	movq	48(%rbx), %rbx
	leaq	8(%rsp), %r14
	movq	%r14, %rdi
	movq	%rbx, %rsi
	movl	$1, %edx
	callq	hipMallocManaged
	movq	(%r14), %rsi
	movl	%ebp, %edi
	movq	%rbx, %rdx
	callq	read
	testl	%eax, %eax
	jle	.LBB1_2
# %bb.1:
	movabsq	$-6148914691236517205, %rcx     # imm = 0xAAAAAAAAAAAAAAAB
	movq	%rbx, %rax
	mulq	%rcx
	movq	%rdx, %rax
	shrq	$5, %rax
	movq	8(%rsp), %rdx
                                        # kill: def $eax killed $eax killed $rax
	addq	$160, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB1_2:
	.cfi_def_cfa_offset 192
	movl	$.Lstr, %edi
	callq	puts@PLT
	xorl	%edi, %edi
	callq	exit
.Lfunc_end1:
	.size	_Z11loadMinutesPc, .Lfunc_end1-_Z11loadMinutesPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z11printMinuteP6Minute         # -- Begin function _Z11printMinuteP6Minute
	.type	_Z11printMinuteP6Minute,@function
_Z11printMinuteP6Minute:                # @_Z11printMinuteP6Minute
	.cfi_startproc
# %bb.0:
	movq	(%rdi), %rsi
	movsd	8(%rdi), %xmm0                  # xmm0 = mem[0],zero
	movsd	16(%rdi), %xmm1                 # xmm1 = mem[0],zero
	movsd	24(%rdi), %xmm2                 # xmm2 = mem[0],zero
	movsd	32(%rdi), %xmm3                 # xmm3 = mem[0],zero
	movsd	40(%rdi), %xmm4                 # xmm4 = mem[0],zero
	movl	$.L.str.1, %edi
	movb	$5, %al
	jmp	printf                          # TAILCALL
.Lfunc_end2:
	.size	_Z11printMinuteP6Minute, .Lfunc_end2-_Z11printMinuteP6Minute
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z10searchPike4Data
.LCPI3_0:
	.quad	0x3ff0666666666666              # double 1.0249999999999999
.LCPI3_1:
	.quad	0x3fef333333333333              # double 0.97499999999999997
	.text
	.globl	_Z10searchPike4Data
	.type	_Z10searchPike4Data,@function
_Z10searchPike4Data:                    # @_Z10searchPike4Data
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rsi, %rbx
	movl	%edi, %r15d
	xorl	%r14d, %r14d
	movl	$.L.str.2, %edi
	movl	%r15d, %esi
	xorl	%eax, %eax
	callq	printf
	cmpl	$81, %r15d
	jl	.LBB3_6
# %bb.1:                                # %.lr.ph.preheader
	addl	$-40, %r15d
	leaq	(%r15,%r15,2), %r15
	shlq	$4, %r15
	addq	$-1920, %r15                    # imm = 0xF880
	movsd	.LCPI3_0(%rip), %xmm1           # xmm1 = mem[0],zero
	xorl	%r12d, %r12d
.LBB3_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movsd	1928(%rbx,%r12), %xmm0          # xmm0 = mem[0],zero
	divsd	2888(%rbx,%r12), %xmm0
	ucomisd	%xmm1, %xmm0
	ja	.LBB3_4
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB3_2 Depth=1
	movsd	.LCPI3_1(%rip), %xmm2           # xmm2 = mem[0],zero
	ucomisd	%xmm0, %xmm2
	jbe	.LBB3_5
.LBB3_4:                                #   in Loop: Header=BB3_2 Depth=1
	movl	$.L.str.3, %edi
	movl	%r14d, %esi
	movb	$1, %al
	callq	printf
	movsd	.LCPI3_0(%rip), %xmm1           # xmm1 = mem[0],zero
	incl	%r14d
.LBB3_5:                                #   in Loop: Header=BB3_2 Depth=1
	addq	$48, %r12
	cmpq	%r12, %r15
	jne	.LBB3_2
.LBB3_6:                                # %._crit_edge
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z10searchPike4Data, .Lfunc_end3-_Z10searchPike4Data
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movabsq	$4294968320, %rbx               # imm = 0x100000400
	movl	$.L.str.4, %edi
	callq	_Z11loadMinutesPc
	movl	%eax, 4(%rsp)                   # 4-byte Spill
	movq	%rdx, 8(%rsp)                   # 8-byte Spill
	leaq	16(%rsp), %rdi
	movl	$536870912, %esi                # imm = 0x20000000
	callq	hipMalloc
	movq	%rbx, %rbp
	leaq	31744(%rbx), %r15
	xorl	%r14d, %r14d
	xorl	%ebx, %ebx
	xorl	%r12d, %r12d
.LBB4_1:                                # =>This Inner Loop Header: Depth=1
	movq	%r12, %rax
	movabsq	$-3689348814741910323, %rcx     # imm = 0xCCCCCCCCCCCCCCCD
	mulq	%rcx
	movq	%rdx, %r13
	movq	%r15, %rdi
	movl	$1, %esi
	movq	%rbp, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_3
# %bb.2:                                #   in Loop: Header=BB4_1 Depth=1
	movq	16(%rsp), %rdx
	movl	4(%rsp), %edi                   # 4-byte Reload
	movq	8(%rsp), %rsi                   # 8-byte Reload
	callq	_Z19__device_stub__bake4DataP6Worker
.LBB4_3:                                #   in Loop: Header=BB4_1 Depth=1
	callq	hipDeviceSynchronize
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB4_7
# %bb.4:                                #   in Loop: Header=BB4_1 Depth=1
	shrq	$3, %r13
	leaq	(,%r13,4), %rax
	addq	%r13, %rax
	leaq	(%r14,%rax,2), %rax
	testq	%rax, %rax
	jne	.LBB4_6
# %bb.5:                                #   in Loop: Header=BB4_1 Depth=1
	movq	%rbx, %rax
	shrq	$9, %rax
	movabsq	$19342813113834067, %rcx        # imm = 0x44B82FA09B5A53
	mulq	%rcx
	shrq	$11, %rdx
	movl	$.L.str.6, %edi
	movq	%r12, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB4_6:                                #   in Loop: Header=BB4_1 Depth=1
	incq	%r12
	addq	$33554432, %rbx                 # imm = 0x2000000
	decq	%r14
	jmp	.LBB4_1
.LBB4_7:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.5, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$-1, %edi
	callq	exit
.Lfunc_end4:
	.size	main, .Lfunc_end4-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z4bake4DataP6Worker, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB6_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z4bake4DataP6Worker,@object    # @_Z4bake4DataP6Worker
	.section	.rodata,"a",@progbits
	.globl	_Z4bake4DataP6Worker
	.p2align	3, 0x0
_Z4bake4DataP6Worker:
	.quad	_Z19__device_stub__bake4DataP6Worker
	.size	_Z4bake4DataP6Worker, 8

	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"%ld OPEN: %-10.5lf HIGH: %-10.5lf LOW: %-10.5lf CLOSE: %-10.5lf VOLUME: %-10.5lf\n"
	.size	.L.str.1, 82

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"%d\n"
	.size	.L.str.2, 4

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"%lf %d\n"
	.size	.L.str.3, 8

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"./data"
	.size	.L.str.4, 7

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"CUDA error: %s\n"
	.size	.L.str.5, 16

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"DONE %ld - %ld B\n"
	.size	.L.str.6, 18

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z4bake4DataP6Worker"
	.size	.L__unnamed_1, 21

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"ERROR LOAD FILE"
	.size	.Lstr, 16

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z19__device_stub__bake4DataP6Worker
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z4bake4DataP6Worker
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z4bake4DataP6Worker    ; -- Begin function _Z4bake4DataP6Worker
	.globl	_Z4bake4DataP6Worker
	.p2align	8
	.type	_Z4bake4DataP6Worker,@function
_Z4bake4DataP6Worker:                   ; @_Z4bake4DataP6Worker
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x24
	s_load_b64 s[0:1], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_mov_b32 s2, 0xc4ec4ec5
	v_lshl_add_u32 v0, v1, 2, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshrrev_b32_e32 v2, 31, v0
	v_add_nc_u32_e32 v0, v0, v2
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v0, 1, v0
	v_mad_u64_u32 v[3:4], null, v0, s2, 0xffffffff93b13b18
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[0:1], 4, v[1:2]
	s_mov_b32 s2, 0
	v_alignbit_b32 v4, v3, v3, 2
	v_mov_b32_e32 v3, s2
	s_delay_alu instid0(VALU_DEP_2)
	v_cmp_gt_u32_e32 vcc_lo, 0x4ec4ec5, v4
	v_cndmask_b32_e64 v2, 0, 1, vcc_lo
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	global_store_b64 v[0:1], v[2:3], off offset:8
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z4bake4DataP6Worker
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 5
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z4bake4DataP6Worker, .Lfunc_end0-_Z4bake4DataP6Worker
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 176
; NumSgprs: 18
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 5
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .offset:         0
        .size:           16
        .value_kind:     by_value
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z4bake4DataP6Worker
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z4bake4DataP6Worker.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
