/****************************************************************************
 *
 * cuda-rule30.cu - Rule30 Cellular Automaton with CUDA
 *
 * Written in 2017 by Moreno Marzolla <moreno.marzolla(at)unibo.it>
 *
 * To the extent possible under law, the author(s) have dedicated all 
 * copyright and related and neighboring rights to this software to the 
 * public domain worldwide. This software is distributed without any warranty.
 *
 * You should have received a copy of the CC0 Public Domain Dedication
 * along with this software. If not, see 
 * <http://creativecommons.org/publicdomain/zero/1.0/>. 
 *
 * --------------------------------------------------------------------------
 *
 * This program implements the "rule 30 CA" as described in
 * https://en.wikipedia.org/wiki/Rule_30 . This program uses the CPU
 * only.
 *
 * Compile with:
 * nvcc cuda-rule30.cu -o cuda-rule30
 *
 * Run with:
 * /cuda-rule30 1024 1024
 *
 ****************************************************************************/
#include <stdio.h>
#include <stdlib.h>

typedef unsigned char cell_t;

/**
 * Given the current state of the CA, compute the next state.
 */
void rule30( cell_t *cur, cell_t *next, int n )
{
    int i;
    for (i=0; i<n; i++) {
        const cell_t left   = cur[(i-1+n)%n];
        const cell_t center = cur[i        ];
        const cell_t right  = cur[(i+1)%n  ];
        next[i] =                               \
            ( left && !center && !right) ||
            (!left && !center &&  right) ||
            (!left &&  center && !right) ||
            (!left &&  center &&  right);
    }
}

/**
 * Initialize the domain; all cells are 0, with the exception of a
 * single cell in the middle of the domain.
 */
void init_domain( cell_t *cur, int n )
{
    int i;
    for (i=0; i<n; i++) {
        cur[i] = 0;
    }
    cur[n/2] = 1;
}

/**
 * Dump the current state of the CA to PBM file |out|.
 */
void dump_state( FILE *out, cell_t *cur, int n )
{
    int i;
    for (i=0; i<n; i++) {
        fprintf(out, "%d ", cur[i]);
    }
    fprintf(out, "\n");
}

int main( int argc, char* argv[] )
{
    const char *outname = "rule30.pbm";
    FILE *out;
    cell_t *cur, *next, *tmp;
    int width = 1024, steps = 1024, s;    
    
    if ( argc > 3 ) {
        fprintf(stderr, "Usage: %s [width [steps]]\n", argv[0]);
        return -1;
    }

    if ( argc > 1 ) {
        width = atoi(argv[1]);
    }

    if ( argc > 2 ) {
        steps = atoi(argv[2]);
    }

    const size_t size = width * sizeof(cell_t);

    /* Allocate space for host copy the cur[] and next[] vectors */
    cur = (cell_t*)malloc(size);    
    next = (cell_t*)malloc(size);

    /* Create the output file */
    out = fopen(outname, "w");
    if ( !out ) {
        fprintf(stderr, "Cannot create %s\n", outname);
        return -1;
    }
    fprintf(out, "P1\n");
    fprintf(out, "# produced by %s %d %d\n", argv[0], width, steps);
    fprintf(out, "%d %d\n", width, steps);
    
    /* Initialize the domain */
    init_domain(cur, width);
    
    /* Evolve the CA */
    for (s=0; s<steps; s++) {
        
        /* Dump the current state to the output image */
        dump_state(out, cur, width);

        /* Compute next state */
        rule30(cur, next, width);

        /* swap cur and next on the GPU */
        tmp = cur;
        cur = next;
        next = tmp;
    }
    
    fclose(out);
    free(cur);
    free(next);
    return 0;
}

	.file	"tmpxft_0037a2c7_00000000-6_cuda-rule30.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2033:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2033:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z6rule30PhS_i
	.type	_Z6rule30PhS_i, @function
_Z6rule30PhS_i:
.LFB2027:
	.cfi_startproc
	endbr64
	movq	%rsi, %r8
	xorl	%esi, %esi
	leal	-1(%rdx), %r11d
	movl	%edx, %ecx
	cmpl	%esi, %edx
	jg	.L13
	ret
.L13:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
.L7:
	leal	(%r11,%rsi), %eax
	movb	(%rdi,%rsi), %r9b
	cltd
	idivl	%ecx
	leal	1(%rsi), %eax
	movslq	%edx, %rdx
	movb	(%rdi,%rdx), %r10b
	cltd
	idivl	%ecx
	testb	%r10b, %r10b
	setne	%al
	testb	%r9b, %r9b
	sete	%bl
	movslq	%edx, %rdx
	movb	(%rdi,%rdx), %dl
	andb	%bl, %al
	je	.L4
	testb	%dl, %dl
	je	.L5
	jmp	.L6
.L4:
	movl	%r10d, %eax
	orb	%r9b, %al
	sete	%al
	testb	%dl, %dl
	setne	%dl
	andb	%dl, %al
	jne	.L5
.L6:
	testb	%r10b, %r10b
	sete	%al
	testb	%r9b, %r9b
	setne	%dl
	andl	%edx, %eax
.L5:
	movb	%al, (%r8,%rsi)
	incq	%rsi
	cmpl	%esi, %ecx
	jg	.L7
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z6rule30PhS_i, .-_Z6rule30PhS_i
	.globl	_Z11init_domainPhi
	.type	_Z11init_domainPhi, @function
_Z11init_domainPhi:
.LFB2028:
	.cfi_startproc
	endbr64
	movl	%esi, %eax
	xorl	%edx, %edx
.L16:
	cmpl	%edx, %eax
	jle	.L18
	movb	$0, (%rdi,%rdx)
	incq	%rdx
	jmp	.L16
.L18:
	movl	$2, %ecx
	cltd
	idivl	%ecx
	cltq
	movb	$1, (%rdi,%rax)
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z11init_domainPhi, .-_Z11init_domainPhi
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d "
.LC1:
	.string	"\n"
	.text
	.globl	_Z10dump_stateP8_IO_FILEPhi
	.type	_Z10dump_stateP8_IO_FILEPhi, @function
_Z10dump_stateP8_IO_FILEPhi:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	.LC0(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movq	%rsi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	xorl	%ebp, %ebp
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
.L20:
	cmpl	%ebp, %r12d
	jle	.L23
	movzbl	0(%r13,%rbp), %ecx
	movq	%r14, %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	movq	%rdi, 8(%rsp)
	incq	%rbp
	call	__fprintf_chk@PLT
	movq	8(%rsp), %rdi
	jmp	.L20
.L23:
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	leaq	.LC1(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	__fprintf_chk@PLT
	.cfi_endproc
.LFE2029:
	.size	_Z10dump_stateP8_IO_FILEPhi, .-_Z10dump_stateP8_IO_FILEPhi
	.section	.rodata.str1.1
.LC2:
	.string	"Usage: %s [width [steps]]\n"
.LC3:
	.string	"w"
.LC4:
	.string	"rule30.pbm"
.LC5:
	.string	"Cannot create %s\n"
.LC6:
	.string	"P1\n"
.LC7:
	.string	"# produced by %s %d %d\n"
.LC8:
	.string	"%d %d\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rsi, %r15
	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
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	pushq	%rcx
	.cfi_def_cfa_offset 64
	cmpl	$3, %edi
	jle	.L25
	movq	(%rsi), %rcx
	leaq	.LC2(%rip), %rdx
	jmp	.L35
.L25:
	movl	%edi, %ebp
	cmpl	$1, %edi
	jle	.L32
	movq	8(%rsi), %rdi
	movl	$1024, %r13d
	call	atoi@PLT
	movl	%eax, %ebx
	cmpl	$3, %ebp
	jne	.L27
	movq	16(%r15), %rdi
	call	atoi@PLT
	movl	%eax, %r13d
	jmp	.L27
.L32:
	movl	$1024, %ebx
	movl	$1024, %r13d
.L27:
	movslq	%ebx, %r12
	movq	%r12, %rdi
	call	malloc@PLT
	movq	%r12, %rdi
	movq	%rax, %rbp
	call	malloc@PLT
	leaq	.LC4(%rip), %rcx
	leaq	.LC3(%rip), %rsi
	movq	%rcx, %rdi
	movq	%rax, %r14
	call	fopen@PLT
	leaq	.LC4(%rip), %rcx
	testq	%rax, %rax
	movq	%rax, %r12
	jne	.L28
	leaq	.LC5(%rip), %rdx
.L35:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	orl	$-1, %eax
	jmp	.L24
.L28:
	movq	%rax, %rdi
	leaq	.LC6(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	(%r15), %rcx
	movl	%r13d, %r9d
	movl	%ebx, %r8d
	leaq	.LC7(%rip), %rdx
	movq	%r12, %rdi
	xorl	%eax, %eax
	xorl	%r15d, %r15d
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	%ebx, %ecx
	leaq	.LC8(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	movq	%r12, %rdi
	movl	%r13d, %r8d
	call	__fprintf_chk@PLT
	movl	%ebx, %esi
	movq	%rbp, %rdi
	call	_Z11init_domainPhi
.L30:
	cmpl	%r15d, %r13d
	jle	.L36
	movq	%rbp, %rsi
	movl	%ebx, %edx
	movq	%r12, %rdi
	incl	%r15d
	call	_Z10dump_stateP8_IO_FILEPhi
	movq	%r14, %rsi
	movq	%rbp, %rdi
	movl	%ebx, %edx
	call	_Z6rule30PhS_i
	xchgq	%r14, %rbp
	jmp	.L30
.L36:
	movq	%r12, %rdi
	call	fclose@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%r14, %rdi
	call	free@PLT
	xorl	%eax, %eax
.L24:
	popq	%rdx
	.cfi_def_cfa_offset 56
	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
.LFE2030:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2056:
	.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
.LFE2056:
	.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:

/****************************************************************************
 *
 * cuda-rule30.cu - Rule30 Cellular Automaton with CUDA
 *
 * Written in 2017 by Moreno Marzolla <moreno.marzolla(at)unibo.it>
 *
 * To the extent possible under law, the author(s) have dedicated all 
 * copyright and related and neighboring rights to this software to the 
 * public domain worldwide. This software is distributed without any warranty.
 *
 * You should have received a copy of the CC0 Public Domain Dedication
 * along with this software. If not, see 
 * <http://creativecommons.org/publicdomain/zero/1.0/>. 
 *
 * --------------------------------------------------------------------------
 *
 * This program implements the "rule 30 CA" as described in
 * https://en.wikipedia.org/wiki/Rule_30 . This program uses the CPU
 * only.
 *
 * Compile with:
 * nvcc cuda-rule30.cu -o cuda-rule30
 *
 * Run with:
 * /cuda-rule30 1024 1024
 *
 ****************************************************************************/

#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>

typedef unsigned char cell_t;

/**
 * Given the current state of the CA, compute the next state.
 */
void rule30( cell_t *cur, cell_t *next, int n )
{
    int i;
    for (i=0; i<n; i++) {
        const cell_t left   = cur[(i-1+n)%n];
        const cell_t center = cur[i        ];
        const cell_t right  = cur[(i+1)%n  ];
        next[i] =                               \
            ( left && !center && !right) ||
            (!left && !center &&  right) ||
            (!left &&  center && !right) ||
            (!left &&  center &&  right);
    }
}

/**
 * Initialize the domain; all cells are 0, with the exception of a
 * single cell in the middle of the domain.
 */
void init_domain( cell_t *cur, int n )
{
    int i;
    for (i=0; i<n; i++) {
        cur[i] = 0;
    }
    cur[n/2] = 1;
}

/**
 * Dump the current state of the CA to PBM file |out|.
 */
void dump_state( FILE *out, cell_t *cur, int n )
{
    int i;
    for (i=0; i<n; i++) {
        fprintf(out, "%d ", cur[i]);
    }
    fprintf(out, "\n");
}

int main( int argc, char* argv[] )
{
    const char *outname = "rule30.pbm";
    FILE *out;
    cell_t *cur, *next, *tmp;
    int width = 1024, steps = 1024, s;    
    
    if ( argc > 3 ) {
        fprintf(stderr, "Usage: %s [width [steps]]\n", argv[0]);
        return -1;
    }

    if ( argc > 1 ) {
        width = atoi(argv[1]);
    }

    if ( argc > 2 ) {
        steps = atoi(argv[2]);
    }

    const size_t size = width * sizeof(cell_t);

    /* Allocate space for host copy the cur[] and next[] vectors */
    cur = (cell_t*)malloc(size);    
    next = (cell_t*)malloc(size);

    /* Create the output file */
    out = fopen(outname, "w");
    if ( !out ) {
        fprintf(stderr, "Cannot create %s\n", outname);
        return -1;
    }
    fprintf(out, "P1\n");
    fprintf(out, "# produced by %s %d %d\n", argv[0], width, steps);
    fprintf(out, "%d %d\n", width, steps);
    
    /* Initialize the domain */
    init_domain(cur, width);
    
    /* Evolve the CA */
    for (s=0; s<steps; s++) {
        
        /* Dump the current state to the output image */
        dump_state(out, cur, width);

        /* Compute next state */
        rule30(cur, next, width);

        /* swap cur and next on the GPU */
        tmp = cur;
        cur = next;
        next = tmp;
    }
    
    fclose(out);
    free(cur);
    free(next);
    return 0;
}

	.text
	.file	"cuda-rule30.hip"
	.globl	_Z6rule30PhS_i                  # -- Begin function _Z6rule30PhS_i
	.type	_Z6rule30PhS_i,@function
_Z6rule30PhS_i:                         # @_Z6rule30PhS_i
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jle	.LBB0_8
# %bb.1:                                # %.lr.ph
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset %rbx, -24
	.cfi_offset %rbp, -16
	movl	%edx, %ecx
	movq	%rcx, %r8
	negq	%r8
	movl	$1, %r9d
	xorl	%r10d, %r10d
.LBB0_2:                                # =>This Inner Loop Header: Depth=1
	leal	(%rcx,%r9), %eax
	addl	$-2, %eax
	cltd
	idivl	%ecx
	movslq	%edx, %rax
	movb	(%rdi,%rax), %al
	movb	-1(%rdi,%r9), %dl
	cmpq	%r9, %rcx
	movq	%r9, %r11
	cmoveq	%r10, %r11
	movb	(%rdi,%r11), %bl
	testb	%al, %al
	je	.LBB0_5
# %bb.3:                                #   in Loop: Header=BB0_2 Depth=1
	testb	%dl, %dl
	jne	.LBB0_5
# %bb.4:                                #   in Loop: Header=BB0_2 Depth=1
	movb	$1, %r11b
	testb	%bl, %bl
	je	.LBB0_6
.LBB0_5:                                #   in Loop: Header=BB0_2 Depth=1
	testb	%bl, %bl
	setne	%bl
	testb	%dl, %dl
	setne	%bpl
	testb	%al, %al
	sete	%r11b
	orb	%dl, %al
	sete	%al
	andb	%bl, %al
	andb	%bpl, %r11b
	orb	%al, %r11b
.LBB0_6:                                #   in Loop: Header=BB0_2 Depth=1
	movb	%r11b, -1(%rsi,%r9)
	leaq	(%r8,%r9), %rax
	incq	%rax
	incq	%r9
	cmpq	$1, %rax
	jne	.LBB0_2
# %bb.7:
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %rbp
.LBB0_8:                                # %._crit_edge
	retq
.Lfunc_end0:
	.size	_Z6rule30PhS_i, .Lfunc_end0-_Z6rule30PhS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z11init_domainPhi              # -- Begin function _Z11init_domainPhi
	.type	_Z11init_domainPhi,@function
_Z11init_domainPhi:                     # @_Z11init_domainPhi
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %rbp, -16
	movl	%esi, %ebp
	movq	%rdi, %rbx
	testl	%esi, %esi
	jle	.LBB1_2
# %bb.1:                                # %.lr.ph.preheader
	movl	%ebp, %edx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
.LBB1_2:                                # %._crit_edge
	movl	%ebp, %eax
	shrl	$31, %eax
	addl	%ebp, %eax
	sarl	%eax
	cltq
	movb	$1, (%rbx,%rax)
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z11init_domainPhi, .Lfunc_end1-_Z11init_domainPhi
	.cfi_endproc
                                        # -- End function
	.globl	_Z10dump_stateP8_IO_FILEPhi     # -- Begin function _Z10dump_stateP8_IO_FILEPhi
	.type	_Z10dump_stateP8_IO_FILEPhi,@function
_Z10dump_stateP8_IO_FILEPhi:            # @_Z10dump_stateP8_IO_FILEPhi
	.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	%rdi, %rbx
	testl	%edx, %edx
	jle	.LBB2_3
# %bb.1:                                # %.lr.ph.preheader
	movq	%rsi, %r14
	movl	%edx, %r15d
	xorl	%r12d, %r12d
.LBB2_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movzbl	(%r14,%r12), %edx
	movl	$.L.str, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	fprintf
	incq	%r12
	cmpq	%r12, %r15
	jne	.LBB2_2
.LBB2_3:                                # %._crit_edge
	movl	$10, %edi
	movq	%rbx, %rsi
	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
	jmp	fputc@PLT                       # TAILCALL
.Lfunc_end2:
	.size	_Z10dump_stateP8_IO_FILEPhi, .Lfunc_end2-_Z10dump_stateP8_IO_FILEPhi
	.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
	pushq	%rax
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %r13
	cmpl	$4, %edi
	jge	.LBB3_1
# %bb.2:
	movl	%edi, %r14d
	movl	$1024, %ebx                     # imm = 0x400
	cmpl	$2, %edi
	jl	.LBB3_3
# %bb.4:
	movq	8(%r13), %rdi
	callq	atoi
	movl	%eax, %ebp
	cmpl	$3, %r14d
	jne	.LBB3_6
# %bb.5:
	movq	16(%r13), %rdi
	callq	atoi
	movl	%eax, %ebx
	jmp	.LBB3_6
.LBB3_3:
	movl	$1024, %ebp                     # imm = 0x400
.LBB3_6:                                # %.thread
	movslq	%ebp, %r14
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, %r12
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, %r14
	movl	$.L.str.2, %edi
	movl	$.L.str.4, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB3_7
# %bb.9:
	movq	%rax, %r15
	movl	$.L.str.6, %edi
	movl	$3, %esi
	movl	$1, %edx
	movq	%rax, %rcx
	callq	fwrite@PLT
	movq	(%r13), %rdx
	movl	$.L.str.7, %esi
	movq	%r15, %rdi
	movl	%ebp, %ecx
	movl	%ebx, %r8d
	xorl	%eax, %eax
	callq	fprintf
	movl	$.L.str.8, %esi
	movq	%r15, %rdi
	movl	%ebp, %edx
	movl	%ebx, %ecx
	xorl	%eax, %eax
	callq	fprintf
	testl	%ebp, %ebp
	jle	.LBB3_11
# %bb.10:                               # %.lr.ph.preheader.i
	movl	%ebp, %edx
	movq	%r12, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
.LBB3_11:                               # %_Z11init_domainPhi.exit
	movl	%ebp, %eax
	shrl	$31, %eax
	addl	%ebp, %eax
	sarl	%eax
	cltq
	movb	$1, (%r12,%rax)
	testl	%ebx, %ebx
	jle	.LBB3_12
.LBB3_13:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	%r14, %r13
	movq	%r12, %r14
	movq	%r15, %rdi
	movq	%r12, %rsi
	movl	%ebp, %edx
	callq	_Z10dump_stateP8_IO_FILEPhi
	movq	%r12, %rdi
	movq	%r13, %rsi
	movl	%ebp, %edx
	callq	_Z6rule30PhS_i
	movq	%r13, %r12
	decl	%ebx
	jne	.LBB3_13
	jmp	.LBB3_14
.LBB3_12:
	movq	%r12, %r13
.LBB3_14:                               # %._crit_edge
	movq	%r15, %rdi
	callq	fclose
	movq	%r13, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	xorl	%eax, %eax
.LBB3_15:
	addq	$8, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.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
.LBB3_1:
	.cfi_def_cfa_offset 64
	movq	stderr(%rip), %rdi
	movq	(%r13), %rdx
	movl	$.L.str.3, %esi
	jmp	.LBB3_8
.LBB3_7:
	movq	stderr(%rip), %rdi
	movl	$.L.str.5, %esi
	movl	$.L.str.2, %edx
.LBB3_8:
	xorl	%eax, %eax
	callq	fprintf
	movl	$-1, %eax
	jmp	.LBB3_15
.Lfunc_end3:
	.size	main, .Lfunc_end3-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%d "
	.size	.L.str, 4

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"rule30.pbm"
	.size	.L.str.2, 11

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Usage: %s [width [steps]]\n"
	.size	.L.str.3, 27

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"w"
	.size	.L.str.4, 2

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Cannot create %s\n"
	.size	.L.str.5, 18

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"P1\n"
	.size	.L.str.6, 4

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"# produced by %s %d %d\n"
	.size	.L.str.7, 24

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

	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.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_

	.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
