; LLVM IR from whoiswelliton/Computer_Engineering_UTFPR-PB :: Embedded_Systems/TIVA Connected TM4C1294XL Projects (CLIProcessCommand)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.xCOMMAND_INPUT_LIST = type { ptr, ptr }
%struct.xCOMMAND_LINE_INPUT = type { ptr, ptr, ptr, i8 }

@xRegisteredCommands = external hidden global %struct.xCOMMAND_INPUT_LIST, align 8
@FreeRTOS_CLIProcessCommand.pxCommand = external hidden global ptr, align 8
@.str = external hidden unnamed_addr constant [88 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local i64 @FreeRTOS_CLIProcessCommand(ptr noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 1, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %10 = load ptr, ptr @FreeRTOS_CLIProcessCommand.pxCommand, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %72

12:                                               ; preds = %3
  store ptr @xRegisteredCommands, ptr @FreeRTOS_CLIProcessCommand.pxCommand, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %67, %12
  %14 = load ptr, ptr @FreeRTOS_CLIProcessCommand.pxCommand, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %71

16:                                               ; preds = %13
  %17 = load ptr, ptr @FreeRTOS_CLIProcessCommand.pxCommand, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.xCOMMAND_INPUT_LIST, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = getelementptr inbounds %struct.xCOMMAND_LINE_INPUT, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  store ptr %21, ptr %8, align 8, !tbaa !5
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = call i64 @strlen(ptr noundef %22) #5
  store i64 %23, ptr %9, align 8, !tbaa !9
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load i64, ptr %9, align 8, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %24, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !15
  %28 = sext i8 %27 to i32
  %29 = icmp eq i32 %28, 32
  br i1 %29, label %37, label %30

30:                                               ; preds = %16
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i64, ptr %9, align 8, !tbaa !9
  %33 = getelementptr inbounds i8, ptr %31, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !15
  %35 = sext i8 %34 to i32
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %66

37:                                               ; preds = %30, %16
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = load i64, ptr %9, align 8, !tbaa !9
  %41 = call i32 @strncmp(ptr noundef %38, ptr noundef %39, i64 noundef %40) #5
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %65

43:                                               ; preds = %37
  %44 = load ptr, ptr @FreeRTOS_CLIProcessCommand.pxCommand, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.xCOMMAND_INPUT_LIST, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !11
  %47 = getelementptr inbounds %struct.xCOMMAND_LINE_INPUT, ptr %46, i32 0, i32 3
  %48 = load i8, ptr %47, align 8, !tbaa !16
  %49 = sext i8 %48 to i32
  %50 = icmp sge i32 %49, 0
  br i1 %50, label %51, label %64

51:                                               ; preds = %43
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = call signext i8 @prvGetNumberOfParameters(ptr noundef %52)
  %54 = sext i8 %53 to i32
  %55 = load ptr, ptr @FreeRTOS_CLIProcessCommand.pxCommand, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.xCOMMAND_INPUT_LIST, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !11
  %58 = getelementptr inbounds %struct.xCOMMAND_LINE_INPUT, ptr %57, i32 0, i32 3
  %59 = load i8, ptr %58, align 8, !tbaa !16
  %60 = sext i8 %59 to i32
  %61 = icmp ne i32 %54, %60
  br i1 %61, label %62, label %63

62:                                               ; preds = %51
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %63

63:                                               ; preds = %62, %51
  br label %64

64:                                               ; preds = %63, %43
  br label %71

65:                                               ; preds = %37
  br label %66

66:                                               ; preds = %65, %30
  br label %67

67:                                               ; preds = %66
  %68 = load ptr, ptr @FreeRTOS_CLIProcessCommand.pxCommand, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.xCOMMAND_INPUT_LIST, ptr %68, i32 0, i32 1
  %70 = load ptr, ptr %69, align 8, !tbaa !17
  store ptr %70, ptr @FreeRTOS_CLIProcessCommand.pxCommand, align 8, !tbaa !5
  br label %13, !llvm.loop !18

71:                                               ; preds = %64, %13
  br label %72

72:                                               ; preds = %71, %3
  %73 = load ptr, ptr @FreeRTOS_CLIProcessCommand.pxCommand, align 8, !tbaa !5
  %74 = icmp ne ptr %73, null
  br i1 %74, label %75, label %82

75:                                               ; preds = %72
  %76 = load i64, ptr %7, align 8, !tbaa !9
  %77 = icmp eq i64 %76, 0
  br i1 %77, label %78, label %82

78:                                               ; preds = %75
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = load i64, ptr %6, align 8, !tbaa !9
  %81 = call ptr @strncpy(ptr noundef %79, ptr noundef @.str, i64 noundef %80) #4
  store ptr null, ptr @FreeRTOS_CLIProcessCommand.pxCommand, align 8, !tbaa !5
  br label %104

82:                                               ; preds = %75, %72
  %83 = load ptr, ptr @FreeRTOS_CLIProcessCommand.pxCommand, align 8, !tbaa !5
  %84 = icmp ne ptr %83, null
  br i1 %84, label %85, label %99

85:                                               ; preds = %82
  %86 = load ptr, ptr @FreeRTOS_CLIProcessCommand.pxCommand, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.xCOMMAND_INPUT_LIST, ptr %86, i32 0, i32 0
  %88 = load ptr, ptr %87, align 8, !tbaa !11
  %89 = getelementptr inbounds %struct.xCOMMAND_LINE_INPUT, ptr %88, i32 0, i32 2
  %90 = load ptr, ptr %89, align 8, !tbaa !20
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = load i64, ptr %6, align 8, !tbaa !9
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  %94 = call i64 %90(ptr noundef %91, i64 noundef %92, ptr noundef %93)
  store i64 %94, ptr %7, align 8, !tbaa !9
  %95 = load i64, ptr %7, align 8, !tbaa !9
  %96 = icmp eq i64 %95, 0
  br i1 %96, label %97, label %98

97:                                               ; preds = %85
  store ptr null, ptr @FreeRTOS_CLIProcessCommand.pxCommand, align 8, !tbaa !5
  br label %98

98:                                               ; preds = %97, %85
  br label %103

99:                                               ; preds = %82
  %100 = load ptr, ptr %5, align 8, !tbaa !5
  %101 = load i64, ptr %6, align 8, !tbaa !9
  %102 = call ptr @strncpy(ptr noundef %100, ptr noundef @.str.1, i64 noundef %101) #4
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %103

103:                                              ; preds = %99, %98
  br label %104

104:                                              ; preds = %103, %78
  %105 = load i64, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret i64 %105
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strncmp(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden signext i8 @prvGetNumberOfParameters(ptr noundef) #1

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind willreturn memory(read) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"xCOMMAND_INPUT_LIST", !6, i64 0, !6, i64 8}
!13 = !{!14, !6, i64 0}
!14 = !{!"xCOMMAND_LINE_INPUT", !6, i64 0, !6, i64 8, !6, i64 16, !7, i64 24}
!15 = !{!7, !7, i64 0}
!16 = !{!14, !7, i64 24}
!17 = !{!12, !6, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!14, !6, i64 16}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.xCOMMAND_INPUT_LIST = type { ptr, ptr }

@xRegisteredCommands = external hidden global %struct.xCOMMAND_INPUT_LIST, align 8
@FreeRTOS_CLIProcessCommand.pxCommand = external hidden local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [88 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @FreeRTOS_CLIProcessCommand(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr @FreeRTOS_CLIProcessCommand.pxCommand, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %.preheader, label %..thread.thread_crit_edge

..thread.thread_crit_edge:                        ; preds = %3
  %.pre = load ptr, ptr %4, align 8, !tbaa !9
  br label %.thread.thread

.preheader:                                       ; preds = %3
  store ptr @xRegisteredCommands, ptr @FreeRTOS_CLIProcessCommand.pxCommand, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %.preheader, %19
  %.pr = phi ptr [ @xRegisteredCommands, %.preheader ], [ %21, %19 ]
  %7 = load ptr, ptr %.pr, align 8, !tbaa !9
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %8) #3
  %10 = getelementptr inbounds i8, ptr %0, i64 %9
  %11 = load i8, ptr %10, align 1, !tbaa !13
  switch i8 %11, label %19 [
    i8 32, label %12
    i8 0, label %12
  ]

12:                                               ; preds = %6, %6
  %13 = tail call i32 @strncmp(ptr noundef nonnull %0, ptr noundef %8, i64 noundef %9) #3
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %19

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %7, i64 24
  %17 = load i8, ptr %16, align 8, !tbaa !14
  %18 = icmp sgt i8 %17, -1
  br i1 %18, label %22, label %.thread.thread

19:                                               ; preds = %6, %12
  %20 = getelementptr inbounds i8, ptr %.pr, i64 8
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  store ptr %21, ptr @FreeRTOS_CLIProcessCommand.pxCommand, align 8, !tbaa !5
  %.not = icmp eq ptr %21, null
  br i1 %.not, label %.thread.thread26, label %6, !llvm.loop !16

22:                                               ; preds = %15
  %23 = tail call signext i8 @prvGetNumberOfParameters(ptr noundef nonnull %0)
  %24 = load ptr, ptr @FreeRTOS_CLIProcessCommand.pxCommand, align 8, !tbaa !5
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %25, i64 24
  %27 = load i8, ptr %26, align 8, !tbaa !14
  %.not24.not = icmp eq i8 %23, %27
  br i1 %.not24.not, label %.thread.thread, label %28

28:                                               ; preds = %22
  %29 = tail call ptr @strncpy(ptr noundef %1, ptr noundef nonnull @.str, i64 noundef %2) #4
  store ptr null, ptr @FreeRTOS_CLIProcessCommand.pxCommand, align 8, !tbaa !5
  br label %37

.thread.thread:                                   ; preds = %15, %..thread.thread_crit_edge, %22
  %30 = phi ptr [ %.pre, %..thread.thread_crit_edge ], [ %25, %22 ], [ %7, %15 ]
  %31 = getelementptr inbounds i8, ptr %30, i64 16
  %32 = load ptr, ptr %31, align 8, !tbaa !18
  %33 = tail call i64 %32(ptr noundef %1, i64 noundef %2, ptr noundef %0) #4
  %34 = icmp eq i64 %33, 0
  br i1 %34, label %35, label %37

35:                                               ; preds = %.thread.thread
  store ptr null, ptr @FreeRTOS_CLIProcessCommand.pxCommand, align 8, !tbaa !5
  br label %37

.thread.thread26:                                 ; preds = %19
  %36 = tail call ptr @strncpy(ptr noundef %1, ptr noundef nonnull @.str.1, i64 noundef %2) #4
  br label %37

37:                                               ; preds = %.thread.thread26, %35, %.thread.thread, %28
  %.1 = phi i64 [ 0, %28 ], [ 0, %35 ], [ %33, %.thread.thread ], [ 0, %.thread.thread26 ]
  ret i64 %.1
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strncmp(ptr nocapture noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden signext i8 @prvGetNumberOfParameters(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #2

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nofree nounwind willreturn memory(argmem: read) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind willreturn memory(read) }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"xCOMMAND_INPUT_LIST", !6, i64 0, !6, i64 8}
!11 = !{!12, !6, i64 0}
!12 = !{!"xCOMMAND_LINE_INPUT", !6, i64 0, !6, i64 8, !6, i64 16, !7, i64 24}
!13 = !{!7, !7, i64 0}
!14 = !{!12, !7, i64 24}
!15 = !{!10, !6, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!12, !6, i64 16}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass