// 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 ( *P384Element) ( *P384Element) *P384Element {
	// Inversion is implemented as exponentiation with exponent p − 2.
	// The sequence of 15 multiplications and 383 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
	//	x24     = x12 << 12 + x12
	//	x30     = x24 << 6 + _111111
	//	x31     = 2*x30 + 1
	//	x32     = 2*x31 + 1
	//	x63     = x32 << 31 + x31
	//	x126    = x63 << 63 + x63
	//	x252    = x126 << 126 + x126
	//	x255    = x252 << 3 + _111
	//	i397    = ((x255 << 33 + x32) << 94 + x30) << 2
	//	return    1 + i397
	//

	var  = new(P384Element).Set()
	var  = new(P384Element)
	var  = new(P384Element)
	var  = new(P384Element)
	var  = new(P384Element)

	.Square()
	.Mul(, )
	.Square()
	.Mul(, )
	.Square()
	for  := 1;  < 3; ++ {
		.Square()
	}
	.Mul(, )
	.Square()
	for  := 1;  < 6; ++ {
		.Square()
	}
	.Mul(, )
	.Square()
	for  := 1;  < 12; ++ {
		.Square()
	}
	.Mul(, )
	for  := 0;  < 6; ++ {
		.Square()
	}
	.Mul(, )
	.Square()
	.Mul(, )
	.Square()
	.Mul(, )
	.Square()
	for  := 1;  < 31; ++ {
		.Square()
	}
	.Mul(, )
	.Square()
	for  := 1;  < 63; ++ {
		.Square()
	}
	.Mul(, )
	.Square()
	for  := 1;  < 126; ++ {
		.Square()
	}
	.Mul(, )
	for  := 0;  < 3; ++ {
		.Square()
	}
	.Mul(, )
	for  := 0;  < 33; ++ {
		.Square()
	}
	.Mul(, )
	for  := 0;  < 94; ++ {
		.Square()
	}
	.Mul(, )
	for  := 0;  < 2; ++ {
		.Square()
	}
	.Mul(, )

	return .Set()
}