Skip to content

Instantly share code, notes, and snippets.

@arnabanimesh
Last active September 15, 2024 19:44
Show Gist options
  • Save arnabanimesh/0d29e6ca6199b8106c8758cc5c9bb2a4 to your computer and use it in GitHub Desktop.
Save arnabanimesh/0d29e6ca6199b8106c8758cc5c9bb2a4 to your computer and use it in GitHub Desktop.
run `amicable_num_bench` C code using `-S` and `-fverbose-asm` flags. use gcc 14.2 and clang 18.1.8 on windows 11. Clang uses msvc libraries and lld linker. Optimization level 2 with no lto
.text
.def @feat.00;
.scl 3;
.type 0;
.endef
.globl @feat.00
.set @feat.00, 0
.file "c99.c"
.def strtouint32_safe;
.scl 2;
.type 32;
.endef
.globl strtouint32_safe # -- Begin function strtouint32_safe
.p2align 4, 0x90
strtouint32_safe: # @strtouint32_safe
.seh_proc strtouint32_safe
# %bb.0:
pushq %rsi
.seh_pushreg %rsi
pushq %rdi
.seh_pushreg %rdi
subq $40, %rsp
.seh_stackalloc 40
.seh_endprologue
movq %rdx, %rsi
movq %rcx, %rdi
callq _errno
movl $0, (%rax)
leaq 32(%rsp), %rdx
movq %rdi, %rcx
xorl %r8d, %r8d
callq strtol
movslq %eax, %rcx
movq %rcx, (%rsi)
movq 32(%rsp), %rcx
cmpq %rdi, %rcx
je .LBB0_4
# %bb.1:
cmpb $0, (%rcx)
je .LBB0_2
.LBB0_4:
xorl %esi, %esi
.LBB0_5:
movl %esi, %eax
addq $40, %rsp
popq %rdi
popq %rsi
retq
.LBB0_2:
addl $-2147483647, %eax # imm = 0x80000001
movb $1, %sil
cmpl $1, %eax
ja .LBB0_5
# %bb.3:
callq _errno
cmpl $34, (%rax)
je .LBB0_4
jmp .LBB0_5
.seh_endproc
# -- End function
.def power;
.scl 2;
.type 32;
.endef
.globl power # -- Begin function power
.p2align 4, 0x90
power: # @power
# %bb.0:
testb $1, %dl
movl $1, %r8d
movq %rcx, %rax
cmoveq %r8, %rax
cmpl $2, %edx
jb .LBB1_3
# %bb.1:
movl %edx, %r9d
.p2align 4, 0x90
.LBB1_2: # =>This Inner Loop Header: Depth=1
shrl %r9d
imulq %rcx, %rcx
testb $2, %dl
movq %rcx, %r10
cmoveq %r8, %r10
imulq %r10, %rax
cmpl $3, %edx
movl %r9d, %edx
ja .LBB1_2
.LBB1_3:
retq
# -- End function
.def sum_of_proper_divisors;
.scl 2;
.type 32;
.endef
.globl sum_of_proper_divisors # -- Begin function sum_of_proper_divisors
.p2align 4, 0x90
sum_of_proper_divisors: # @sum_of_proper_divisors
.seh_proc sum_of_proper_divisors
# %bb.0:
pushq %rsi
.seh_pushreg %rsi
pushq %rdi
.seh_pushreg %rdi
pushq %rbx
.seh_pushreg %rbx
.seh_endprologue
movl $2, %r8d
movq %rcx, %r9
testb $1, %cl
jne .LBB2_6
# %bb.1:
movl $-1, %eax
movq %rcx, %r9
.p2align 4, 0x90
.LBB2_2: # =>This Inner Loop Header: Depth=1
movq %r9, %rdx
shrq %r9
incl %eax
testb $2, %dl
je .LBB2_2
# %bb.3:
movl %eax, %r8d
andl $1, %r8d
incq %r8
cmpl $-3, %eax
ja .LBB2_6
# %bb.4:
addl $2, %eax
movl $2, %edx
movl $1, %r10d
movl %eax, %r11d
.p2align 4, 0x90
.LBB2_5: # =>This Inner Loop Header: Depth=1
shrl %r11d
imulq %rdx, %rdx
testb $2, %al
movq %rdx, %rsi
cmoveq %r10, %rsi
imulq %rsi, %r8
cmpl $3, %eax
movl %r11d, %eax
ja .LBB2_5
.LBB2_6:
decq %r8
cmpq $9, %r9
jae .LBB2_7
.LBB2_28:
cmpq $3, %r9
jb .LBB2_33
# %bb.29:
movq %r9, %rax
imulq %r9, %rax
decq %rax
decq %r9
movq %rax, %rdx
orq %r9, %rdx
shrq $32, %rdx
je .LBB2_30
# %bb.31:
xorl %edx, %edx
divq %r9
jmp .LBB2_32
.LBB2_7:
movl $3, %r10d
movl $1, %r11d
jmp .LBB2_8
.p2align 4, 0x90
.LBB2_25: # in Loop: Header=BB2_8 Depth=1
# kill: def $eax killed $eax killed $rax
xorl %edx, %edx
divl %esi
# kill: def $eax killed $eax def $rax
.LBB2_27: # in Loop: Header=BB2_8 Depth=1
imulq %rax, %r8
addq $2, %r10
movq %r10, %rax
imulq %r10, %rax
cmpq %r9, %rax
ja .LBB2_28
.LBB2_8: # =>This Loop Header: Depth=1
# Child Loop BB2_14 Depth 2
# Child Loop BB2_23 Depth 2
movq %r9, %rax
orq %r10, %rax
shrq $32, %rax
je .LBB2_9
# %bb.10: # in Loop: Header=BB2_8 Depth=1
movq %r9, %rax
xorl %edx, %edx
divq %r10
testq %rdx, %rdx
je .LBB2_13
.LBB2_12: # in Loop: Header=BB2_8 Depth=1
movq %r10, %rax
jmp .LBB2_24
.p2align 4, 0x90
.LBB2_9: # in Loop: Header=BB2_8 Depth=1
movl %r9d, %eax
xorl %edx, %edx
divl %r10d
# kill: def $edx killed $edx def $rdx
testq %rdx, %rdx
jne .LBB2_12
.LBB2_13: # in Loop: Header=BB2_8 Depth=1
movl $-1, %esi
jmp .LBB2_14
.p2align 4, 0x90
.LBB2_19: # in Loop: Header=BB2_14 Depth=2
movq %r9, %rax
xorl %edx, %edx
divq %r10
.LBB2_20: # in Loop: Header=BB2_14 Depth=2
incl %esi
testq %rdx, %rdx
jne .LBB2_21
.LBB2_14: # Parent Loop BB2_8 Depth=1
# => This Inner Loop Header: Depth=2
movq %r9, %rax
orq %r10, %rax
shrq $32, %rax
je .LBB2_15
# %bb.16: # in Loop: Header=BB2_14 Depth=2
movq %r9, %rax
xorl %edx, %edx
divq %r10
movq %rax, %r9
jmp .LBB2_17
.p2align 4, 0x90
.LBB2_15: # in Loop: Header=BB2_14 Depth=2
movl %r9d, %eax
xorl %edx, %edx
divl %r10d
movl %eax, %r9d
.LBB2_17: # in Loop: Header=BB2_14 Depth=2
movq %r9, %rax
orq %r10, %rax
shrq $32, %rax
jne .LBB2_19
# %bb.18: # in Loop: Header=BB2_14 Depth=2
movl %r9d, %eax
xorl %edx, %edx
divl %r10d
# kill: def $edx killed $edx def $rdx
jmp .LBB2_20
.p2align 4, 0x90
.LBB2_21: # in Loop: Header=BB2_8 Depth=1
testb $1, %sil
movq %r10, %rax
cmoveq %r11, %rax
cmpl $-3, %esi
ja .LBB2_24
# %bb.22: # in Loop: Header=BB2_8 Depth=1
addl $2, %esi
movq %r10, %rdx
movl %esi, %edi
.p2align 4, 0x90
.LBB2_23: # Parent Loop BB2_8 Depth=1
# => This Inner Loop Header: Depth=2
shrl %edi
imulq %rdx, %rdx
testb $2, %sil
movq %rdx, %rbx
cmoveq %r11, %rbx
imulq %rbx, %rax
cmpl $3, %esi
movl %edi, %esi
ja .LBB2_23
.p2align 4, 0x90
.LBB2_24: # in Loop: Header=BB2_8 Depth=1
decq %rax
leaq -1(%r10), %rsi
movq %rax, %rdx
orq %rsi, %rdx
shrq $32, %rdx
je .LBB2_25
# %bb.26: # in Loop: Header=BB2_8 Depth=1
xorl %edx, %edx
divq %rsi
jmp .LBB2_27
.LBB2_30:
# kill: def $eax killed $eax killed $rax
xorl %edx, %edx
divl %r9d
# kill: def $eax killed $eax def $rax
.LBB2_32:
imulq %rax, %r8
.LBB2_33:
subq %rcx, %r8
movq %r8, %rax
popq %rbx
popq %rdi
popq %rsi
retq
.seh_endproc
# -- End function
.def main;
.scl 2;
.type 32;
.endef
.globl main # -- Begin function main
.p2align 4, 0x90
main: # @main
.seh_proc main
# %bb.0:
pushq %rsi
.seh_pushreg %rsi
pushq %rdi
.seh_pushreg %rdi
pushq %rbx
.seh_pushreg %rbx
subq $48, %rsp
.seh_stackalloc 48
.seh_endprologue
movl $10000, %ebx # imm = 0x2710
cmpl $2, %ecx
jl .LBB3_7
# %bb.1:
movq 8(%rdx), %rdi
callq _errno
movl $0, (%rax)
leaq 40(%rsp), %rdx
movq %rdi, %rcx
xorl %r8d, %r8d
callq strtol
movl %eax, %esi
movq 40(%rsp), %rax
cmpq %rdi, %rax
je .LBB3_13
# %bb.2:
cmpb $0, (%rax)
jne .LBB3_13
# %bb.3:
leal -2147483647(%rsi), %eax
cmpl $1, %eax
ja .LBB3_5
# %bb.4:
callq _errno
cmpl $34, (%rax)
je .LBB3_13
.LBB3_5:
cmpl $4, %esi
jb .LBB3_11
# %bb.6:
movslq %esi, %rbx
.LBB3_7:
movl $3, %edi
xorl %esi, %esi
jmp .LBB3_8
.p2align 4, 0x90
.LBB3_10: # in Loop: Header=BB3_8 Depth=1
incq %rdi
cmpq %rdi, %rbx
je .LBB3_12
.LBB3_8: # =>This Inner Loop Header: Depth=1
movq %rdi, %rcx
callq sum_of_proper_divisors
cmpq %rax, %rdi
je .LBB3_10
# %bb.9: # in Loop: Header=BB3_8 Depth=1
movq %rax, %rcx
callq sum_of_proper_divisors
cmpq %rax, %rdi
movl $0, %eax
cmoveq %rdi, %rax
addq %rax, %rsi
jmp .LBB3_10
.LBB3_11:
xorl %esi, %esi
.LBB3_12:
leaq "??_C@_05JMLLFKBP@?$CFllu?6?$AA@"(%rip), %rcx
movq %rsi, %rdx
callq printf
xorl %eax, %eax
addq $48, %rsp
popq %rbx
popq %rdi
popq %rsi
retq
.LBB3_13:
movl $2, %ecx
callq __acrt_iob_func
leaq "??_C@_0GC@KBLCMAPK@Enter?5a?5valid?5integer?5as?5first?5C@"(%rip), %rcx
movl $97, %edx
movl $1, %r8d
movq %rax, %r9
callq fwrite
movl $1, %ecx
callq exit
int3
.seh_endproc
# -- End function
.def printf;
.scl 2;
.type 32;
.endef
.section .text,"xr",discard,printf
.globl printf # -- Begin function printf
.p2align 4, 0x90
printf: # @printf
.seh_proc printf
# %bb.0:
pushq %rsi
.seh_pushreg %rsi
pushq %rdi
.seh_pushreg %rdi
pushq %rbx
.seh_pushreg %rbx
subq $48, %rsp
.seh_stackalloc 48
.seh_endprologue
movq %rcx, %rsi
movq %rdx, 88(%rsp)
movq %r8, 96(%rsp)
movq %r9, 104(%rsp)
leaq 88(%rsp), %rbx
movq %rbx, 40(%rsp)
movl $1, %ecx
callq __acrt_iob_func
movq %rax, %rdi
callq __local_stdio_printf_options
movq (%rax), %rcx
movq %rbx, 32(%rsp)
movq %rdi, %rdx
movq %rsi, %r8
xorl %r9d, %r9d
callq __stdio_common_vfprintf
nop
addq $48, %rsp
popq %rbx
popq %rdi
popq %rsi
retq
.seh_endproc
# -- End function
.def __local_stdio_printf_options;
.scl 2;
.type 32;
.endef
.section .text,"xr",discard,__local_stdio_printf_options
.globl __local_stdio_printf_options # -- Begin function __local_stdio_printf_options
.p2align 4, 0x90
__local_stdio_printf_options: # @__local_stdio_printf_options
# %bb.0:
leaq __local_stdio_printf_options._OptionsStorage(%rip), %rax
retq
# -- End function
.section .rdata,"dr",discard,"??_C@_0GC@KBLCMAPK@Enter?5a?5valid?5integer?5as?5first?5C@"
.globl "??_C@_0GC@KBLCMAPK@Enter?5a?5valid?5integer?5as?5first?5C@" # @"??_C@_0GC@KBLCMAPK@Enter?5a?5valid?5integer?5as?5first?5C@"
"??_C@_0GC@KBLCMAPK@Enter?5a?5valid?5integer?5as?5first?5C@":
.asciz "Enter a valid integer as first CLI argument or pass no argument to consider a max limit of 10,000"
.section .rdata,"dr",discard,"??_C@_05JMLLFKBP@?$CFllu?6?$AA@"
.globl "??_C@_05JMLLFKBP@?$CFllu?6?$AA@" # @"??_C@_05JMLLFKBP@?$CFllu?6?$AA@"
"??_C@_05JMLLFKBP@?$CFllu?6?$AA@":
.asciz "%llu\n"
.lcomm __local_stdio_printf_options._OptionsStorage,8,8 # @__local_stdio_printf_options._OptionsStorage
.addrsig
.addrsig_sym __local_stdio_printf_options._OptionsStorage
.file "c99.c"
# GNU C99 (GCC) version 14.2.0 (x86_64-w64-mingw32)
# compiled by GNU C version 14.2.0, GMP version 6.3.0, MPFR version 4.2.1, MPC version 1.3.1, isl version none
# GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
# options passed: -mtune=generic -march=x86-64 -O2 -std=c99
.text
.section .rdata,"dr"
.LC0:
.ascii "%llu\12\0"
.text
.p2align 4
.def printf.constprop.0; .scl 3; .type 32; .endef
.seh_proc printf.constprop.0
printf.constprop.0:
pushq %rbx #
.seh_pushreg %rbx
subq $48, %rsp #,
.seh_stackalloc 48
.seh_endprologue
# C:/Users/arnab/scoop/apps/w64devkit/2.0.0/x86_64-w64-mingw32/include/stdio.h:383: __retval = __mingw_vfprintf( stdout, __format, __local_argv );
movl $1, %ecx #,
# C:/Users/arnab/scoop/apps/w64devkit/2.0.0/x86_64-w64-mingw32/include/stdio.h:382: __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
leaq 72(%rsp), %rbx #, tmp102
# C:/Users/arnab/scoop/apps/w64devkit/2.0.0/x86_64-w64-mingw32/include/stdio.h:379: int printf (const char *__format, ...)
movq %rdx, 72(%rsp) #,
movq %r8, 80(%rsp) #,
movq %r9, 88(%rsp) #,
# C:/Users/arnab/scoop/apps/w64devkit/2.0.0/x86_64-w64-mingw32/include/stdio.h:382: __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
movq %rbx, 40(%rsp) # tmp102, MEM[(char * *)&__local_argv]
# C:/Users/arnab/scoop/apps/w64devkit/2.0.0/x86_64-w64-mingw32/include/stdio.h:383: __retval = __mingw_vfprintf( stdout, __format, __local_argv );
call *__imp___acrt_iob_func(%rip) #
# C:/Users/arnab/scoop/apps/w64devkit/2.0.0/x86_64-w64-mingw32/include/stdio.h:383: __retval = __mingw_vfprintf( stdout, __format, __local_argv );
movq %rbx, %r8 # tmp102,
leaq .LC0(%rip), %rdx #, tmp104
# C:/Users/arnab/scoop/apps/w64devkit/2.0.0/x86_64-w64-mingw32/include/stdio.h:383: __retval = __mingw_vfprintf( stdout, __format, __local_argv );
movq %rax, %rcx # tmp106, _2
# C:/Users/arnab/scoop/apps/w64devkit/2.0.0/x86_64-w64-mingw32/include/stdio.h:383: __retval = __mingw_vfprintf( stdout, __format, __local_argv );
call __mingw_vfprintf #
# C:/Users/arnab/scoop/apps/w64devkit/2.0.0/x86_64-w64-mingw32/include/stdio.h:386: }
addq $48, %rsp #,
popq %rbx #
ret
.seh_endproc
.section .rdata,"dr"
.align 8
.LC1:
.ascii "Enter a valid integer as first CLI argument or pass no argument to consider a max limit of 10,000\0"
.text
.p2align 4
.def fprintf.constprop.0; .scl 3; .type 32; .endef
.seh_proc fprintf.constprop.0
fprintf.constprop.0:
subq $56, %rsp #,
.seh_stackalloc 56
.seh_endprologue
# C:/Users/arnab/scoop/apps/w64devkit/2.0.0/x86_64-w64-mingw32/include/stdio.h:372: __retval = __mingw_vfprintf( __stream, __format, __local_argv );
leaq .LC1(%rip), %rdx #, tmp104
# C:/Users/arnab/scoop/apps/w64devkit/2.0.0/x86_64-w64-mingw32/include/stdio.h:368: int fprintf (FILE *__stream, const char *__format, ...)
movq %r8, 80(%rsp) #,
# C:/Users/arnab/scoop/apps/w64devkit/2.0.0/x86_64-w64-mingw32/include/stdio.h:371: __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
leaq 80(%rsp), %r8 #, tmp102
# C:/Users/arnab/scoop/apps/w64devkit/2.0.0/x86_64-w64-mingw32/include/stdio.h:368: int fprintf (FILE *__stream, const char *__format, ...)
movq %r9, 88(%rsp) #,
# C:/Users/arnab/scoop/apps/w64devkit/2.0.0/x86_64-w64-mingw32/include/stdio.h:371: __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
movq %r8, 40(%rsp) # tmp102, MEM[(char * *)&__local_argv]
# C:/Users/arnab/scoop/apps/w64devkit/2.0.0/x86_64-w64-mingw32/include/stdio.h:372: __retval = __mingw_vfprintf( __stream, __format, __local_argv );
call __mingw_vfprintf #
# C:/Users/arnab/scoop/apps/w64devkit/2.0.0/x86_64-w64-mingw32/include/stdio.h:375: }
addq $56, %rsp #,
ret
.seh_endproc
.p2align 4
.globl strtouint32_safe
.def strtouint32_safe; .scl 2; .type 32; .endef
.seh_proc strtouint32_safe
strtouint32_safe:
pushq %rdi #
.seh_pushreg %rdi
pushq %rsi #
.seh_pushreg %rsi
pushq %rbx #
.seh_pushreg %rbx
subq $48, %rsp #,
.seh_stackalloc 48
.seh_endprologue
# c99.c:12: errno = 0;
movq __imp__errno(%rip), %rdi #, tmp120
# c99.c:10: {
movq %rdx, %rsi # tmp122, val
movq %rcx, %rbx # tmp121, str
# c99.c:12: errno = 0;
call *%rdi # tmp120
# c99.c:14: *val = (uint64_t)strtol(str, &temp, 0);
leaq 40(%rsp), %rdx #, tmp112
movq %rbx, %rcx # str,
xorl %r8d, %r8d #
# c99.c:12: errno = 0;
movl $0, (%rax) #, *_1
# c99.c:14: *val = (uint64_t)strtol(str, &temp, 0);
call strtol #
# c99.c:15: if (temp == str || *temp != '\0' || (((*val == (uint64_t)LONG_MIN) || (*val == (uint64_t)LONG_MAX)) && (errno == ERANGE)))
movq 40(%rsp), %rdx # temp, temp.0_4
# c99.c:16: rc = false;
xorl %ecx, %ecx # <retval>
# c99.c:14: *val = (uint64_t)strtol(str, &temp, 0);
cltq
# c99.c:14: *val = (uint64_t)strtol(str, &temp, 0);
movq %rax, (%rsi) # _3, *val_20(D)
# c99.c:15: if (temp == str || *temp != '\0' || (((*val == (uint64_t)LONG_MIN) || (*val == (uint64_t)LONG_MAX)) && (errno == ERANGE)))
cmpq %rbx, %rdx # str, temp.0_4
je .L4 #,
# c99.c:15: if (temp == str || *temp != '\0' || (((*val == (uint64_t)LONG_MIN) || (*val == (uint64_t)LONG_MAX)) && (errno == ERANGE)))
cmpb $0, (%rdx) #, *temp.0_4
jne .L4 #,
# c99.c:15: if (temp == str || *temp != '\0' || (((*val == (uint64_t)LONG_MIN) || (*val == (uint64_t)LONG_MAX)) && (errno == ERANGE)))
cmpq $-2147483648, %rax #, _3
je .L10 #,
# c99.c:13: bool rc = true;
movl $1, %ecx #, <retval>
# c99.c:15: if (temp == str || *temp != '\0' || (((*val == (uint64_t)LONG_MIN) || (*val == (uint64_t)LONG_MAX)) && (errno == ERANGE)))
cmpq $2147483647, %rax #, _3
je .L10 #,
.L4:
# c99.c:18: }
movl %ecx, %eax # <retval>,
addq $48, %rsp #,
popq %rbx #
popq %rsi #
popq %rdi #
ret
.p2align 4,,10
.p2align 3
.L10:
# c99.c:15: if (temp == str || *temp != '\0' || (((*val == (uint64_t)LONG_MIN) || (*val == (uint64_t)LONG_MAX)) && (errno == ERANGE)))
call *%rdi # tmp120
# c99.c:15: if (temp == str || *temp != '\0' || (((*val == (uint64_t)LONG_MIN) || (*val == (uint64_t)LONG_MAX)) && (errno == ERANGE)))
cmpl $34, (%rax) #, *_10
setne %cl #, <retval>
# c99.c:18: }
movl %ecx, %eax # <retval>,
addq $48, %rsp #,
popq %rbx #
popq %rsi #
popq %rdi #
ret
.seh_endproc
.p2align 4
.globl power
.def power; .scl 2; .type 32; .endef
.seh_proc power
power:
.seh_endprologue
movl $1, %eax #, <retval>
# c99.c:25: if (exp&1)
testb $1, %dl #, exp
je .L13 #,
.p2align 4
.p2align 3
.L15:
# c99.c:27: result *= base;
imulq %rcx, %rax # base, <retval>
.L13:
# c99.c:30: if (exp == 0)
shrl %edx # exp
je .L12 #,
# c99.c:34: base *= base;
imulq %rcx, %rcx # base, base
# c99.c:25: if (exp&1)
testb $1, %dl #, exp
jne .L15 #,
.L19:
# c99.c:29: exp >>= 1;
shrl %edx # exp
# c99.c:34: base *= base;
imulq %rcx, %rcx # base, base
# c99.c:25: if (exp&1)
testb $1, %dl #, exp
jne .L15 #,
jmp .L19 #
.p2align 4,,10
.p2align 3
.L12:
# c99.c:37: }
ret
.seh_endproc
.p2align 4
.globl sum_of_proper_divisors
.def sum_of_proper_divisors; .scl 2; .type 32; .endef
.seh_proc sum_of_proper_divisors
sum_of_proper_divisors:
pushq %rbx #
.seh_pushreg %rbx
.seh_endprologue
# c99.c:40: {
movq %rcx, %rbx # tmp156, n
# c99.c:44: while (n_mut % 2 == 0)
testb $1, %cl #, n
jne .L36 #,
# c99.c:43: uint32_t step = 0;
xorl %edx, %edx # step
.p2align 4
.p2align 4
.p2align 3
.L22:
# c99.c:47: n_mut /= 2;
shrq %rcx # n_mut
movl %edx, %eax # step, step
# c99.c:46: step += 1;
addl $1, %edx #, step
# c99.c:44: while (n_mut % 2 == 0)
testb $1, %cl #, n_mut
je .L22 #,
# c99.c:49: sum_divisors *= power(2, step + 1) - 1;
addl $2, %eax #, exp
.L21:
# c99.c:25: if (exp&1)
testb $1, %al #, exp
je .L37 #,
movl $1, %r11d #, result
movl $2, %edx #, base
.p2align 4
.p2align 3
.L25:
# c99.c:27: result *= base;
imulq %rdx, %r11 # base, result
.L23:
# c99.c:30: if (exp == 0)
shrl %eax # exp
je .L24 #,
# c99.c:34: base *= base;
imulq %rdx, %rdx # base, base
# c99.c:25: if (exp&1)
testb $1, %al #, exp
jne .L25 #,
.L48:
# c99.c:29: exp >>= 1;
shrl %eax # exp
# c99.c:34: base *= base;
imulq %rdx, %rdx # base, base
# c99.c:25: if (exp&1)
testb $1, %al #, exp
jne .L25 #,
jmp .L48 #
.p2align 4,,10
.p2align 3
.L24:
# c99.c:49: sum_divisors *= power(2, step + 1) - 1;
subq $1, %r11 #, sum_divisors
# c99.c:50: uint64_t i = 3;
movl $3, %r9d #, i
# c99.c:51: while (i * i <= n_mut)
cmpq $8, %rcx #, n_mut
jbe .L28 #,
.p2align 4
.p2align 3
.L27:
# c99.c:54: while (n_mut % i == 0)
movq %rcx, %rax # n_mut, tmp148
xorl %edx, %edx # _49
# c99.c:53: step = 0;
xorl %r10d, %r10d # step
# c99.c:54: while (n_mut % i == 0)
divq %r9 # i
# c99.c:54: while (n_mut % i == 0)
testq %rdx, %rdx # _49
jne .L49 #,
.p2align 5
.p2align 4
.p2align 3
.L29:
# c99.c:57: n_mut /= i;
movq %rcx, %rax # n_mut, n_mut
xorl %edx, %edx # tmp134
movl %r10d, %r8d # step, step
# c99.c:56: step += 1;
addl $1, %r10d #, step
# c99.c:57: n_mut /= i;
divq %r9 # i
# c99.c:54: while (n_mut % i == 0)
xorl %edx, %edx # _3
# c99.c:57: n_mut /= i;
movq %rax, %rcx # n_mut, n_mut
# c99.c:54: while (n_mut % i == 0)
divq %r9 # i
# c99.c:54: while (n_mut % i == 0)
testq %rdx, %rdx # _3
je .L29 #,
# c99.c:59: sum_divisors *= (power(i, step + 1) - 1) / (i - 1);
leal 2(%r8), %edx #, exp
.L34:
movq %r9, %r8 # i, base
movl $1, %eax #, result
# c99.c:25: if (exp&1)
testb $1, %dl #, exp
je .L30 #,
.p2align 5
.p2align 4
.p2align 3
.L32:
# c99.c:27: result *= base;
imulq %r8, %rax # base, result
.L30:
# c99.c:30: if (exp == 0)
shrl %edx # exp
je .L31 #,
# c99.c:34: base *= base;
imulq %r8, %r8 # base, base
# c99.c:25: if (exp&1)
testb $1, %dl #, exp
jne .L32 #,
.L50:
# c99.c:29: exp >>= 1;
shrl %edx # exp
# c99.c:34: base *= base;
imulq %r8, %r8 # base, base
# c99.c:25: if (exp&1)
testb $1, %dl #, exp
jne .L32 #,
jmp .L50 #
.p2align 4,,10
.p2align 3
.L31:
# c99.c:59: sum_divisors *= (power(i, step + 1) - 1) / (i - 1);
leaq -1(%r9), %r8 #, _6
# c99.c:59: sum_divisors *= (power(i, step + 1) - 1) / (i - 1);
subq $1, %rax #, _5
# c99.c:59: sum_divisors *= (power(i, step + 1) - 1) / (i - 1);
xorl %edx, %edx # tmp144
# c99.c:60: i += 2;
addq $2, %r9 #, i
# c99.c:59: sum_divisors *= (power(i, step + 1) - 1) / (i - 1);
divq %r8 # _6
# c99.c:59: sum_divisors *= (power(i, step + 1) - 1) / (i - 1);
imulq %rax, %r11 # _27, sum_divisors
# c99.c:51: while (i * i <= n_mut)
movq %r9, %rax # i, powmult_16
imulq %r9, %rax # i, powmult_16
# c99.c:51: while (i * i <= n_mut)
cmpq %rax, %rcx # powmult_16, n_mut
jnb .L27 #,
.L28:
# c99.c:62: if (n_mut > 2)
cmpq $2, %rcx #, n_mut
jbe .L35 #,
# c99.c:64: sum_divisors *= (n_mut * n_mut - 1) / (n_mut - 1);
movq %rcx, %rax # n_mut, powmult_19
# c99.c:64: sum_divisors *= (n_mut * n_mut - 1) / (n_mut - 1);
xorl %edx, %edx # tmp154
# c99.c:64: sum_divisors *= (n_mut * n_mut - 1) / (n_mut - 1);
imulq %rcx, %rax # n_mut, powmult_19
# c99.c:64: sum_divisors *= (n_mut * n_mut - 1) / (n_mut - 1);
subq $1, %rcx #, _10
# c99.c:64: sum_divisors *= (n_mut * n_mut - 1) / (n_mut - 1);
subq $1, %rax #, _9
# c99.c:64: sum_divisors *= (n_mut * n_mut - 1) / (n_mut - 1);
divq %rcx # _10
# c99.c:64: sum_divisors *= (n_mut * n_mut - 1) / (n_mut - 1);
imulq %rax, %r11 # _11, sum_divisors
.L35:
# c99.c:66: return sum_divisors - n;
movq %r11, %rax # sum_divisors, sum_divisors
subq %rbx, %rax # n, sum_divisors
# c99.c:67: }
popq %rbx #
ret
.p2align 4,,10
.p2align 3
.L49:
# c99.c:54: while (n_mut % i == 0)
movl $1, %edx #, exp
jmp .L34 #
.L37:
movl $2, %edx #, base
movl $1, %r11d #, result
jmp .L23 #
.L36:
# c99.c:44: while (n_mut % 2 == 0)
movl $1, %eax #, exp
jmp .L21 #
.seh_endproc
.section .text.startup,"x"
.p2align 4
.globl main
.def main; .scl 2; .type 32; .endef
.seh_proc main
main:
pushq %rdi #
.seh_pushreg %rdi
pushq %rsi #
.seh_pushreg %rsi
pushq %rbx #
.seh_pushreg %rbx
subq $48, %rsp #,
.seh_stackalloc 48
.seh_endprologue
# c99.c:81: for (uint64_t i = 3; i < max_limit; i++)
movl $10000, %edi #, max_limit.2_24
# c99.c:70: {
movl %ecx, %ebx # tmp118, argc
movq %rdx, %rsi # tmp119, argv
call __main #
# c99.c:71: uint64_t max_limit = 10000;
movq $10000, 40(%rsp) #, max_limit
# c99.c:72: if (argc > 1)
cmpl $1, %ebx #, argc
jg .L62 #,
.L54:
# c99.c:70: {
movl $3, %ebx #, i
xorl %esi, %esi # amicable_sum
.p2align 4
.p2align 3
.L58:
# c99.c:83: uint64_t s = sum_of_proper_divisors(i);
movq %rbx, %rcx # i,
call sum_of_proper_divisors #
# c99.c:84: if (s == i)
cmpq %rbx, %rax # i, s
je .L57 #,
# c99.c:88: if (sum_of_proper_divisors(s) == i)
movq %rax, %rcx # s,
call sum_of_proper_divisors #
movq %rax, %rdx #, tmp123
# c99.c:90: amicable_sum += i;
leaq (%rsi,%rbx), %rax #, tmp116
cmpq %rbx, %rdx # i, tmp123
cmove %rax, %rsi # tmp116,, amicable_sum
.L57:
# c99.c:81: for (uint64_t i = 3; i < max_limit; i++)
addq $1, %rbx #, i
# c99.c:81: for (uint64_t i = 3; i < max_limit; i++)
cmpq %rdi, %rbx # max_limit.2_24, i
jne .L58 #,
.L55:
# c99.c:93: printf("%" PRIu64 "\n",amicable_sum);
movq %rsi, %rdx # amicable_sum,
leaq .LC0(%rip), %rcx #, tmp113
call printf.constprop.0 #
# c99.c:95: }
xorl %eax, %eax #
addq $48, %rsp #,
popq %rbx #
popq %rsi #
popq %rdi #
ret
.L62:
# c99.c:74: if (strtouint32_safe(argv[1], &max_limit) == false)
movq 8(%rsi), %rcx # MEM[(char * *)argv_12(D) + 8B], MEM[(char * *)argv_12(D) + 8B]
leaq 40(%rsp), %rdx #, tmp109
call strtouint32_safe #
# c99.c:74: if (strtouint32_safe(argv[1], &max_limit) == false)
testb %al, %al # tmp120
je .L63 #,
# c99.c:81: for (uint64_t i = 3; i < max_limit; i++)
movq 40(%rsp), %rdi # max_limit, max_limit.2_24
xorl %esi, %esi # amicable_sum
cmpq $3, %rdi #, max_limit.2_24
ja .L54 #,
jmp .L55 #
.L63:
# c99.c:76: fprintf(stderr, "Enter a valid integer as first CLI argument or pass no argument to consider a max limit of 10,000");
movl $2, %ecx #,
call *__imp___acrt_iob_func(%rip) #
# c99.c:76: fprintf(stderr, "Enter a valid integer as first CLI argument or pass no argument to consider a max limit of 10,000");
leaq .LC1(%rip), %rdx #, tmp112
# c99.c:76: fprintf(stderr, "Enter a valid integer as first CLI argument or pass no argument to consider a max limit of 10,000");
movq %rax, %rcx # tmp121, _3
# c99.c:76: fprintf(stderr, "Enter a valid integer as first CLI argument or pass no argument to consider a max limit of 10,000");
call fprintf.constprop.0 #
# c99.c:77: exit(1);
movl $1, %ecx #,
call exit #
nop
.seh_endproc
.def __main; .scl 2; .type 32; .endef
.ident "GCC: (GNU) 14.2.0"
.def __mingw_vfprintf; .scl 2; .type 32; .endef
.def strtol; .scl 2; .type 32; .endef
.def exit; .scl 2; .type 32; .endef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment