# An Empirical Study of the Code Generation of Safety-Critical Software Using LLMs
## Appendix A Generated Code for NucRate Algorithm
CC Commands command;
16. float speed;
17. float accel;
18. float brake;
19. } CC Input;
20. 21. //Outputsignalnames
22. typedefstruct{
23. float cruise.speed;
24. bool throttle_cmd;
25. enum{CS_OFF,CS_ON,CS_STDBY,CS_INT} cruise_state;
26. } CC_Output;
27. 28. //Function prototypes
29. void cruise control(CC Inputinput,CC Output Output);
30. void cruise.speed_management(CC_InputInput,CC_OutputOutput);
31. void car driving control(CC Inputinput,CC_OutputOutput);
32. void pedals_pressed_detection(CC_Inputinput,CC_OutputOutput);
33. 34. intmain(){
35. CC Input input;
36. CC Output output;
37. 38. //Updateinputsignshere
39. 39. 40. cruise_control(input,&output);
41. 42. return0;
43. 44. 45. //Maincrisecontrolfunction
46. void cruise.control(CC_Inputinput,CC_OutputOutput){
47. cruise_speed_management(input,output);
48. car_driving_control(input,output);
49. pedals pressed detection(input,output);
50. } 51. 52. //Cruisespeedmanagementfunctionality
53. void cruise.speed_management(CC_InputInput,CC_OutputOutput){
54. const float SpeedMin=30.0;
55. const float SpeedMax=150.0;
56. const float SpeedInc=2.5;
57. 58. if(output-cruise state==CS ON|output->cruise state==CS STDBY|||
59. if(input.command==CC_SET){
60. output->cruise_speed=input,speed;
61. else if(input.command==CC_QUICK_ACCEL){
62. output->cruise speed=(output->cruise speed+SpeedInc<=SpeedMax)? 63. }elseif(input.command==CC QUICKDECEL){
64. output->cruise_speed=(output->cruise_speed-SpeedInc>=SpeedMin)? 65. } 66. } 67. } ```

**Algorithm 1**Catalog-Based on CruiseControl's specific requirements. 68. //Cardivingcontrolfunctionity
69. voidcar_driving_control(CC_Inputinput,CC_Output*output){
70. constFloatKm=8.113;
71. const floatKm=9.5;
72. constFloatThrotilesatMax=45.0;
73. //Implementtheproportionalandfineralatorithmhere;usingKmandKlfactors
75. //Limitthethrottle commandtoThrottleSatMaxtoensurecomfortduring//automaticregulation
77. if(output->throttlecmd>ThrottleSatMax){
78. output->throttle_cmd=ThrottleSatMax;
79. } 80. } 81. //Pedotspresseddetectionfunction(ity
83. voidpedals_presseddetection(CC_Inputinput,CC_Output*output){
84. constfloatPedalsMin=3.0;
85. boolaccelpressed=input.accel>PedalsMin;
87. boolbrake_pressed=input.brake>PedalsMin;
88. //UpdateCruiseStatebasedonpedalpressesandCC commands
90. switch(input.command){
91. caseCC:ff;
92. output->cruise_state=CS_OFF;
93. break;
94. caseCC:un;
95. output->cruise_state=CS_ON;
96. break;
97. caseCCRESUME:
98. if(lacedpressed<=(input.speed>=30.0&&input.speed<=150.0)){
99. output->cruise_state=CS_ON;
100. }else{
101. output->cruise_state=CS_STDRY;
102. } 103. break;
104. default;
105. break;
106. } 107. if(brakepressed){
109. output->cruise_state=CS_INT;
110. }elseif(accelpressed||input.speed<30.0||input.speed>150.0){
111. output->cruise_state=CS_STDRY;
112. }elseif(laced_pressed<=63(input.speed>=30.0&&input.speed<=150.0)){
113. output->cruise_state=CS_ON;
114. } 115. } 3 Generated code based on software requirements through augmented prompt is shown in Listing A6:```
1. #include<stdbool.h>
2. #include<stdint.h>
3. //Constomsfor cruisecontrolsystem
5. #defineSPEED_MIN38.of> ////minimum cruisespeed
6. #defineSPEED_MAX350.of> //Maximum cruisespeed
7. #defineSPEED_INC2.5f> //Speed increment/decrement for quickacct/decet. 8. #defineVP.8113f> //Proportionalain
9. #defineK1.5f> //Intercaption
10. #defineTHMOTTLE_SAT_MAX45.0f> //Maximum throttle saturation value
11. #definePEDALSMIN3.0f> //Minimumpedal value to detect pedol press
12. //Cruisestate enumfordifferent cruisecontrolstates
14.typedeffrom
15. {
16. #CUISE OFF, //Cruisecontrolisoff
17. #CUISE_ON, //Cruisecontrolisonandactive
18. #CUISE_STOSY, //Cruisecontrolisonstandby
19. #CUISEINT //Cruisecontrolisinternouredbybrake pedol
20. } CruiseState;
21. //Cru drivingcontrolfunctioncalcutotes throttle commandbasedonspeed errorand//intercapt
22. {
23. *staticfloatcar drivingcontrol(floatspeederror,float*integral;boolison, boolis_saturated)
24. {
25. {
26. {
27. //Resetintegralwhen cruisecontrolisoff
28. *integral=0.0f;
29.  return0;
30. } 31. } 32. {
33. {
34.