Skip to content

Instantly share code, notes, and snippets.

@bdonlan
Created May 20, 2009 01:53
Show Gist options
  • Save bdonlan/114562 to your computer and use it in GitHub Desktop.
Save bdonlan/114562 to your computer and use it in GitHub Desktop.
#include <limits.h>
#include <stdlib.h>
size_t tmul(int x, int y) {
long long tv = (long long)x * (long long)y;
if (tv < 0 || tv > UINT_MAX)
return -1;
return tv;
}
.file "test2.c"
.text
.p2align 4,,15
.globl tmul
.type tmul, @function
tmul:
pushl %ebp
movl $-1, %ecx
movl %esp, %ebp
movl 12(%ebp), %eax
imull 8(%ebp)
cmpl $0, %edx
ja .L3
movl %eax, %ecx
.L3:
movl %ecx, %eax
popl %ebp
ret
.size tmul, .-tmul
.ident "GCC: (Ubuntu 4.3.3-5ubuntu4) 4.3.3"
.section .note.GNU-stack,"",@progbits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment