-
-
Save rightfold/6cde0585de86ea332650 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
#include <stdint.h> | |
#include <stdio.h> | |
int method(char const* str) { | |
if (*(uint32_t const*)str == *(uint32_t const*)"GET ") return 0; | |
if (*(uint32_t const*)str == *(uint32_t const*)"POST") return 1; | |
if (*(uint32_t const*)str == *(uint32_t const*)"PUT ") return 2; | |
if (*(uint32_t const*)str == *(uint32_t const*)"DELE") return 3; | |
if (*(uint32_t const*)str == *(uint32_t const*)"PATC") return 4; | |
return -1; | |
} | |
int main() { | |
printf("%d\n", method("GET ")); | |
printf("%d\n", method("POST ")); | |
printf("%d\n", method("PUT ")); | |
printf("%d\n", method("DELETE ")); | |
printf("%d\n", method("PATCH ")); | |
printf("%d\n", method("OTHER ")); | |
return 0; | |
} |
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
.section __TEXT,__text,regular,pure_instructions | |
.globl _method | |
.align 4, 0x90 | |
_method: ## @method | |
.cfi_startproc | |
## BB#0: | |
pushq %rbp | |
Ltmp2: | |
.cfi_def_cfa_offset 16 | |
Ltmp3: | |
.cfi_offset %rbp, -16 | |
movq %rsp, %rbp | |
Ltmp4: | |
.cfi_def_cfa_register %rbp | |
movl (%rdi), %ecx | |
cmpl $1414745935, %ecx ## imm = 0x54534F4F | |
ja LBB0_6 | |
## BB#1: | |
cmpl $1162626371, %ecx ## imm = 0x454C4543 | |
ja LBB0_9 | |
## BB#2: | |
xorl %eax, %eax | |
cmpl $542393671, %ecx ## imm = 0x20544547 | |
je LBB0_12 | |
## BB#3: | |
cmpl $542397776, %ecx ## imm = 0x20545550 | |
jne LBB0_4 | |
## BB#8: | |
movl $2, %eax | |
popq %rbp | |
ret | |
LBB0_6: | |
cmpl $1414745936, %ecx ## imm = 0x54534F50 | |
jne LBB0_11 | |
## BB#7: | |
movl $1, %eax | |
popq %rbp | |
ret | |
LBB0_9: | |
cmpl $1162626372, %ecx ## imm = 0x454C4544 | |
jne LBB0_11 | |
## BB#10: | |
movl $3, %eax | |
popq %rbp | |
ret | |
LBB0_4: | |
cmpl $1129595216, %ecx ## imm = 0x43544150 | |
jne LBB0_11 | |
## BB#5: | |
movl $4, %eax | |
popq %rbp | |
ret | |
LBB0_11: | |
movl $-1, %eax | |
LBB0_12: | |
popq %rbp | |
ret | |
.cfi_endproc | |
.globl _main | |
.align 4, 0x90 | |
_main: ## @main | |
.cfi_startproc | |
## BB#0: | |
pushq %rbp | |
Ltmp8: | |
.cfi_def_cfa_offset 16 | |
Ltmp9: | |
.cfi_offset %rbp, -16 | |
movq %rsp, %rbp | |
Ltmp10: | |
.cfi_def_cfa_register %rbp | |
pushq %rbx | |
pushq %rax | |
Ltmp11: | |
.cfi_offset %rbx, -24 | |
leaq L_.str5(%rip), %rbx | |
movq %rbx, %rdi | |
xorl %esi, %esi | |
xorb %al, %al | |
callq _printf | |
movq %rbx, %rdi | |
movl $1, %esi | |
xorb %al, %al | |
callq _printf | |
movq %rbx, %rdi | |
movl $2, %esi | |
xorb %al, %al | |
callq _printf | |
movq %rbx, %rdi | |
movl $3, %esi | |
xorb %al, %al | |
callq _printf | |
movq %rbx, %rdi | |
movl $4, %esi | |
xorb %al, %al | |
callq _printf | |
movq %rbx, %rdi | |
movl $-1, %esi | |
xorb %al, %al | |
callq _printf | |
xorl %eax, %eax | |
addq $8, %rsp | |
popq %rbx | |
popq %rbp | |
ret | |
.cfi_endproc | |
.section __TEXT,__cstring,cstring_literals | |
L_.str5: ## @.str5 | |
.asciz "%d\n" | |
.subsections_via_symbols |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment