// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Code generated by addchain. DO NOT EDIT.

package fiat

// Invert sets e = 1/x, and returns e.
//
// If x == 0, Invert returns e = 0.
func ( *P256Element) ( *P256Element) *P256Element {
	// Inversion is implemented as exponentiation with exponent p − 2.
	// The sequence of 12 multiplications and 255 squarings is derived from the
	// following addition chain generated with github.com/mmcloughlin/addchain v0.4.0.
	//
	//	_10     = 2*1
	//	_11     = 1 + _10
	//	_110    = 2*_11
	//	_111    = 1 + _110
	//	_111000 = _111 << 3
	//	_111111 = _111 + _111000
	//	x12     = _111111 << 6 + _111111
	//	x15     = x12 << 3 + _111
	//	x16     = 2*x15 + 1
	//	x32     = x16 << 16 + x16
	//	i53     = x32 << 15
	//	x47     = x15 + i53
	//	i263    = ((i53 << 17 + 1) << 143 + x47) << 47
	//	return    (x47 + i263) << 2 + 1
	//

	var  = new(P256Element).Set()
	var  = new(P256Element)
	var  = new(P256Element)

	.Square()
	.Mul(, )
	.Square()
	.Mul(, )
	.Square()
	for  := 1;  < 3; ++ {
		.Square()
	}
	.Mul(, )
	.Square()
	for  := 1;  < 6; ++ {
		.Square()
	}
	.Mul(, )
	for  := 0;  < 3; ++ {
		.Square()
	}
	.Mul(, )
	.Square()
	.Mul(, )
	.Square()
	for  := 1;  < 16; ++ {
		.Square()
	}
	.Mul(, )
	for  := 0;  < 15; ++ {
		.Square()
	}
	.Mul(, )
	for  := 0;  < 17; ++ {
		.Square()
	}
	.Mul(, )
	for  := 0;  < 143; ++ {
		.Square()
	}
	.Mul(, )
	for  := 0;  < 47; ++ {
		.Square()
	}
	.Mul(, )
	for  := 0;  < 2; ++ {
		.Square()
	}
	.Mul(, )

	return .Set()
}