# An Empirical Study of the Code Generation of Safety-Critical Software Using LLMs
## Appendix A Generated Code for NucRate Algorithm
87.intactiveinputs=g;
88.for(inti=g;i<4;i++){
89.if(inputsi1|8:qualitybits[i1]){
90.active_inputs++;
91.} 92.} 93. 94.if(active_inputs>=threshold){
95.\"output=true;
96.\"output=true;
97. }else{
98.\"output=false;
99.\"output2=false;
100.} 101.} 102. (3)Generated code based on software requirements through augmented prompt is shown in Listing A3:  
**Listing A3. ** Generated code based on NucRate algorithm's requirements through augmented prompt. 1. #include<stdbool.h> //Forbooleantype
2.#include<stdint.h> //ForuintRtype
3. 4.//Constants for input range validation
5.defineUPPER LIMIT(10000.0f) //UpperLimitforinputsignal
6.#defineLOWER LIMIT(10.0f) //LowerLimitforinputsignal
7. 8.//Hysteresisthreshoids
9.#defineHSTERESIGHTHRESHU (100.0f) //Highthresholdforhysteresis
10.defineHSTERESIGHUMTHRESHU (95.0f) //Lowthresholdforhysteresis
11. 12.//Function prototypes
13.staticboolhysteresisThresholdComparator(floatinput,float*previousoutput):
14.staticvoidrsIfempty[boolset,boolreset,bool\"output):
15.staticboolfourToToWe  
40.//Comparator that applies hysteresis to an input signal. 41.Static bool hysteresisThisholdComparator(Floatinput,float*previous_output){
42.//if input is above the high threshold, signal is on
43.if (input*hysteresisIS_HIGH_THRESHOLD){
44.\"previous_output=input;
45.\"returntrue;
46.} 47.//If input drops below low threshold and was previous\(\upsilon\) above it. signal is off
48.if (input*HysteresisIS_LOWTHRESHOLD 88*previous_output*hysteresisIS_LOWTHRESHOLD){
49.\"previous_output=input;
50.\"returnfalse;
51.} 52.//Return the Lost known state if thresholds are not crossed
53.return*\"previous_output*hysteresisIS_LOWTHRESHOLD;
54.} 55.//Res flip-Flop logic to an input signal. 57.staticvoidrsfFlipFlop(bool set,bool reset, bool*output){
58.if (set){
59.\"output=true;//Set output to true if set signal.is received
60. }elseif(reset){
61.\"output=false;//Reset output to false ifreset signal.is received
62.} 63.//If  
**Listing A4**. Generated code based on CruiseControl's overall requirements. 1. **Rinclude<stdio.h>**
2. 3. //CCparameters
4. **#defineMIN_SPEED_20
5. **#defineMAX_SPEED_120
6. **#defineSPEED_INCRHENT**
7. **#defineMAX_THROTTLE_SATURATION_100
8. **#defineMIN_PEBAL_PRESS_DETECTION_10
9. 10. //CCstates
11. **enumCCState{OFF,ON,STDSY}**;
12. 13. //CCvariables
14. **intruiseSpeed=0**;
15. **inten**?Speed=0**;
16. **int throttlcCommand=0**;
17. **enumCCstate**ccstate=OFF**;
18. **int acceleratorPredal=0**;
19. **intbravePedal=0**;
20. **intbravePedal=0**;
21. //_FunctiontoupdateCCstate_
22. **void**updatecState(){
23. **if**(ccState=OFF){
24. **if**(carSpeed>=MIN_SPEED&&carSpeed<=MAX_SPEED&&acceleratorPedal<
25. **MIN_PEAL_PRESS_DETECTION){
26. **ccState=ON**;
27. **cruisSpeed=carSpeed;
28. }**elseif**(ccState=ON){
30. **if**(acceleratorPredal>=MIN_PEDAL_PRESS_DETECTION|carSpeed<MINSPEED|
31. **ccState=STDSY;
32. **elseif**(parkePedal>=MIN_PEDAL_PRESS_DETECTION){
33. }**ccState=OFF;
34. }**elseif**(ccState==STDSY){
35. **if**(acceleratorPedal<MIN_PEDAL_PRESS_DETECTION&&carSpeed>=MIN_SPEED&&
37. **ccState=ON;
38. }**
39. } 40. } 41. //_FunctiontoupdatethrottlcCommand_
43. **void**updateThrottlcCommand_
44. **if**(ccState=ON){
45. **throttlcCommand=(_cruisSpeed-carSpeed)*MAX_THROTTLE_SATURATION/(MAXSPEED
46. **if**(throttlcCommand>MAX_THROTTLE_SATURATION){
47. **throttlcCommand=MAX_THROTTLE_SATURATION;
48. }**else{
50. **throttlcCommand=0**;
51. } 52. } 53. //_Nationfunction_
55. **intmain**(){
56. //_Simuote cardand driver actions_
57. **carSpeed=50**;
58. **acceleratorPedal=0**;
59. **bravePedal=0**;
60. **updateCCState(){
61. **updateThrottlcCommand**;
62. **print**(\"CCState:**3d, CruiseSpeed:**3d,**ThrottlcCommand:**3d\
\",ccState,**cruiseSpeed,**throttlcCommand);
63. **return0**;
64. } (2) **Generated code based on CruiseControl's specific requirements is shown in Listing A5:**```
1. #include<stdbool.h>
2. #include<stddef.h>
3. 4. //Inputsignalnamesandsources
5. typedefenum{
6. CC OFF,
7. CC ON,
8. CC RESUME,
9. CC-SET,
10. CC-QUICK_DECEL,
11. CC-QUICK_ACCEL
12. } CC Commands;
13. 14. typedefstruct{
15.