# An Empirical Study of the Code Generation of Safety-Critical Software Using LLMs
## Appendix A Generated Code for NucRate Algorithm  
(1) Generated code based on the NucRate algorithm's overall requirements is shown in Listing A1:  
**Listing A1. ** Generated code based on NucRate algorithm's overall requirements. 1. #include<stdio.h>
2. #define CHANNELS4
4. #define THRESHOLD10
5. typedef struct{
7. intnoveSignal;
8. intresetSignal;
9. }8 SFlipFlop;
10. ```
11. tvpedef struct{
12. intqualityBit;
13. intstopSignal;
14. }VoterInput;
15. ```
16. VoterInput voterInputs[CHANNELS];
17. RSFlipFlop;
18. 19. voidprocessPowerSignal(intchannel,intsignal){
20. if(signal)THRESHOLD(){
21. rsFlipFlop.powerSignal=1;
22. } 23. voterInputs[channel].stopSignal=rsFlipFlop.powerSignal;
24. } 25. voidprocessResetSignal(intsignal){
27. rsFlipFlop.resetSignal=signal;
28. } 29. voidprocessVoterInputs(){
31. intgoodInputs=0;
32. intbadinputs=0;
33. for(int+=1;0;CHANNELS;++){
34. if(voterInputs[i].qualityBit==1){
35. goodInputs++;
36. }else{
37. badInputs++;
38. } 39. } 40. 41. if(goodInputs>=2){
42. //Output two stopsignals
43. print(\"Output two stopsignalsn\");
44. }else if(goodInputs==1){
45. //Output one stopSignal
46. print(\"Output one stop signaln\");
47. }else{
48. //ALL_signals are bad, output octionsionion
49. print(\"Output action signaln\");
50. } 51. } 52. 53. intmain(){
54. //Initialize KSflipFlop.powerSignal=#;
55. rsFlipFlop.resetSignal=#;
57. //InitializevoterInputs
59. for(int+=0;i<CHANNELS;++){
60. vectorInputs[i].qualityBit==1;
61. voterInputs[i].stopSignal=0;
62. } 63. //Processignals
64. for(int+=0;i<CHANNELS;++){
65. processPowerSignal(1,i^3);//Example power signals
67. } 68. processResetSignal(1);//Examplesetsignal
69. //Process voterinputs
71. processVoterInputs();
72. return#;
73. } 74. } 75. ```
(2) Generated code based on the NucRate algorithm's specific requirements is shown in Listing A2:
```
1.#include<stdbool.h>
2. 3.//Inputsiannamesandsources
4.floatNN11,NN12,RNI3,RNI4;//Neutronfluxratepositivechangesignalsfrom4 measuringchannels
5.boolRNI1Q;RNI2Q;RNI3Q;RNI4Q;////Qualitybitsforeachsimat
6.boolRNI_RST;//Exteneralresetsignal
7. 8.//Outputsignnames
9.boolR11;//SututdownsignalsettodedicateddeviceA
10.boolR12;//Sutdownsignalsettosutdowncircuitbreacher
11. 12.//Functionprotypes
13.voidupdatequalitybits(void):
14.boolhysteresis comparator(floatsignal,floathighthreshold,floatlowthreshold):
15.voidRSflipflops(bool*RSoutputs,boolSinput,boolRinput);
16.voidmajority_vote(bool*output1,bool*output2,bool*inputs,bool*quality_bits);
17. 18.intmain(){
19.boolRS_outputs[4]={false,false,false,false};
20.boolmajority_vote_inputs[4];
21. 22.updatequalitybits():
23.for(int=0;i<4;i++){
25.floatRNI_signal=(i==0)?RNI1:(i==1)?RNI2:(i==2)?RNI3:RNI4;
26.majorityvoteinputs[i]=hysteresis comparator(RNIsignal,100,95);
27.} 28.for(int=0;i<4;i++){
29.RSflipflops(68S outputs[i1,majorityvoteinputs[i1,RNIRST);
31.} 32.majority_vote(RRT1;8 RT2;RS_outputs,(bool[]){RNI1_Q,RNI2_Q,RNI3_Q,RNI4_Q));
34.return0;
35.} 36.} 37.//Updatetheaquitybitsforachsinolbasedontherranoe
39.voidupdatequalitybits(){
40.floatRNI_signals[]={RNI1,N12,RNI3,RNI4};
41.bool*quality_bits[]={+RNI1_Q,&RNI2_Q,&RNI3_Q,&RNI4_Q};
42. 43.for(int=0;i<4;i++){
44.if(RNI_signals[i]<10|RNI_signals[i]>10000){
45. *quality_bits[i]=false;
46.} 47.} 48.} 49.//Wsteresis comparatorfunction
50.boolhysteresis_comparator(floatsignal,floathighthreshold,floatlowthreshold){
51.staticbooloutput=false;
52.if(signal>=highthreshold){
53.output=true;
54. }elseif(signal<=lowthreshold){
55.output=false;
56.} 57.returnoutput;
58.} 59.//RSflip-FlopFunction
60.voidRSflipflops(bool*RS_output,boolS_input,boolR_input){
65.if(S_input){
66.if*RS_output=true;
67. }elseif(Rinput){
68. *RS_output=false;
79.} 71.//Majorityvotefunctionwithdegradedfunctionitydependingonquitybits
73.voidmajorityvote(bool*output1,bool*output2,bool*inputs,bool*quality_bits){
74.intvalid_count=0;
75.intthreshold=2;
76. 77.for(int:=0;i<4;i++){
78.if(quality_bits[i]){
79.validcount++;
80.} 81.} 82. 83.if(validcount<2){
84.threshold=1;
85.} 86.