; 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] }

; Function Attrs: nounwind uwtable
define dso_local ptr @fsm_init(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i64 noundef %4, i64 noundef %5) #0 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i64 %4, ptr %11, align 8, !tbaa !9
  store i64 %5, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %14 = call ptr @mmt_mem_alloc(i64 noundef 128)
  store ptr %14, ptr %13, align 8, !tbaa !5
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = load ptr, ptr %13, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.fsm_struct, ptr %16, i32 0, i32 5
  store ptr %15, ptr %17, align 32, !tbaa !11
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = load ptr, ptr %13, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.fsm_struct, ptr %19, i32 0, i32 4
  store ptr %18, ptr %20, align 8, !tbaa !14
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = load ptr, ptr %13, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.fsm_struct, ptr %22, i32 0, i32 6
  store ptr %21, ptr %23, align 8, !tbaa !15
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  %25 = load ptr, ptr %13, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.fsm_struct, ptr %25, i32 0, i32 7
  store ptr %24, ptr %26, align 16, !tbaa !16
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = load ptr, ptr %13, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.fsm_struct, ptr %28, i32 0, i32 8
  store ptr %27, ptr %29, align 8, !tbaa !17
  %30 = load ptr, ptr %13, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.fsm_struct, ptr %30, i32 0, i32 2
  store i16 0, ptr %31, align 16, !tbaa !18
  %32 = load i64, ptr %11, align 8, !tbaa !9
  %33 = add i64 %32, 1
  %34 = call ptr @mmt_array_init(i64 noundef %33)
  %35 = load ptr, ptr %13, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.fsm_struct, ptr %35, i32 0, i32 9
  store ptr %34, ptr %36, align 64, !tbaa !19
  %37 = load ptr, ptr %13, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.fsm_struct, ptr %37, i32 0, i32 0
  store i64 0, ptr %38, align 64, !tbaa !20
  %39 = load ptr, ptr %13, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.fsm_struct, ptr %39, i32 0, i32 1
  store i64 0, ptr %40, align 8, !tbaa !21
  %41 = load ptr, ptr %13, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.fsm_struct, ptr %41, i32 0, i32 3
  store i16 0, ptr %42, align 2, !tbaa !22
  %43 = load ptr, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  ret ptr %43
}

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

declare ptr @mmt_mem_alloc(i64 noundef) #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden ptr @mmt_array_init(i64 noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { alwaysinline 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 #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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 32}
!12 = !{!"fsm_struct", !10, i64 0, !10, i64 8, !13, i64 16, !13, i64 18, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !6, i64 24}
!15 = !{!12, !6, i64 40}
!16 = !{!12, !6, i64 48}
!17 = !{!12, !6, i64 56}
!18 = !{!12, !13, i64 16}
!19 = !{!12, !6, i64 64}
!20 = !{!12, !10, i64 0}
!21 = !{!12, !10, i64 8}
!22 = !{!12, !13, i64 18}


; 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 ptr @fsm_init(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i64 noundef %4, i64 noundef %5) local_unnamed_addr #0 {
  %7 = tail call ptr @mmt_mem_alloc(i64 noundef 128) #4
  %8 = getelementptr inbounds i8, ptr %7, i64 32
  store ptr %0, ptr %8, align 32, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %7, i64 24
  store ptr %0, ptr %9, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %7, i64 40
  store ptr %1, ptr %10, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %7, i64 48
  store ptr %3, ptr %11, align 16, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %7, i64 56
  store ptr %2, ptr %12, align 8, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %7, i64 16
  store i16 0, ptr %13, align 16, !tbaa !16
  %14 = add i64 %4, 1
  %15 = tail call ptr @mmt_array_init(i64 noundef %14)
  %16 = getelementptr inbounds i8, ptr %7, i64 64
  store ptr %15, ptr %16, align 64, !tbaa !17
  %17 = getelementptr inbounds i8, ptr %7, i64 18
  store i16 0, ptr %17, align 2, !tbaa !18
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 64 dereferenceable(16) %7, i8 0, i64 16, i1 false)
  ret ptr %7
}

declare ptr @mmt_mem_alloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: alwaysinline nounwind uwtable
declare hidden ptr @mmt_array_init(i64 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 = { "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 = { alwaysinline 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !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 = !{!6, !11, i64 24}
!13 = !{!6, !11, i64 40}
!14 = !{!6, !11, i64 48}
!15 = !{!6, !11, i64 56}
!16 = !{!6, !10, i64 16}
!17 = !{!6, !11, i64 64}
!18 = !{!6, !10, i64 18}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,TailCallElimPass