//====================================================
// GPIO Control
//     main.cu : Main Routine
//----------------------------------------------------
// Rev.01 2019.06.08 M.Munetomo
//----------------------------------------------------
// Copyright (C) 2019 Munetomo Maruyama
//====================================================

#include <cinttypes>
#include <fcntl.h>
#include <poll.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

//----------------------------------
// Main Routine
//----------------------------------
int main(void)
{
	int fd, fd_poll;
	int byte;
	
	// Teach how to quit
	printf("Please Hit Enter to Quit.\n");
	
    // Export GPIO50 (11pin)
    fd = open("/sys/class/gpio/export", O_WRONLY);
    if (fd < 0) exit(EXIT_FAILURE);
    byte = write(fd, "50", 3);
    close(fd);

    // Set Direction of GPIO50 (11pin) as Input
    fd = open("/sys/class/gpio/gpio50/direction", O_WRONLY);
    if (fd < 0) exit(EXIT_FAILURE);
    byte = write(fd, "in", 3);
    close(fd);

    // Set Edge Detection of GPIO50 (11pin) as Both
    fd = open("/sys/class/gpio/gpio50/edge", O_WRONLY);
    if (fd < 0) exit(EXIT_FAILURE);
    byte = write(fd, "both", 5);
    close(fd);
    
    // Left Open Value of GPIO50 (11pin)
    fd_poll = open("/sys/class/gpio/gpio50/value", O_RDONLY | O_NONBLOCK);
    if (fd_poll < 0) exit(EXIT_FAILURE);

    // Export GPIO79 (12pin)
    fd = open("/sys/class/gpio/export", O_WRONLY);
    if (fd < 0) exit(EXIT_FAILURE);
    byte = write(fd, "79", 3);
    close(fd);

    // Set Direction of GPIO79 (12pin) as Output
    fd = open("/sys/class/gpio/gpio79/direction", O_WRONLY);
    if (fd < 0) exit(EXIT_FAILURE);
    byte = write(fd, "out", 4);
    close(fd);
    
    // Prepare Interrupt Polling
    struct pollfd fdset[2];
    int    nfds = 2;
    memset((void*)fdset, 0, sizeof(fdset));
    fdset[0].fd = STDIN_FILENO;
    fdset[0].events = POLLIN;
    fdset[1].fd = fd_poll;
    fdset[1].events = POLLPRI;

    // Forever Loop
    while(1)
    {
		char ch;
		
		// Wait for Interrupt
		int rc = poll(fdset, nfds, 3000); // polling with timeout 3sec
		if (rc < 0) exit(EXIT_FAILURE);
		// Timeout?
		if (rc == 0)
		{
			printf("Timeout\n");
			continue;
		}
		// Detected Stdin?
        if (fdset[0].revents & POLLIN)
        {
			byte = read(fdset[0].fd, &ch, 1);
			printf("poll() stdin read %c\n", ch);
			break;
		}
		// Detected GPIO50 Edge?
        if (fdset[1].revents & POLLPRI)
        {
            lseek(fdset[1].fd, 0, SEEK_SET);
			byte = read(fdset[1].fd, &ch, 1);
			printf("poll() GPIO50 Interrupt Detected, level=%c\n", ch);
			//
			// Toggle GPIO79 (12pin) 10times
            for (int i = 0; i < 10; i++)
            {
				// Open
                fd = open("/sys/class/gpio/gpio79/value", O_WRONLY);
                if (fd < 0) exit(EXIT_FAILURE);
		        // Set High
                byte = write(fd, "1", 2);
                // Wait
                usleep(1000);
		        // Set Low
                byte = write(fd, "0", 2);
                // Wait
                usleep(1000);
                // Close
                close(fd);
			}
		}
	}
    
    // Close File of Value of GPIO50 (11pin)
    close(fd_poll);

    // UnExport GPIO50 (11pin)
    fd = open("/sys/class/gpio/unexport", O_WRONLY);
    if (fd < 0) exit(EXIT_FAILURE);
    byte = write(fd, "50", 3);
    close(fd);

    // UnExport GPIO79 (12pin)
    fd = open("/sys/class/gpio/unexport", O_WRONLY);
    if (fd < 0) exit(EXIT_FAILURE);
    byte = write(fd, "79", 3);
    close(fd);

    // Return from this Program
    return(EXIT_SUCCESS);
}

//====================================================
// End of Program
//====================================================

	.file	"tmpxft_002c8dd8_00000000-6_main.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2049:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2049:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Please Hit Enter to Quit.\n"
.LC1:
	.string	"/sys/class/gpio/export"
.LC2:
	.string	"50"
.LC3:
	.string	"/sys/class/gpio/gpio50/direction"
.LC4:
	.string	"in"
.LC5:
	.string	"/sys/class/gpio/gpio50/edge"
.LC6:
	.string	"both"
.LC7:
	.string	"/sys/class/gpio/gpio50/value"
.LC8:
	.string	"79"
.LC9:
	.string	"/sys/class/gpio/gpio79/direction"
.LC10:
	.string	"out"
.LC11:
	.string	"Timeout\n"
.LC12:
	.string	"poll() stdin read %c\n"
.LC13:
	.string	"/sys/class/gpio/unexport"
.LC14:
	.string	"poll() GPIO50 Interrupt Detected, level=%c\n"
.LC15:
	.string	"/sys/class/gpio/gpio79/value"
.LC16:
	.string	"1"
.LC17:
	.string	"0"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2046:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leaq	.LC1(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %esi
	movq	%r12, %rdi
	call	__open_2@PLT
	testl	%eax, %eax
	jns	.L3
.L4:
	movl	$1, %edi
	call	exit@PLT
.L3:
	leaq	.LC2(%rip), %r13
	movl	%eax, %ebx
	movl	$3, %edx
	movl	%eax, %edi
	movq	%r13, %rsi
	call	write@PLT
	movl	%ebx, %edi
	call	close@PLT
	movl	$1, %esi
	leaq	.LC3(%rip), %rdi
	call	__open_2@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	js	.L4
	movl	$3, %edx
	leaq	.LC4(%rip), %rsi
	movl	%eax, %edi
	call	write@PLT
	movl	%ebx, %edi
	call	close@PLT
	movl	$1, %esi
	leaq	.LC5(%rip), %rdi
	call	__open_2@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	js	.L4
	movl	$5, %edx
	leaq	.LC6(%rip), %rsi
	movl	%eax, %edi
	call	write@PLT
	movl	%ebx, %edi
	call	close@PLT
	movl	$2048, %esi
	leaq	.LC7(%rip), %rdi
	call	__open_2@PLT
	movl	%eax, %ebp
	testl	%eax, %eax
	js	.L4
	movl	$1, %esi
	movq	%r12, %rdi
	call	__open_2@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	js	.L4
	movl	$3, %edx
	leaq	.LC8(%rip), %rsi
	movl	%eax, %edi
	call	write@PLT
	movl	%ebx, %edi
	call	close@PLT
	movl	$1, %esi
	leaq	.LC9(%rip), %rdi
	call	__open_2@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	js	.L4
	movl	$4, %edx
	leaq	.LC10(%rip), %rsi
	movl	%eax, %edi
	call	write@PLT
	movl	%ebx, %edi
	leaq	.LC14(%rip), %r14
	call	close@PLT
	xorps	%xmm0, %xmm0
	movups	%xmm0, 8(%rsp)
	movw	$1, 12(%rsp)
	movl	%ebp, 16(%rsp)
	movw	$2, 20(%rsp)
.L5:
	leaq	8(%rsp), %rdi
	movl	$16, %ecx
	movl	$3000, %edx
	movl	$2, %esi
	call	__poll_chk@PLT
	testl	%eax, %eax
	js	.L4
	jne	.L6
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L5
.L6:
	testb	$1, 14(%rsp)
	je	.L8
	movl	8(%rsp), %edi
	movl	$1, %ecx
	leaq	7(%rsp), %rsi
	movl	$1, %edx
	call	__read_chk@PLT
	movsbl	7(%rsp), %edx
	leaq	.LC12(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	%ebp, %edi
	leaq	.LC13(%rip), %rbp
	call	close@PLT
	movl	$1, %esi
	movq	%rbp, %rdi
	call	__open_2@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jns	.L17
	jmp	.L4
.L8:
	testb	$2, 22(%rsp)
	je	.L5
	movl	16(%rsp), %edi
	xorl	%edx, %edx
	xorl	%esi, %esi
	movl	$10, %r12d
	leaq	.LC15(%rip), %r15
	call	lseek@PLT
	movl	16(%rsp), %edi
	leaq	7(%rsp), %rsi
	movl	$1, %ecx
	movl	$1, %edx
	call	__read_chk@PLT
	movsbl	7(%rsp), %edx
	movq	%r14, %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
.L11:
	movl	$1, %esi
	movq	%r15, %rdi
	call	__open_2@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	js	.L4
	movl	$2, %edx
	leaq	.LC16(%rip), %rsi
	movl	%eax, %edi
	call	write@PLT
	movl	$1000, %edi
	call	usleep@PLT
	movl	$2, %edx
	leaq	.LC17(%rip), %rsi
	movl	%ebx, %edi
	call	write@PLT
	movl	$1000, %edi
	call	usleep@PLT
	movl	%ebx, %edi
	call	close@PLT
	decl	%r12d
	jne	.L11
	jmp	.L5
.L17:
	movl	$3, %edx
	movq	%r13, %rsi
	movl	%eax, %edi
	call	write@PLT
	movl	%ebx, %edi
	call	close@PLT
	movl	$1, %esi
	movq	%rbp, %rdi
	call	__open_2@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	js	.L4
	movl	%eax, %edi
	movl	$3, %edx
	leaq	.LC8(%rip), %rsi
	call	write@PLT
	movl	%ebx, %edi
	call	close@PLT
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.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
	ret
	.cfi_endproc
.LFE2046:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2072:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2072:
	.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
	.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:

//====================================================
// GPIO Control
//     main.cu : Main Routine
//----------------------------------------------------
// Rev.01 2019.06.08 M.Munetomo
//----------------------------------------------------
// Copyright (C) 2019 Munetomo Maruyama
//====================================================


#include <hip/hip_runtime.h>
#include <cinttypes>
#include <fcntl.h>
#include <poll.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

//----------------------------------
// Main Routine
//----------------------------------
int main(void)
{
	int fd, fd_poll;
	int byte;
	
	// Teach how to quit
	printf("Please Hit Enter to Quit.\n");
	
    // Export GPIO50 (11pin)
    fd = open("/sys/class/gpio/export", O_WRONLY);
    if (fd < 0) exit(EXIT_FAILURE);
    byte = write(fd, "50", 3);
    close(fd);

    // Set Direction of GPIO50 (11pin) as Input
    fd = open("/sys/class/gpio/gpio50/direction", O_WRONLY);
    if (fd < 0) exit(EXIT_FAILURE);
    byte = write(fd, "in", 3);
    close(fd);

    // Set Edge Detection of GPIO50 (11pin) as Both
    fd = open("/sys/class/gpio/gpio50/edge", O_WRONLY);
    if (fd < 0) exit(EXIT_FAILURE);
    byte = write(fd, "both", 5);
    close(fd);
    
    // Left Open Value of GPIO50 (11pin)
    fd_poll = open("/sys/class/gpio/gpio50/value", O_RDONLY | O_NONBLOCK);
    if (fd_poll < 0) exit(EXIT_FAILURE);

    // Export GPIO79 (12pin)
    fd = open("/sys/class/gpio/export", O_WRONLY);
    if (fd < 0) exit(EXIT_FAILURE);
    byte = write(fd, "79", 3);
    close(fd);

    // Set Direction of GPIO79 (12pin) as Output
    fd = open("/sys/class/gpio/gpio79/direction", O_WRONLY);
    if (fd < 0) exit(EXIT_FAILURE);
    byte = write(fd, "out", 4);
    close(fd);
    
    // Prepare Interrupt Polling
    struct pollfd fdset[2];
    int    nfds = 2;
    memset((void*)fdset, 0, sizeof(fdset));
    fdset[0].fd = STDIN_FILENO;
    fdset[0].events = POLLIN;
    fdset[1].fd = fd_poll;
    fdset[1].events = POLLPRI;

    // Forever Loop
    while(1)
    {
		char ch;
		
		// Wait for Interrupt
		int rc = poll(fdset, nfds, 3000); // polling with timeout 3sec
		if (rc < 0) exit(EXIT_FAILURE);
		// Timeout?
		if (rc == 0)
		{
			printf("Timeout\n");
			continue;
		}
		// Detected Stdin?
        if (fdset[0].revents & POLLIN)
        {
			byte = read(fdset[0].fd, &ch, 1);
			printf("poll() stdin read %c\n", ch);
			break;
		}
		// Detected GPIO50 Edge?
        if (fdset[1].revents & POLLPRI)
        {
            lseek(fdset[1].fd, 0, SEEK_SET);
			byte = read(fdset[1].fd, &ch, 1);
			printf("poll() GPIO50 Interrupt Detected, level=%c\n", ch);
			//
			// Toggle GPIO79 (12pin) 10times
            for (int i = 0; i < 10; i++)
            {
				// Open
                fd = open("/sys/class/gpio/gpio79/value", O_WRONLY);
                if (fd < 0) exit(EXIT_FAILURE);
		        // Set High
                byte = write(fd, "1", 2);
                // Wait
                usleep(1000);
		        // Set Low
                byte = write(fd, "0", 2);
                // Wait
                usleep(1000);
                // Close
                close(fd);
			}
		}
	}
    
    // Close File of Value of GPIO50 (11pin)
    close(fd_poll);

    // UnExport GPIO50 (11pin)
    fd = open("/sys/class/gpio/unexport", O_WRONLY);
    if (fd < 0) exit(EXIT_FAILURE);
    byte = write(fd, "50", 3);
    close(fd);

    // UnExport GPIO79 (12pin)
    fd = open("/sys/class/gpio/unexport", O_WRONLY);
    if (fd < 0) exit(EXIT_FAILURE);
    byte = write(fd, "79", 3);
    close(fd);

    // Return from this Program
    return(EXIT_SUCCESS);
}

//====================================================
// End of Program
//====================================================

	.text
	.file	"main.hip"
	.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	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$32, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$.L.str.1, %edi
	movl	$1, %esi
	xorl	%eax, %eax
	callq	open
	testl	%eax, %eax
	js	.LBB0_16
# %bb.1:
	movl	%eax, %ebx
	movl	$.L.str.2, %esi
	movl	$3, %edx
	movl	%eax, %edi
	callq	write
	movl	%ebx, %edi
	callq	close
	movl	$.L.str.3, %edi
	movl	$1, %esi
	xorl	%eax, %eax
	callq	open
	testl	%eax, %eax
	js	.LBB0_16
# %bb.2:
	movl	%eax, %ebx
	movl	$.L.str.4, %esi
	movl	$3, %edx
	movl	%eax, %edi
	callq	write
	movl	%ebx, %edi
	callq	close
	movl	$.L.str.5, %edi
	movl	$1, %esi
	xorl	%eax, %eax
	callq	open
	testl	%eax, %eax
	js	.LBB0_16
# %bb.3:
	movl	%eax, %ebx
	movl	$.L.str.6, %esi
	movl	$5, %edx
	movl	%eax, %edi
	callq	write
	movl	%ebx, %edi
	callq	close
	movl	$.L.str.7, %edi
	movl	$2048, %esi                     # imm = 0x800
	xorl	%eax, %eax
	callq	open
	testl	%eax, %eax
	js	.LBB0_16
# %bb.4:
	movl	%eax, %ebx
	movl	$.L.str.1, %edi
	movl	$1, %esi
	xorl	%eax, %eax
	callq	open
	testl	%eax, %eax
	js	.LBB0_16
# %bb.5:
	movl	%eax, %ebp
	movl	$.L.str.8, %esi
	movl	$3, %edx
	movl	%eax, %edi
	callq	write
	movl	%ebp, %edi
	callq	close
	movl	$.L.str.9, %edi
	movl	$1, %esi
	xorl	%eax, %eax
	callq	open
	testl	%eax, %eax
	js	.LBB0_16
# %bb.6:
	movl	%eax, %ebp
	movl	$.L.str.10, %esi
	movl	$4, %edx
	movl	%eax, %edi
	callq	write
	movl	%ebp, %edi
	callq	close
	xorps	%xmm0, %xmm0
	leaq	16(%rsp), %rdi
	movaps	%xmm0, (%rdi)
	movw	$1, 4(%rdi)
	movl	%ebx, 8(%rdi)
	movw	$2, 12(%rdi)
	movl	$2, %esi
	movl	$3000, %edx                     # imm = 0xBB8
	callq	poll
	testl	%eax, %eax
	js	.LBB0_16
# %bb.7:
	leaq	16(%rsp), %r14
	leaq	15(%rsp), %r15
.LBB0_8:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_13 Depth 2
	testl	%eax, %eax
	je	.LBB0_9
# %bb.10:                               #   in Loop: Header=BB0_8 Depth=1
	testb	$1, 22(%rsp)
	jne	.LBB0_17
# %bb.11:                               #   in Loop: Header=BB0_8 Depth=1
	testb	$2, 30(%rsp)
	je	.LBB0_15
# %bb.12:                               #   in Loop: Header=BB0_8 Depth=1
	movl	24(%rsp), %edi
	xorl	%esi, %esi
	xorl	%edx, %edx
	callq	lseek
	movl	24(%rsp), %edi
	movl	$1, %edx
	movq	%r15, %rsi
	callq	read
	movsbl	15(%rsp), %esi
	movl	$.L.str.13, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$10, %r12d
.LBB0_13:                               #   Parent Loop BB0_8 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	$.L.str.14, %edi
	movl	$1, %esi
	xorl	%eax, %eax
	callq	open
	testl	%eax, %eax
	js	.LBB0_16
# %bb.14:                               #   in Loop: Header=BB0_13 Depth=2
	movl	%eax, %ebp
	movl	$.L.str.15, %esi
	movl	$2, %edx
	movl	%eax, %edi
	callq	write
	movl	$1000, %edi                     # imm = 0x3E8
	callq	usleep
	movl	$.L.str.16, %esi
	movl	$2, %edx
	movl	%ebp, %edi
	callq	write
	movl	$1000, %edi                     # imm = 0x3E8
	callq	usleep
	movl	%ebp, %edi
	callq	close
	decl	%r12d
	jne	.LBB0_13
	jmp	.LBB0_15
.LBB0_9:                                #   in Loop: Header=BB0_8 Depth=1
	movl	$.Lstr.1, %edi
	callq	puts@PLT
.LBB0_15:                               # %.loopexit
                                        #   in Loop: Header=BB0_8 Depth=1
	movl	$2, %esi
	movq	%r14, %rdi
	movl	$3000, %edx                     # imm = 0xBB8
	callq	poll
	testl	%eax, %eax
	jns	.LBB0_8
.LBB0_16:
	movl	$1, %edi
	callq	exit
.LBB0_17:
	movl	16(%rsp), %edi
	leaq	15(%rsp), %r14
	movl	$1, %edx
	movq	%r14, %rsi
	callq	read
	movsbl	(%r14), %esi
	movl	$.L.str.12, %edi
	xorl	%eax, %eax
	callq	printf
	movl	%ebx, %edi
	callq	close
	movl	$.L.str.17, %edi
	movl	$1, %esi
	xorl	%eax, %eax
	callq	open
	testl	%eax, %eax
	js	.LBB0_16
# %bb.18:
	movl	%eax, %ebx
	movl	$.L.str.2, %esi
	movl	$3, %edx
	movl	%eax, %edi
	callq	write
	movl	%ebx, %edi
	callq	close
	movl	$.L.str.17, %edi
	movl	$1, %esi
	xorl	%eax, %eax
	callq	open
	testl	%eax, %eax
	js	.LBB0_16
# %bb.19:
	movl	%eax, %ebx
	movl	$.L.str.8, %esi
	movl	$3, %edx
	movl	%eax, %edi
	callq	write
	movl	%ebx, %edi
	callq	close
	xorl	%eax, %eax
	addq	$32, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"/sys/class/gpio/export"
	.size	.L.str.1, 23

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"50"
	.size	.L.str.2, 3

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"/sys/class/gpio/gpio50/direction"
	.size	.L.str.3, 33

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"in"
	.size	.L.str.4, 3

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"/sys/class/gpio/gpio50/edge"
	.size	.L.str.5, 28

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"both"
	.size	.L.str.6, 5

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"/sys/class/gpio/gpio50/value"
	.size	.L.str.7, 29

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"79"
	.size	.L.str.8, 3

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"/sys/class/gpio/gpio79/direction"
	.size	.L.str.9, 33

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"out"
	.size	.L.str.10, 4

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"poll() stdin read %c\n"
	.size	.L.str.12, 22

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"poll() GPIO50 Interrupt Detected, level=%c\n"
	.size	.L.str.13, 44

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"/sys/class/gpio/gpio79/value"
	.size	.L.str.14, 29

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"1"
	.size	.L.str.15, 2

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"0"
	.size	.L.str.16, 2

	.type	.L.str.17,@object               # @.str.17
.L.str.17:
	.asciz	"/sys/class/gpio/unexport"
	.size	.L.str.17, 25

	.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	"Please Hit Enter to Quit."
	.size	.Lstr, 26

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Timeout"
	.size	.Lstr.1, 8

	.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_

	.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_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
