<commit_before>.data
/* std._environment : byte[:][:] */
.globl _std$_environment
_std$_environment:
.envbase:
.quad 0 /* env size */
.envlen:
.quad 0 /* env ptr */

.globl _std$__cenvp
_std$__cenvp:
.quad 0

.text
/*
 * counts the length of the string pointed to
 * by %r8, returning len in %r9. Does not modify
 * any registers outside of %r9
 */
cstrlen:
	xorq	%r9,%r9
	jmp .lentest

	.lenloop:
	incq	%r9
	.lentest:
	cmpb	$0,(%r8,%r9)
	jne	.lenloop
	ret


/*
 * Counts the size of the null terminated string vector
 * pointed to by %rbx. Clobbers %r10,%r11
 */
count:
	xorq %r9,%r9
	movq %rbx,%r11
.countloop:
	movq (%r11),%r10
	testq %r10,%r10
	jz .countdone
	addq $1,%r9
	addq $8,%r11
	jmp .countloop
.countdone:
	ret

/*
 * iterate over the strings for argc, and put
 * them into the args array.
 * 
 * argc in %rax, argv in %rbx, dest vector in %rcx
 */
cvt:
        jmp .cvttest
.cvtloop:
	subq	$1,%rax
	movq	(%rbx),%r8
	call	cstrlen
	movq	%r8, (%rcx)
	movq	%r9, 8(%rcx)
	addq	$8, %rbx
	addq	$16, %rcx
.cvttest:
	testq	%rax,%rax
	jnz .cvtloop
.cvtdone:
        ret

.globl start
start:
	/* turn args into a slice */
	movq	%rsp,%rbp
	/* stack allocate sizeof(byte[:])*(argc + len(envp)) */
	movq	(%rbp),%rax
	leaq	16(%rbp,%rax,8), %rbx	/* argp = argv + 8*argc + 8 */
        call    count
	addq	%r9,%rax
	imulq	$16,%rax
	subq	%rax,%rsp
	movq	%rsp, %rdx	/* saved args[:] */

	/* convert envp to byte[:][:] for std._environment */
	movq	(%rbp),%rax
	leaq	16(%rbp,%rax,8), %rbx	/* envp = argv + 8*argc + 8 */
        movq    %rbx,_std$__cenvp(%rip)
	movq	%r9,%rax
	movq	%rsp, %rcx
	movq	%r9,.envlen(%rip)
	movq	%rdx,.envbase(%rip)
	call cvt
	movq	%rcx,%rdx

        /* convert argc, argv to byte[:][:] for args. */
	movq	(%rbp), %rax	/* argc */
	leaq	8(%rbp), %rbx	/* argv */
	movq	(%rbp), %rsi	/* saved argc */
        call cvt
	pushq %rsi
	pushq %rdx

	/* enter the main program */
	call	_main
	/* exit */
	xorq	%rdi,%rdi
	movq	$0x2000001,%rax
	syscall

<commit_msg>OSX start does the same thing. Add the same comment.<commit_after>.data
/* std._environment : byte[:][:] */
.globl _std$_environment
_std$_environment:
.envbase:
.quad 0 /* env size */
.envlen:
.quad 0 /* env ptr */

.globl _std$__cenvp
_std$__cenvp:
.quad 0

.text
/*
 * counts the length of the string pointed to
 * by %r8, returning len in %r9. Does not modify
 * any registers outside of %r9
 */
cstrlen:
	xorq	%r9,%r9
	jmp .lentest

	.lenloop:
	incq	%r9
	.lentest:
	cmpb	$0,(%r8,%r9)
	jne	.lenloop
	ret


/*
 * Counts the size of the null terminated string vector
 * pointed to by %rbx. Clobbers %r10,%r11
 */
count:
	xorq %r9,%r9
	movq %rbx,%r11
.countloop:
	movq (%r11),%r10
	testq %r10,%r10
	jz .countdone
	addq $1,%r9
	addq $8,%r11
	jmp .countloop
.countdone:
	ret

/*
 * iterate over the strings for argc, and put
 * them into the args array.
 * 
 * argc in %rax, argv in %rbx, dest vector in %rcx
 */
cvt:
        jmp .cvttest
.cvtloop:
	subq	$1,%rax
	movq	(%rbx),%r8
	call	cstrlen
	movq	%r8, (%rcx)
	movq	%r9, 8(%rcx)
	addq	$8, %rbx
	addq	$16, %rcx
.cvttest:
	testq	%rax,%rax
	jnz .cvtloop
.cvtdone:
        ret

/*
 * The entry point for the whole program.
 * This is called by the OS. In order, it:
 *  - Sets up all argc entries as slices
 *  - Sets up all envp entries as slices
 *  - Converts argc/argv to a slice
 *  - Stashes envp in std._environment
 *  - Stashes a raw envp copy in __cenvp (for syscalls to use)
 *  - Calls main()
 */
.globl start
start:
	/* turn args into a slice */
	movq	%rsp,%rbp
	/* stack allocate sizeof(byte[:])*(argc + len(envp)) */
	movq	(%rbp),%rax
	leaq	16(%rbp,%rax,8), %rbx	/* argp = argv + 8*argc + 8 */
        call    count
	addq	%r9,%rax
	imulq	$16,%rax
	subq	%rax,%rsp
	movq	%rsp, %rdx	/* saved args[:] */

	/* convert envp to byte[:][:] for std._environment */
	movq	(%rbp),%rax
	leaq	16(%rbp,%rax,8), %rbx	/* envp = argv + 8*argc + 8 */
        movq    %rbx,_std$__cenvp(%rip)
	movq	%r9,%rax
	movq	%rsp, %rcx
	movq	%r9,.envlen(%rip)
	movq	%rdx,.envbase(%rip)
	call cvt
	movq	%rcx,%rdx

        /* convert argc, argv to byte[:][:] for args. */
	movq	(%rbp), %rax	/* argc */
	leaq	8(%rbp), %rbx	/* argv */
	movq	(%rbp), %rsi	/* saved argc */
        call cvt
	pushq %rsi
	pushq %rdx

	/* enter the main program */
	call	_main
	/* exit */
	xorq	%rdi,%rdi
	movq	$0x2000001,%rax
	syscall


{'fraction_non_alphanumeric': 0.16318961520630507, 'fraction_numerical': 0.03013444598980065, 'mean_word_length': 2.883888388838884, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4848758', 'n_tokens_mistral': 2089, 'n_tokens_neox': 1942, 'n_words': 559}