c.godbolt.org
Compiler Explorer - C
// PROCEDURE WriteNum(n, width: INTEGER); // VAR d, t: INTEGER; // BEGIN REG n, width, d, t; d := 1; t := n; // IF t < 0 THEN d := 2; t := -t END; // WHILE t >= 10 DO t := t DIV 10; d += 1 END; // WHILE d < width DO WriteChar(32); d += 1 END; // WriteInt(n) // END WriteNum; // // : // sub rsp,24 // cmp rsp,QWORD PTR // jb // mov r15d,ecx // mov r14d,esi // mov r12d,1 // mov ebp,r15d // test ebp,ebp // ,-- jge // | mov r12d,2to // | neg ebp // >-> cmp ebp,10 // ,--|-- jl // | | mov edx,ebp // | | sar edx,31 // | | xor ebp,edx // | | imul rbp,rbp,1717986919 // | | shr rbp,34 // | | xor ebp,edx // | | inc r12d // | '-- jmp // >----> cmp r12d,r14d // | ,-- jge // | | mov esi,32 // | | mov rdi,QWORD PTR // | | call QWORD PTR // | | inc r12d // '--|-- jmp // '-> mov esi,r15d // mov rdi,QWORD PTR // call QWORD PTR // add rsp,24 // ret extern void *io; extern void WriteChar(void *io, int c); extern void WriteInt(void *io, int i); // If you don't know, 'register' actually has an effect on gcc -O0. void WriteNum(register int n, register int width) { register int d, t; d = 1; t = n; if (t < 0) { d = 2; t = -t; } // Oberon has Euclidean division, so t / 10 is not exactly the same. while (t >= 10) { t = t / 10; d += 1; } while (d < width) { WriteChar(io, 32); d += 1; } WriteInt(io, n); } #ifdef __TINYC__ void *io; void WriteChar(void *io, int c) {} void WriteInt(void *io, int i) {} void main() {} #endif