Skip to content

Instantly share code, notes, and snippets.

@iccir
Last active August 29, 2015 14:11
Show Gist options
  • Save iccir/b243c30b593c80808c53 to your computer and use it in GitHub Desktop.
Save iccir/b243c30b593c80808c53 to your computer and use it in GitHub Desktop.
// Input
void a() {
NSNumber *n = @42;
(void)n;
}
void b() {
NSNumber *n = [[NSNumber alloc] initWithInt:42];
(void)n;
}
void c() {
NSNumber *n = [NSNumber numberWithInt:42];
(void)n;
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
a();
b();
c();
}
return 0;
}
// Psuedocode of Compiler Output
void _a() {
rax = [NSNumber numberWithInt:0x2a];
rax = [rax retain];
rax = [rax release];
return;
}
void _b() {
rbx = *objc_msgSend;
rax = [NSNumber alloc];
rax = [rax initWithInt:0x2a];
rax = [rax release];
return;
}
void _c() {
rax = [NSNumber numberWithInt:0x2a];
rax = [rax retain];
rax = [rax release];
return;
}
// Psuedocode of +[NSNumber numberWithInt:]
void * +[NSNumber numberWithInt:](void * self, void * _cmd, int arg2) {
rdi = self;
LODWORD(rbx) = LODWORD(arg2);
if (*___NSNumberTaggedClass != rdi) {
r14 = *objc_msgSend;
rdi = [[rdi allocWithZone:0x0] initWithInt:LODWORD(rbx)];
rax = [rdi autorelease];
}
else {
rax = 0xb000000000000002 | 0xffffffffffffff0 & sign_extend_64(LODWORD(rbx)) << 0x4;
return rax;
}
return rax;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment