Last active
August 29, 2015 14:11
-
-
Save iccir/b243c30b593c80808c53 to your computer and use it in GitHub Desktop.
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
// 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