; LLVM IR from Montimage/mmt-security :: src/lib (mmt_fsm)

; 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.fsm_struct = type { i64, i64, i16, i16, ptr, ptr, ptr, ptr, ptr, ptr, ptr, [48 x i8] }
%struct.fsm_state_struct = type { %struct.fsm_delay_struct, i8, ptr, ptr, i64, i32, i32 }
%struct.fsm_delay_struct = type { i64, i64, i32, i32, i64, i64, i32, i32 }
%struct.fsm_transition_struct = type { i16, ptr, i32, ptr }
%struct.mmt_array_struct = type { i64, ptr }

; 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 i32 @fsm_handle_single_packet(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.fsm_struct, ptr %10, i32 0, i32 5
  %12 = load ptr, ptr %11, align 32, !tbaa !9
  %13 = getelementptr inbounds %struct.fsm_state_struct, ptr %12, i32 0, i32 3
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = getelementptr inbounds %struct.fsm_transition_struct, ptr %14, i64 0
  store ptr %15, ptr %6, align 8, !tbaa !5
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.fsm_transition_struct, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !18
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %29

20:                                               ; preds = %2
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.fsm_transition_struct, ptr %21, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !18
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = call i32 %23(ptr noundef %24, ptr noundef %25)
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %20
  store i32 2, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %108

29:                                               ; preds = %20, %2
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = call ptr @mmt_mem_atomic_retains(ptr noundef %30, i64 noundef 2)
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.fsm_struct, ptr %32, i32 0, i32 9
  %34 = load ptr, ptr %33, align 64, !tbaa !20
  %35 = getelementptr inbounds %struct.mmt_array_struct, ptr %34, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !21
  %37 = getelementptr inbounds ptr, ptr %36, i64 1
  store ptr %31, ptr %37, align 8, !tbaa !5
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.fsm_struct, ptr %38, i32 0, i32 5
  %40 = load ptr, ptr %39, align 32, !tbaa !9
  %41 = getelementptr inbounds %struct.fsm_state_struct, ptr %40, i32 0, i32 3
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  %43 = getelementptr inbounds %struct.fsm_transition_struct, ptr %42, i64 0
  %44 = getelementptr inbounds %struct.fsm_transition_struct, ptr %43, i32 0, i32 3
  %45 = load ptr, ptr %44, align 8, !tbaa !23
  %46 = getelementptr inbounds %struct.fsm_state_struct, ptr %45, i32 0, i32 3
  %47 = load ptr, ptr %46, align 8, !tbaa !13
  %48 = getelementptr inbounds %struct.fsm_transition_struct, ptr %47, i64 1
  store ptr %48, ptr %6, align 8, !tbaa !5
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.fsm_transition_struct, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !18
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %75

53:                                               ; preds = %29
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.fsm_transition_struct, ptr %54, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !18
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = call i32 %56(ptr noundef %57, ptr noundef %58)
  %60 = icmp eq i32 %59, 0
  br i1 %60, label %61, label %75

61:                                               ; preds = %53
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.fsm_struct, ptr %62, i32 0, i32 5
  %64 = load ptr, ptr %63, align 32, !tbaa !9
  %65 = getelementptr inbounds %struct.fsm_state_struct, ptr %64, i32 0, i32 3
  %66 = load ptr, ptr %65, align 8, !tbaa !13
  %67 = getelementptr inbounds %struct.fsm_transition_struct, ptr %66, i64 0
  %68 = getelementptr inbounds %struct.fsm_transition_struct, ptr %67, i32 0, i32 3
  %69 = load ptr, ptr %68, align 8, !tbaa !23
  %70 = getelementptr inbounds %struct.fsm_state_struct, ptr %69, i32 0, i32 3
  %71 = load ptr, ptr %70, align 8, !tbaa !13
  %72 = getelementptr inbounds %struct.fsm_transition_struct, ptr %71, i64 0
  %73 = getelementptr inbounds %struct.fsm_transition_struct, ptr %72, i32 0, i32 3
  %74 = load ptr, ptr %73, align 8, !tbaa !23
  store ptr %74, ptr %8, align 8, !tbaa !5
  br label %79

75:                                               ; preds = %53, %29
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.fsm_transition_struct, ptr %76, i32 0, i32 3
  %78 = load ptr, ptr %77, align 8, !tbaa !23
  store ptr %78, ptr %8, align 8, !tbaa !5
  br label %79

79:                                               ; preds = %75, %61
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.fsm_struct, ptr %81, i32 0, i32 9
  %83 = load ptr, ptr %82, align 64, !tbaa !20
  %84 = getelementptr inbounds %struct.mmt_array_struct, ptr %83, i32 0, i32 1
  %85 = load ptr, ptr %84, align 8, !tbaa !21
  %86 = getelementptr inbounds ptr, ptr %85, i64 2
  store ptr %80, ptr %86, align 8, !tbaa !5
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.fsm_struct, ptr %88, i32 0, i32 6
  %90 = load ptr, ptr %89, align 8, !tbaa !24
  %91 = icmp eq ptr %87, %90
  br i1 %91, label %92, label %93

92:                                               ; preds = %79
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %108

93:                                               ; preds = %79
  %94 = load ptr, ptr %8, align 8, !tbaa !5
  %95 = load ptr, ptr %4, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.fsm_struct, ptr %95, i32 0, i32 7
  %97 = load ptr, ptr %96, align 16, !tbaa !25
  %98 = icmp eq ptr %94, %97
  br i1 %98, label %99, label %100

99:                                               ; preds = %93
  store i32 4, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %108

100:                                              ; preds = %93
  %101 = load ptr, ptr %8, align 8, !tbaa !5
  %102 = load ptr, ptr %4, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.fsm_struct, ptr %102, i32 0, i32 8
  %104 = load ptr, ptr %103, align 8, !tbaa !26
  %105 = icmp eq ptr %101, %104
  br i1 %105, label %106, label %107

106:                                              ; preds = %100
  store i32 3, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %108

107:                                              ; preds = %100
  store i32 -2, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %108

108:                                              ; preds = %107, %106, %99, %92, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %109 = load i32, ptr %3, align 4
  ret i32 %109
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @mmt_mem_atomic_retains(ptr noundef, i64 noundef) #2

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 = { inlinehint 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 #3 = { 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 32}
!10 = !{!"fsm_struct", !11, i64 0, !11, i64 8, !12, i64 16, !12, i64 18, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72}
!11 = !{!"long", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !6, i64 64}
!14 = !{!"fsm_state_struct", !15, i64 0, !17, i64 48, !6, i64 56, !6, i64 64, !11, i64 72, !16, i64 80, !16, i64 84}
!15 = !{!"fsm_delay_struct", !11, i64 0, !11, i64 8, !16, i64 16, !16, i64 20, !11, i64 24, !11, i64 32, !16, i64 40, !16, i64 44}
!16 = !{!"int", !7, i64 0}
!17 = !{!"_Bool", !7, i64 0}
!18 = !{!19, !6, i64 8}
!19 = !{!"fsm_transition_struct", !12, i64 0, !6, i64 8, !16, i64 16, !6, i64 24}
!20 = !{!10, !6, i64 64}
!21 = !{!22, !6, i64 8}
!22 = !{!"mmt_array_struct", !11, i64 0, !6, i64 8}
!23 = !{!19, !6, i64 24}
!24 = !{!10, !6, i64 40}
!25 = !{!10, !6, i64 48}
!26 = !{!10, !6, i64 56}


; 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"

; Function Attrs: nounwind uwtable
define dso_local range(i32 -2, 5) i32 @fsm_handle_single_packet(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load ptr, ptr %3, align 32, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 64
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !17
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %12, label %9

9:                                                ; preds = %2
  %10 = tail call i32 %8(ptr noundef %1, ptr noundef nonnull %0) #2
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %58, label %12

12:                                               ; preds = %9, %2
  %13 = tail call ptr @mmt_mem_atomic_retains(ptr noundef %1, i64 noundef 2)
  %14 = getelementptr inbounds i8, ptr %0, i64 64
  %15 = load ptr, ptr %14, align 64, !tbaa !19
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !20
  %18 = getelementptr inbounds i8, ptr %17, i64 8
  store ptr %13, ptr %18, align 8, !tbaa !22
  %19 = load ptr, ptr %3, align 32, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 64
  %21 = load ptr, ptr %20, align 8, !tbaa !12
  %22 = getelementptr inbounds i8, ptr %21, i64 24
  %23 = load ptr, ptr %22, align 8, !tbaa !23
  %24 = getelementptr inbounds i8, ptr %23, i64 64
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  %26 = getelementptr inbounds i8, ptr %25, i64 40
  %27 = load ptr, ptr %26, align 8, !tbaa !17
  %.not25 = icmp eq ptr %27, null
  br i1 %.not25, label %40, label %28

28:                                               ; preds = %12
  %29 = tail call i32 %27(ptr noundef %1, ptr noundef nonnull %0) #2
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %40

31:                                               ; preds = %28
  %32 = load ptr, ptr %3, align 32, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 64
  %34 = load ptr, ptr %33, align 8, !tbaa !12
  %35 = getelementptr inbounds i8, ptr %34, i64 24
  %36 = load ptr, ptr %35, align 8, !tbaa !23
  %37 = getelementptr inbounds i8, ptr %36, i64 64
  %38 = load ptr, ptr %37, align 8, !tbaa !12
  %39 = getelementptr inbounds i8, ptr %38, i64 24
  br label %42

40:                                               ; preds = %28, %12
  %41 = getelementptr inbounds i8, ptr %25, i64 56
  br label %42

42:                                               ; preds = %40, %31
  %.0.in = phi ptr [ %39, %31 ], [ %41, %40 ]
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !23
  %43 = load ptr, ptr %14, align 64, !tbaa !19
  %44 = getelementptr inbounds i8, ptr %43, i64 8
  %45 = load ptr, ptr %44, align 8, !tbaa !20
  %46 = getelementptr inbounds i8, ptr %45, i64 16
  store ptr %1, ptr %46, align 8, !tbaa !22
  %47 = getelementptr inbounds i8, ptr %0, i64 40
  %48 = load ptr, ptr %47, align 8, !tbaa !24
  %49 = icmp eq ptr %.0, %48
  br i1 %49, label %58, label %50

50:                                               ; preds = %42
  %51 = getelementptr inbounds i8, ptr %0, i64 48
  %52 = load ptr, ptr %51, align 16, !tbaa !25
  %53 = icmp eq ptr %.0, %52
  br i1 %53, label %58, label %54

54:                                               ; preds = %50
  %55 = getelementptr inbounds i8, ptr %0, i64 56
  %56 = load ptr, ptr %55, align 8, !tbaa !26
  %57 = icmp eq ptr %.0, %56
  %. = select i1 %57, i32 3, i32 -2
  br label %58

58:                                               ; preds = %54, %50, %42, %9
  %.022 = phi i32 [ 2, %9 ], [ -1, %42 ], [ 4, %50 ], [ %., %54 ]
  ret i32 %.022
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @mmt_mem_atomic_retains(ptr noundef, i64 noundef) local_unnamed_addr #1

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 = { inlinehint 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 }

!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, !11, i64 32}
!6 = !{!"fsm_struct", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 18, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!13, !11, i64 64}
!13 = !{!"fsm_state_struct", !14, i64 0, !16, i64 48, !11, i64 56, !11, i64 64, !7, i64 72, !15, i64 80, !15, i64 84}
!14 = !{!"fsm_delay_struct", !7, i64 0, !7, i64 8, !15, i64 16, !15, i64 20, !7, i64 24, !7, i64 32, !15, i64 40, !15, i64 44}
!15 = !{!"int", !8, i64 0}
!16 = !{!"_Bool", !8, i64 0}
!17 = !{!18, !11, i64 8}
!18 = !{!"fsm_transition_struct", !10, i64 0, !11, i64 8, !15, i64 16, !11, i64 24}
!19 = !{!6, !11, i64 64}
!20 = !{!21, !11, i64 8}
!21 = !{!"mmt_array_struct", !7, i64 0, !11, i64 8}
!22 = !{!11, !11, i64 0}
!23 = !{!18, !11, i64 24}
!24 = !{!6, !11, i64 40}
!25 = !{!6, !11, i64 48}
!26 = !{!6, !11, i64 56}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass