; 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.mmt_array_struct = type { i64, ptr }
%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 }

; 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 zeroext i1 @fsm_is_verifying_single_packet(ptr noundef %0) #1 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.fsm_struct, ptr %6, i32 0, i32 9
  %8 = load ptr, ptr %7, align 64, !tbaa !9
  %9 = getelementptr inbounds %struct.mmt_array_struct, ptr %8, i32 0, i32 0
  %10 = load i64, ptr %9, align 8, !tbaa !13
  %11 = icmp ne i64 %10, 3
  br i1 %11, label %12, label %13

12:                                               ; preds = %1
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %75

13:                                               ; preds = %1
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.fsm_struct, ptr %14, i32 0, i32 5
  %16 = load ptr, ptr %15, align 32, !tbaa !15
  %17 = getelementptr inbounds %struct.fsm_state_struct, ptr %16, i32 0, i32 4
  %18 = load i64, ptr %17, align 8, !tbaa !16
  %19 = icmp ne i64 %18, 1
  br i1 %19, label %20, label %21

20:                                               ; preds = %13
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %75

21:                                               ; preds = %13
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.fsm_struct, ptr %22, i32 0, i32 5
  %24 = load ptr, ptr %23, align 32, !tbaa !15
  %25 = getelementptr inbounds %struct.fsm_state_struct, ptr %24, i32 0, i32 3
  %26 = load ptr, ptr %25, align 8, !tbaa !21
  %27 = getelementptr inbounds %struct.fsm_transition_struct, ptr %26, i64 0
  store ptr %27, ptr %4, align 8, !tbaa !5
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.fsm_transition_struct, ptr %28, i32 0, i32 3
  %30 = load ptr, ptr %29, align 8, !tbaa !22
  %31 = getelementptr inbounds %struct.fsm_state_struct, ptr %30, i32 0, i32 1
  %32 = load i8, ptr %31, align 8, !tbaa !24, !range !25, !noundef !26
  %33 = trunc i8 %32 to i1
  br i1 %33, label %35, label %34

34:                                               ; preds = %21
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %75

35:                                               ; preds = %21
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.fsm_transition_struct, ptr %36, i32 0, i32 3
  %38 = load ptr, ptr %37, align 8, !tbaa !22
  %39 = getelementptr inbounds %struct.fsm_state_struct, ptr %38, i32 0, i32 4
  %40 = load i64, ptr %39, align 8, !tbaa !16
  %41 = icmp ne i64 %40, 2
  br i1 %41, label %42, label %43

42:                                               ; preds = %35
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %75

43:                                               ; preds = %35
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.fsm_transition_struct, ptr %44, i32 0, i32 3
  %46 = load ptr, ptr %45, align 8, !tbaa !22
  %47 = getelementptr inbounds %struct.fsm_state_struct, ptr %46, i32 0, i32 3
  %48 = load ptr, ptr %47, align 8, !tbaa !21
  %49 = getelementptr inbounds %struct.fsm_transition_struct, ptr %48, i64 1
  store ptr %49, ptr %4, align 8, !tbaa !5
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.fsm_transition_struct, ptr %50, i32 0, i32 3
  %52 = load ptr, ptr %51, align 8, !tbaa !22
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.fsm_struct, ptr %53, i32 0, i32 6
  %55 = load ptr, ptr %54, align 8, !tbaa !27
  %56 = icmp ne ptr %52, %55
  br i1 %56, label %57, label %74

57:                                               ; preds = %43
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.fsm_transition_struct, ptr %58, i32 0, i32 3
  %60 = load ptr, ptr %59, align 8, !tbaa !22
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.fsm_struct, ptr %61, i32 0, i32 8
  %63 = load ptr, ptr %62, align 8, !tbaa !28
  %64 = icmp ne ptr %60, %63
  br i1 %64, label %65, label %74

65:                                               ; preds = %57
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.fsm_transition_struct, ptr %66, i32 0, i32 3
  %68 = load ptr, ptr %67, align 8, !tbaa !22
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.fsm_struct, ptr %69, i32 0, i32 7
  %71 = load ptr, ptr %70, align 16, !tbaa !29
  %72 = icmp ne ptr %68, %71
  br i1 %72, label %73, label %74

73:                                               ; preds = %65
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %75

74:                                               ; preds = %65, %57, %43
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %75

75:                                               ; preds = %74, %73, %42, %34, %20, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %76 = load i1, ptr %2, align 1
  ret i1 %76
}

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 }

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


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @fsm_is_verifying_single_packet(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 64
  %3 = load ptr, ptr %2, align 64, !tbaa !5
  %4 = load i64, ptr %3, align 8, !tbaa !12
  %.not = icmp eq i64 %4, 3
  br i1 %.not, label %5, label %35

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = load ptr, ptr %6, align 32, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %7, i64 72
  %9 = load i64, ptr %8, align 8, !tbaa !15
  %.not14 = icmp eq i64 %9, 1
  br i1 %.not14, label %10, label %35

10:                                               ; preds = %5
  %11 = getelementptr inbounds i8, ptr %7, i64 64
  %12 = load ptr, ptr %11, align 8, !tbaa !20
  %13 = getelementptr inbounds i8, ptr %12, i64 24
  %14 = load ptr, ptr %13, align 8, !tbaa !21
  %15 = getelementptr inbounds i8, ptr %14, i64 48
  %16 = load i8, ptr %15, align 8, !tbaa !23, !range !24, !noundef !25
  %17 = trunc nuw i8 %16 to i1
  br i1 %17, label %18, label %35

18:                                               ; preds = %10
  %19 = getelementptr inbounds i8, ptr %14, i64 72
  %20 = load i64, ptr %19, align 8, !tbaa !15
  %.not15 = icmp eq i64 %20, 2
  br i1 %.not15, label %21, label %35

21:                                               ; preds = %18
  %22 = getelementptr inbounds i8, ptr %14, i64 64
  %23 = load ptr, ptr %22, align 8, !tbaa !20
  %24 = getelementptr inbounds i8, ptr %23, i64 56
  %25 = load ptr, ptr %24, align 8, !tbaa !21
  %26 = getelementptr inbounds i8, ptr %0, i64 40
  %27 = load ptr, ptr %26, align 8, !tbaa !26
  %.not16 = icmp eq ptr %25, %27
  br i1 %.not16, label %34, label %28

28:                                               ; preds = %21
  %29 = getelementptr inbounds i8, ptr %0, i64 56
  %30 = load ptr, ptr %29, align 8, !tbaa !27
  %.not17 = icmp eq ptr %25, %30
  br i1 %.not17, label %34, label %31

31:                                               ; preds = %28
  %32 = getelementptr inbounds i8, ptr %0, i64 48
  %33 = load ptr, ptr %32, align 16, !tbaa !28
  %.not18 = icmp eq ptr %25, %33
  br i1 %.not18, label %34, label %35

34:                                               ; preds = %31, %28, %21
  br label %35

35:                                               ; preds = %31, %18, %10, %5, %1, %34
  %.0 = phi i1 [ true, %34 ], [ false, %1 ], [ false, %5 ], [ false, %10 ], [ false, %18 ], [ false, %31 ]
  ret i1 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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" }

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


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