1. A method for control flow graph flattening of a function of software code, the function comprising a plurality of basic blocks each having an address and at least one instruction, the method, performed by a processor of a device, comprising: inserting a jump table associating a label of each basic block with the address of the basic block; inserting a coefficient array comprising constant coefficients for each of the plurality of basic blocks; inserting a dispatcher basic block comprising instructions to look up an address in the jump table and to jump to the address; replacing a jump terminal instruction by a jump to the dispatcher basic block in each of the plurality of basic blocks; inserting at least one lookup function in each of the plurality of basic blocks, each lookup function returning, depending on at least an index of the basic block, a derived value based on a constant coefficient from the coefficient array, each constant coefficient; inserting a first branch function and a second branch function, wherein the first branch function calculates the label of a subsequent basic block based on at least the derived value and the label of the present basic block, and wherein the second branch function calculates the index of the subsequent basic block based on the index of the present basic block; and inserting a transition function into the dispatcher basic block, the transition function obtaining the address in the jump table based on at least the label of a subsequent basic block.