Created
December 29, 2015 10:40
-
-
Save Marthog/3543c09bbaae6c4a9a48 to your computer and use it in GitHub Desktop.
Original Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <stdint.h> | |
#include <string.h> | |
struct Program { | |
uint32_t pos; | |
uint32_t* tape; | |
char* code; | |
size_t codelen; | |
uint32_t* bracket_map; | |
}; | |
void init_prog(struct Program* program, char* code, size_t len) { | |
char* prog_code = malloc(len); | |
// allocate stack for the right opening bracket | |
uint32_t* leftstack = malloc(len*sizeof(uint32_t)); | |
uint32_t codecounter = 0; | |
uint32_t leftstackcounter = 0; | |
size_t pc = 0; | |
uint32_t* bracket_map = malloc(len*sizeof(uint32_t)); | |
memset(bracket_map, 0, len*sizeof(uint32_t)); | |
for (char *p=code; *p; ++p) { | |
char x; | |
switch (*p) { | |
case '+': | |
x = 0; | |
break; | |
case '-': | |
x = 1; | |
break; | |
case '<': | |
x = 2; | |
break; | |
case '>': | |
x = 3; | |
break; | |
case '.': | |
x = 6; | |
break; | |
case ',': | |
x = 7; | |
break; | |
case '[': | |
leftstack[leftstackcounter++] = pc; | |
x = 4; | |
break; | |
case ']': | |
if (leftstackcounter>0) { | |
uint32_t left = leftstack[--leftstackcounter]; | |
bracket_map[left] = pc; | |
bracket_map[pc] = left; | |
} | |
x = 5; | |
break; | |
// ignore char | |
default: | |
continue; | |
} | |
prog_code[pc++] = x; | |
} | |
free(leftstack); | |
program->pos = 0; | |
size_t prog_bytes = 100000*sizeof(uint32_t); | |
program->tape = malloc(prog_bytes); | |
memset(program->tape, 0, prog_bytes); | |
program->code = prog_code; | |
program->bracket_map = bracket_map; | |
program->codelen = pc+1; | |
} | |
void run(struct Program* prog) { | |
uint32_t pc = 0; | |
while (pc<prog->codelen) { | |
//fprintf(stderr, "%d %c\n", pc, prog->code[pc]); | |
switch (prog->code[pc]) { | |
case 0: | |
prog->tape[prog->pos]++; | |
break; | |
case 1: | |
prog->tape[prog->pos]--; | |
break; | |
case 2: | |
prog->pos--; | |
break; | |
case 3: | |
prog->pos++; | |
break; | |
case 4: | |
if (!prog->tape[prog->pos]) { pc = prog->bracket_map[pc]; } | |
break; | |
case 5: | |
if (prog->tape[prog->pos]) { pc = prog->bracket_map[pc]; } | |
break; | |
case 6: | |
//fputc(prog->tape[prog->pos], stdout); | |
//fflush(stdout); | |
break; | |
// ignore reads | |
default: | |
// uncommenting this reduces performance | |
//__builtin_unreachable(); | |
break; | |
} | |
pc++; | |
} | |
} | |
int main(int argc, char** argv) { | |
FILE* file = fopen(argv[1], "r"); | |
fseek(file,0,SEEK_END); | |
uint32_t size = ftell(file); | |
rewind(file); | |
char* code = malloc(size+1); | |
fread(code, size, 1, file); | |
fclose(file); | |
code[size] = 0; | |
struct Program prog; | |
init_prog(&prog, code, size); | |
free(code); | |
run(&prog); | |
// ignore memory release | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.text | |
.file "brainfuck-optimized.c" | |
.globl init_prog | |
.align 16, 0x90 | |
.type init_prog,@function | |
init_prog: # @init_prog | |
.cfi_startproc | |
# BB#0: | |
pushq %rbp | |
.Ltmp0: | |
.cfi_def_cfa_offset 16 | |
pushq %r15 | |
.Ltmp1: | |
.cfi_def_cfa_offset 24 | |
pushq %r14 | |
.Ltmp2: | |
.cfi_def_cfa_offset 32 | |
pushq %r13 | |
.Ltmp3: | |
.cfi_def_cfa_offset 40 | |
pushq %r12 | |
.Ltmp4: | |
.cfi_def_cfa_offset 48 | |
pushq %rbx | |
.Ltmp5: | |
.cfi_def_cfa_offset 56 | |
pushq %rax | |
.Ltmp6: | |
.cfi_def_cfa_offset 64 | |
.Ltmp7: | |
.cfi_offset %rbx, -56 | |
.Ltmp8: | |
.cfi_offset %r12, -48 | |
.Ltmp9: | |
.cfi_offset %r13, -40 | |
.Ltmp10: | |
.cfi_offset %r14, -32 | |
.Ltmp11: | |
.cfi_offset %r15, -24 | |
.Ltmp12: | |
.cfi_offset %rbp, -16 | |
movq %rdx, %rbp | |
movq %rsi, %rbx | |
movq %rdi, %r14 | |
movq %rbp, %rdi | |
callq malloc | |
movq %rax, %r12 | |
shlq $2, %rbp | |
movq %rbp, %rdi | |
callq malloc | |
movq %rax, %r13 | |
movq %rbp, %rdi | |
callq malloc | |
movq %rax, (%rsp) # 8-byte Spill | |
xorl %r15d, %r15d | |
xorl %esi, %esi | |
movq %rax, %rdi | |
movq %rbp, %rdx | |
callq memset | |
movb (%rbx), %al | |
testb %al, %al | |
movl $0, %ebp | |
je .LBB0_21 | |
# BB#1: # %.lr.ph.preheader | |
incq %rbx | |
xorl %ebp, %ebp | |
.align 16, 0x90 | |
.LBB0_2: # %.lr.ph | |
# =>This Inner Loop Header: Depth=1 | |
movsbl %al, %ecx | |
cmpl $59, %ecx | |
jg .LBB0_5 | |
# BB#3: # %.lr.ph | |
# in Loop: Header=BB0_2 Depth=1 | |
addl $-43, %ecx | |
cmpl $3, %ecx | |
ja .LBB0_20 | |
# BB#4: # %.lr.ph | |
# in Loop: Header=BB0_2 Depth=1 | |
xorl %eax, %eax | |
jmpq *.LJTI0_0(,%rcx,8) | |
.LBB0_16: # in Loop: Header=BB0_2 Depth=1 | |
movb $7, %al | |
jmp .LBB0_19 | |
.align 16, 0x90 | |
.LBB0_5: # %.lr.ph | |
# in Loop: Header=BB0_2 Depth=1 | |
cmpl $90, %ecx | |
jg .LBB0_9 | |
# BB#6: # %.lr.ph | |
# in Loop: Header=BB0_2 Depth=1 | |
cmpl $60, %ecx | |
jne .LBB0_7 | |
# BB#14: # in Loop: Header=BB0_2 Depth=1 | |
movb $2, %al | |
jmp .LBB0_19 | |
.align 16, 0x90 | |
.LBB0_9: # %.lr.ph | |
# in Loop: Header=BB0_2 Depth=1 | |
cmpl $91, %ecx | |
jne .LBB0_10 | |
# BB#17: # in Loop: Header=BB0_2 Depth=1 | |
movl %r15d, %eax | |
incl %r15d | |
movl %ebp, (%r13,%rax,4) | |
movb $4, %al | |
jmp .LBB0_19 | |
.LBB0_7: # %.lr.ph | |
# in Loop: Header=BB0_2 Depth=1 | |
cmpl $62, %ecx | |
jne .LBB0_20 | |
# BB#8: # in Loop: Header=BB0_2 Depth=1 | |
movb $3, %al | |
jmp .LBB0_19 | |
.LBB0_10: # %.lr.ph | |
# in Loop: Header=BB0_2 Depth=1 | |
cmpl $93, %ecx | |
jne .LBB0_20 | |
# BB#11: # in Loop: Header=BB0_2 Depth=1 | |
movb $5, %al | |
testl %r15d, %r15d | |
je .LBB0_12 | |
# BB#18: # in Loop: Header=BB0_2 Depth=1 | |
decl %r15d | |
movl (%r13,%r15,4), %ecx | |
movq (%rsp), %rdx # 8-byte Reload | |
movl %ebp, (%rdx,%rcx,4) | |
movl %ecx, (%rdx,%rbp,4) | |
jmp .LBB0_19 | |
.LBB0_13: # in Loop: Header=BB0_2 Depth=1 | |
movb $1, %al | |
jmp .LBB0_19 | |
.LBB0_15: # in Loop: Header=BB0_2 Depth=1 | |
movb $6, %al | |
jmp .LBB0_19 | |
.LBB0_12: # in Loop: Header=BB0_2 Depth=1 | |
xorl %r15d, %r15d | |
.align 16, 0x90 | |
.LBB0_19: # in Loop: Header=BB0_2 Depth=1 | |
movb %al, (%r12,%rbp) | |
incq %rbp | |
.LBB0_20: # in Loop: Header=BB0_2 Depth=1 | |
movb (%rbx), %al | |
incq %rbx | |
testb %al, %al | |
jne .LBB0_2 | |
.LBB0_21: # %._crit_edge | |
movq %r13, %rdi | |
callq free | |
movl $0, (%r14) | |
movl $400000, %edi # imm = 0x61A80 | |
callq malloc | |
movq %rax, 8(%r14) | |
xorl %esi, %esi | |
movl $400000, %edx # imm = 0x61A80 | |
movq %rax, %rdi | |
callq memset | |
movq %r12, 16(%r14) | |
movq (%rsp), %rax # 8-byte Reload | |
movq %rax, 32(%r14) | |
incq %rbp | |
movq %rbp, 24(%r14) | |
addq $8, %rsp | |
popq %rbx | |
popq %r12 | |
popq %r13 | |
popq %r14 | |
popq %r15 | |
popq %rbp | |
retq | |
.Lfunc_end0: | |
.size init_prog, .Lfunc_end0-init_prog | |
.cfi_endproc | |
.section .rodata,"a",@progbits | |
.align 8 | |
.LJTI0_0: | |
.quad .LBB0_19 | |
.quad .LBB0_16 | |
.quad .LBB0_13 | |
.quad .LBB0_15 | |
.text | |
.globl run | |
.align 16, 0x90 | |
.type run,@function | |
run: # @run | |
.cfi_startproc | |
# BB#0: | |
movq 24(%rdi), %rax | |
testq %rax, %rax | |
je .LBB1_12 | |
# BB#1: # %.lr.ph | |
movq 16(%rdi), %rcx | |
xorl %edx, %edx | |
.align 16, 0x90 | |
.LBB1_2: # =>This Inner Loop Header: Depth=1 | |
movsbl (%rcx,%rdx), %esi | |
cmpl $5, %esi | |
ja .LBB1_11 | |
# BB#3: # in Loop: Header=BB1_2 Depth=1 | |
jmpq *.LJTI1_0(,%rsi,8) | |
.LBB1_4: # in Loop: Header=BB1_2 Depth=1 | |
movl (%rdi), %r8d | |
movq 8(%rdi), %rsi | |
incl (%rsi,%r8,4) | |
jmp .LBB1_11 | |
.LBB1_5: # in Loop: Header=BB1_2 Depth=1 | |
movl (%rdi), %r8d | |
movq 8(%rdi), %rsi | |
decl (%rsi,%r8,4) | |
jmp .LBB1_11 | |
.LBB1_6: # in Loop: Header=BB1_2 Depth=1 | |
decl (%rdi) | |
jmp .LBB1_11 | |
.LBB1_7: # in Loop: Header=BB1_2 Depth=1 | |
incl (%rdi) | |
jmp .LBB1_11 | |
.LBB1_8: # in Loop: Header=BB1_2 Depth=1 | |
movl (%rdi), %r8d | |
movq 8(%rdi), %rsi | |
cmpl $0, (%rsi,%r8,4) | |
jne .LBB1_11 | |
jmp .LBB1_10 | |
.LBB1_9: # in Loop: Header=BB1_2 Depth=1 | |
movl (%rdi), %r8d | |
movq 8(%rdi), %rsi | |
cmpl $0, (%rsi,%r8,4) | |
je .LBB1_11 | |
.LBB1_10: # in Loop: Header=BB1_2 Depth=1 | |
movq 32(%rdi), %rsi | |
movl (%rsi,%rdx,4), %edx | |
.align 16, 0x90 | |
.LBB1_11: # in Loop: Header=BB1_2 Depth=1 | |
incl %edx | |
cmpq %rax, %rdx | |
jb .LBB1_2 | |
.LBB1_12: # %._crit_edge | |
retq | |
.Lfunc_end1: | |
.size run, .Lfunc_end1-run | |
.cfi_endproc | |
.section .rodata,"a",@progbits | |
.align 8 | |
.LJTI1_0: | |
.quad .LBB1_4 | |
.quad .LBB1_5 | |
.quad .LBB1_6 | |
.quad .LBB1_7 | |
.quad .LBB1_8 | |
.quad .LBB1_9 | |
.text | |
.globl main | |
.align 16, 0x90 | |
.type main,@function | |
main: # @main | |
.cfi_startproc | |
# BB#0: | |
pushq %r15 | |
.Ltmp13: | |
.cfi_def_cfa_offset 16 | |
pushq %r14 | |
.Ltmp14: | |
.cfi_def_cfa_offset 24 | |
pushq %r12 | |
.Ltmp15: | |
.cfi_def_cfa_offset 32 | |
pushq %rbx | |
.Ltmp16: | |
.cfi_def_cfa_offset 40 | |
subq $40, %rsp | |
.Ltmp17: | |
.cfi_def_cfa_offset 80 | |
.Ltmp18: | |
.cfi_offset %rbx, -40 | |
.Ltmp19: | |
.cfi_offset %r12, -32 | |
.Ltmp20: | |
.cfi_offset %r14, -24 | |
.Ltmp21: | |
.cfi_offset %r15, -16 | |
movq 8(%rsi), %rdi | |
movl $.L.str, %esi | |
callq fopen | |
movq %rax, %r15 | |
xorl %ebx, %ebx | |
xorl %esi, %esi | |
movl $2, %edx | |
movq %r15, %rdi | |
callq fseek | |
movq %r15, %rdi | |
callq ftell | |
movq %rax, %r14 | |
movq %r15, %rdi | |
callq rewind | |
leal 1(%r14), %edi | |
callq malloc | |
movq %rax, %r12 | |
movl %r14d, %r14d | |
movl $1, %edx | |
movq %r12, %rdi | |
movq %r14, %rsi | |
movq %r15, %rcx | |
callq fread | |
movq %r15, %rdi | |
callq fclose | |
movb $0, (%r12,%r14) | |
leaq (%rsp), %rdi | |
movq %r12, %rsi | |
movq %r14, %rdx | |
callq init_prog | |
movq %r12, %rdi | |
callq free | |
movq 24(%rsp), %rax | |
testq %rax, %rax | |
je .LBB2_12 | |
# BB#1: # %.lr.ph.i | |
movq 8(%rsp), %rcx | |
movq 16(%rsp), %rdx | |
movq 32(%rsp), %rsi | |
.align 16, 0x90 | |
.LBB2_2: # =>This Inner Loop Header: Depth=1 | |
movsbl (%rdx,%rbx), %edi | |
cmpl $5, %edi | |
ja .LBB2_11 | |
# BB#3: # in Loop: Header=BB2_2 Depth=1 | |
jmpq *.LJTI2_0(,%rdi,8) | |
.LBB2_4: # in Loop: Header=BB2_2 Depth=1 | |
movl (%rsp), %edi | |
incl (%rcx,%rdi,4) | |
jmp .LBB2_11 | |
.LBB2_5: # in Loop: Header=BB2_2 Depth=1 | |
movl (%rsp), %edi | |
decl (%rcx,%rdi,4) | |
jmp .LBB2_11 | |
.LBB2_6: # in Loop: Header=BB2_2 Depth=1 | |
decl (%rsp) | |
jmp .LBB2_11 | |
.LBB2_7: # in Loop: Header=BB2_2 Depth=1 | |
incl (%rsp) | |
jmp .LBB2_11 | |
.LBB2_8: # in Loop: Header=BB2_2 Depth=1 | |
movl (%rsp), %edi | |
cmpl $0, (%rcx,%rdi,4) | |
jne .LBB2_11 | |
jmp .LBB2_10 | |
.LBB2_9: # in Loop: Header=BB2_2 Depth=1 | |
movl (%rsp), %edi | |
cmpl $0, (%rcx,%rdi,4) | |
je .LBB2_11 | |
.LBB2_10: # in Loop: Header=BB2_2 Depth=1 | |
movl (%rsi,%rbx,4), %ebx | |
.align 16, 0x90 | |
.LBB2_11: # in Loop: Header=BB2_2 Depth=1 | |
incl %ebx | |
cmpq %rax, %rbx | |
jb .LBB2_2 | |
.LBB2_12: # %run.exit | |
xorl %eax, %eax | |
addq $40, %rsp | |
popq %rbx | |
popq %r12 | |
popq %r14 | |
popq %r15 | |
retq | |
.Lfunc_end2: | |
.size main, .Lfunc_end2-main | |
.cfi_endproc | |
.section .rodata,"a",@progbits | |
.align 8 | |
.LJTI2_0: | |
.quad .LBB2_4 | |
.quad .LBB2_5 | |
.quad .LBB2_6 | |
.quad .LBB2_7 | |
.quad .LBB2_8 | |
.quad .LBB2_9 | |
.type .L.str,@object # @.str | |
.section .rodata.str1.1,"aMS",@progbits,1 | |
.L.str: | |
.asciz "r" | |
.size .L.str, 2 | |
.ident "clang version 3.7.0 (tags/RELEASE_370/final)" | |
.section ".note.GNU-stack","",@progbits |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.text | |
.file "brainfuck-optimized.c" | |
.globl init_prog | |
.align 16, 0x90 | |
.type init_prog,@function | |
init_prog: # @init_prog | |
.cfi_startproc | |
# BB#0: | |
pushq %rbp | |
.Ltmp0: | |
.cfi_def_cfa_offset 16 | |
pushq %r15 | |
.Ltmp1: | |
.cfi_def_cfa_offset 24 | |
pushq %r14 | |
.Ltmp2: | |
.cfi_def_cfa_offset 32 | |
pushq %r13 | |
.Ltmp3: | |
.cfi_def_cfa_offset 40 | |
pushq %r12 | |
.Ltmp4: | |
.cfi_def_cfa_offset 48 | |
pushq %rbx | |
.Ltmp5: | |
.cfi_def_cfa_offset 56 | |
pushq %rax | |
.Ltmp6: | |
.cfi_def_cfa_offset 64 | |
.Ltmp7: | |
.cfi_offset %rbx, -56 | |
.Ltmp8: | |
.cfi_offset %r12, -48 | |
.Ltmp9: | |
.cfi_offset %r13, -40 | |
.Ltmp10: | |
.cfi_offset %r14, -32 | |
.Ltmp11: | |
.cfi_offset %r15, -24 | |
.Ltmp12: | |
.cfi_offset %rbp, -16 | |
movq %rdx, %rbp | |
movq %rsi, %rbx | |
movq %rdi, %r14 | |
movq %rbp, %rdi | |
callq malloc | |
movq %rax, %r12 | |
shlq $2, %rbp | |
movq %rbp, %rdi | |
callq malloc | |
movq %rax, %r13 | |
movq %rbp, %rdi | |
callq malloc | |
movq %rax, (%rsp) # 8-byte Spill | |
xorl %r15d, %r15d | |
xorl %esi, %esi | |
movq %rax, %rdi | |
movq %rbp, %rdx | |
callq memset | |
movb (%rbx), %al | |
testb %al, %al | |
movl $0, %ebp | |
je .LBB0_21 | |
# BB#1: # %.lr.ph.preheader | |
incq %rbx | |
xorl %ebp, %ebp | |
.align 16, 0x90 | |
.LBB0_2: # %.lr.ph | |
# =>This Inner Loop Header: Depth=1 | |
movsbl %al, %ecx | |
cmpl $59, %ecx | |
jg .LBB0_5 | |
# BB#3: # %.lr.ph | |
# in Loop: Header=BB0_2 Depth=1 | |
addl $-43, %ecx | |
cmpl $3, %ecx | |
ja .LBB0_20 | |
# BB#4: # %.lr.ph | |
# in Loop: Header=BB0_2 Depth=1 | |
xorl %eax, %eax | |
jmpq *.LJTI0_0(,%rcx,8) | |
.LBB0_16: # in Loop: Header=BB0_2 Depth=1 | |
movb $7, %al | |
jmp .LBB0_19 | |
.align 16, 0x90 | |
.LBB0_5: # %.lr.ph | |
# in Loop: Header=BB0_2 Depth=1 | |
cmpl $90, %ecx | |
jg .LBB0_9 | |
# BB#6: # %.lr.ph | |
# in Loop: Header=BB0_2 Depth=1 | |
cmpl $60, %ecx | |
jne .LBB0_7 | |
# BB#14: # in Loop: Header=BB0_2 Depth=1 | |
movb $2, %al | |
jmp .LBB0_19 | |
.align 16, 0x90 | |
.LBB0_9: # %.lr.ph | |
# in Loop: Header=BB0_2 Depth=1 | |
cmpl $91, %ecx | |
jne .LBB0_10 | |
# BB#17: # in Loop: Header=BB0_2 Depth=1 | |
movl %r15d, %eax | |
incl %r15d | |
movl %ebp, (%r13,%rax,4) | |
movb $4, %al | |
jmp .LBB0_19 | |
.LBB0_7: # %.lr.ph | |
# in Loop: Header=BB0_2 Depth=1 | |
cmpl $62, %ecx | |
jne .LBB0_20 | |
# BB#8: # in Loop: Header=BB0_2 Depth=1 | |
movb $3, %al | |
jmp .LBB0_19 | |
.LBB0_10: # %.lr.ph | |
# in Loop: Header=BB0_2 Depth=1 | |
cmpl $93, %ecx | |
jne .LBB0_20 | |
# BB#11: # in Loop: Header=BB0_2 Depth=1 | |
movb $5, %al | |
testl %r15d, %r15d | |
je .LBB0_12 | |
# BB#18: # in Loop: Header=BB0_2 Depth=1 | |
decl %r15d | |
movl (%r13,%r15,4), %ecx | |
movq (%rsp), %rdx # 8-byte Reload | |
movl %ebp, (%rdx,%rcx,4) | |
movl %ecx, (%rdx,%rbp,4) | |
jmp .LBB0_19 | |
.LBB0_13: # in Loop: Header=BB0_2 Depth=1 | |
movb $1, %al | |
jmp .LBB0_19 | |
.LBB0_15: # in Loop: Header=BB0_2 Depth=1 | |
movb $6, %al | |
jmp .LBB0_19 | |
.LBB0_12: # in Loop: Header=BB0_2 Depth=1 | |
xorl %r15d, %r15d | |
.align 16, 0x90 | |
.LBB0_19: # in Loop: Header=BB0_2 Depth=1 | |
movb %al, (%r12,%rbp) | |
incq %rbp | |
.LBB0_20: # in Loop: Header=BB0_2 Depth=1 | |
movb (%rbx), %al | |
incq %rbx | |
testb %al, %al | |
jne .LBB0_2 | |
.LBB0_21: # %._crit_edge | |
movq %r13, %rdi | |
callq free | |
movl $0, (%r14) | |
movl $400000, %edi # imm = 0x61A80 | |
callq malloc | |
movq %rax, 8(%r14) | |
xorl %esi, %esi | |
movl $400000, %edx # imm = 0x61A80 | |
movq %rax, %rdi | |
callq memset | |
movq %r12, 16(%r14) | |
movq (%rsp), %rax # 8-byte Reload | |
movq %rax, 32(%r14) | |
incq %rbp | |
movq %rbp, 24(%r14) | |
addq $8, %rsp | |
popq %rbx | |
popq %r12 | |
popq %r13 | |
popq %r14 | |
popq %r15 | |
popq %rbp | |
retq | |
.Lfunc_end0: | |
.size init_prog, .Lfunc_end0-init_prog | |
.cfi_endproc | |
.section .rodata,"a",@progbits | |
.align 8 | |
.LJTI0_0: | |
.quad .LBB0_19 | |
.quad .LBB0_16 | |
.quad .LBB0_13 | |
.quad .LBB0_15 | |
.text | |
.globl run | |
.align 16, 0x90 | |
.type run,@function | |
run: # @run | |
.cfi_startproc | |
# BB#0: | |
movq 24(%rdi), %rax | |
testq %rax, %rax | |
je .LBB1_12 | |
# BB#1: # %.lr.ph | |
movq 16(%rdi), %r8 | |
xorl %edx, %edx | |
jmp .LBB1_2 | |
.LBB1_3: # in Loop: Header=BB1_2 Depth=1 | |
jmpq *.LJTI1_0(,%rsi,8) | |
.LBB1_5: # in Loop: Header=BB1_2 Depth=1 | |
movl (%rdi), %ecx | |
movq 8(%rdi), %rsi | |
decl (%rsi,%rcx,4) | |
jmp .LBB1_11 | |
.LBB1_6: # in Loop: Header=BB1_2 Depth=1 | |
decl (%rdi) | |
jmp .LBB1_11 | |
.LBB1_7: # in Loop: Header=BB1_2 Depth=1 | |
incl (%rdi) | |
jmp .LBB1_11 | |
.LBB1_8: # in Loop: Header=BB1_2 Depth=1 | |
movl (%rdi), %ecx | |
movq 8(%rdi), %rsi | |
cmpl $0, (%rsi,%rcx,4) | |
jne .LBB1_11 | |
jmp .LBB1_10 | |
.LBB1_9: # in Loop: Header=BB1_2 Depth=1 | |
movl (%rdi), %ecx | |
movq 8(%rdi), %rsi | |
cmpl $0, (%rsi,%rcx,4) | |
je .LBB1_11 | |
.LBB1_10: # in Loop: Header=BB1_2 Depth=1 | |
movq 32(%rdi), %rcx | |
movl (%rcx,%rdx,4), %edx | |
jmp .LBB1_11 | |
.align 16, 0x90 | |
.LBB1_2: # =>This Inner Loop Header: Depth=1 | |
movsbl (%r8,%rdx), %esi | |
decl %esi | |
cmpl $5, %esi | |
jbe .LBB1_3 | |
# BB#4: # in Loop: Header=BB1_2 Depth=1 | |
movl (%rdi), %esi | |
movq 8(%rdi), %rcx | |
incl (%rcx,%rsi,4) | |
.LBB1_11: # in Loop: Header=BB1_2 Depth=1 | |
incl %edx | |
cmpq %rax, %rdx | |
jb .LBB1_2 | |
.LBB1_12: # %._crit_edge | |
retq | |
.Lfunc_end1: | |
.size run, .Lfunc_end1-run | |
.cfi_endproc | |
.section .rodata,"a",@progbits | |
.align 8 | |
.LJTI1_0: | |
.quad .LBB1_5 | |
.quad .LBB1_6 | |
.quad .LBB1_7 | |
.quad .LBB1_8 | |
.quad .LBB1_9 | |
.quad .LBB1_11 | |
.text | |
.globl main | |
.align 16, 0x90 | |
.type main,@function | |
main: # @main | |
.cfi_startproc | |
# BB#0: | |
pushq %r15 | |
.Ltmp13: | |
.cfi_def_cfa_offset 16 | |
pushq %r14 | |
.Ltmp14: | |
.cfi_def_cfa_offset 24 | |
pushq %r12 | |
.Ltmp15: | |
.cfi_def_cfa_offset 32 | |
pushq %rbx | |
.Ltmp16: | |
.cfi_def_cfa_offset 40 | |
subq $40, %rsp | |
.Ltmp17: | |
.cfi_def_cfa_offset 80 | |
.Ltmp18: | |
.cfi_offset %rbx, -40 | |
.Ltmp19: | |
.cfi_offset %r12, -32 | |
.Ltmp20: | |
.cfi_offset %r14, -24 | |
.Ltmp21: | |
.cfi_offset %r15, -16 | |
movq 8(%rsi), %rdi | |
movl $.L.str, %esi | |
callq fopen | |
movq %rax, %r15 | |
xorl %ebx, %ebx | |
xorl %esi, %esi | |
movl $2, %edx | |
movq %r15, %rdi | |
callq fseek | |
movq %r15, %rdi | |
callq ftell | |
movq %rax, %r14 | |
movq %r15, %rdi | |
callq rewind | |
leal 1(%r14), %edi | |
callq malloc | |
movq %rax, %r12 | |
movl %r14d, %r14d | |
movl $1, %edx | |
movq %r12, %rdi | |
movq %r14, %rsi | |
movq %r15, %rcx | |
callq fread | |
movq %r15, %rdi | |
callq fclose | |
movb $0, (%r12,%r14) | |
leaq (%rsp), %rdi | |
movq %r12, %rsi | |
movq %r14, %rdx | |
callq init_prog | |
movq %r12, %rdi | |
callq free | |
movq 24(%rsp), %rax | |
testq %rax, %rax | |
je .LBB2_12 | |
# BB#1: # %.lr.ph.i | |
movq 8(%rsp), %rcx | |
movq 16(%rsp), %rdx | |
movq 32(%rsp), %rsi | |
jmp .LBB2_2 | |
.LBB2_3: # in Loop: Header=BB2_2 Depth=1 | |
jmpq *.LJTI2_0(,%rdi,8) | |
.LBB2_5: # in Loop: Header=BB2_2 Depth=1 | |
movl (%rsp), %edi | |
decl (%rcx,%rdi,4) | |
jmp .LBB2_11 | |
.LBB2_6: # in Loop: Header=BB2_2 Depth=1 | |
decl (%rsp) | |
jmp .LBB2_11 | |
.LBB2_7: # in Loop: Header=BB2_2 Depth=1 | |
incl (%rsp) | |
jmp .LBB2_11 | |
.LBB2_8: # in Loop: Header=BB2_2 Depth=1 | |
movl (%rsp), %edi | |
cmpl $0, (%rcx,%rdi,4) | |
jne .LBB2_11 | |
jmp .LBB2_10 | |
.LBB2_9: # in Loop: Header=BB2_2 Depth=1 | |
movl (%rsp), %edi | |
cmpl $0, (%rcx,%rdi,4) | |
je .LBB2_11 | |
.LBB2_10: # in Loop: Header=BB2_2 Depth=1 | |
movl (%rsi,%rbx,4), %ebx | |
jmp .LBB2_11 | |
.align 16, 0x90 | |
.LBB2_2: # =>This Inner Loop Header: Depth=1 | |
movsbl (%rdx,%rbx), %edi | |
decl %edi | |
cmpl $5, %edi | |
jbe .LBB2_3 | |
# BB#4: # in Loop: Header=BB2_2 Depth=1 | |
movl (%rsp), %edi | |
incl (%rcx,%rdi,4) | |
.LBB2_11: # in Loop: Header=BB2_2 Depth=1 | |
incl %ebx | |
cmpq %rax, %rbx | |
jb .LBB2_2 | |
.LBB2_12: # %run.exit | |
xorl %eax, %eax | |
addq $40, %rsp | |
popq %rbx | |
popq %r12 | |
popq %r14 | |
popq %r15 | |
retq | |
.Lfunc_end2: | |
.size main, .Lfunc_end2-main | |
.cfi_endproc | |
.section .rodata,"a",@progbits | |
.align 8 | |
.LJTI2_0: | |
.quad .LBB2_5 | |
.quad .LBB2_6 | |
.quad .LBB2_7 | |
.quad .LBB2_8 | |
.quad .LBB2_9 | |
.quad .LBB2_11 | |
.type .L.str,@object # @.str | |
.section .rodata.str1.1,"aMS",@progbits,1 | |
.L.str: | |
.asciz "r" | |
.size .L.str, 2 | |
.ident "clang version 3.7.0 (tags/RELEASE_370/final)" | |
.section ".note.GNU-stack","",@progbits |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment