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

; 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.mmt_memory_struct = type { i32, i32, ptr }
%struct.message_struct = type { i64, i64, i64, ptr, i16, %struct.mmt_bit_t, ptr, i32, i32, ptr, [32 x i8] }
%struct.mmt_bit_t = type { [32 x i8] }

@_memory = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @create_message_t() #0 {
  %1 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  %2 = load ptr, ptr @_memory, align 8, !tbaa !5
  %3 = icmp eq ptr %2, null
  %4 = xor i1 %3, true
  %5 = xor i1 %4, true
  %6 = zext i1 %5 to i32
  %7 = sext i32 %6 to i64
  %8 = call i64 @llvm.expect.i64(i64 %7, i64 0)
  %9 = icmp ne i64 %8, 0
  br i1 %9, label %10, label %13

10:                                               ; preds = %0
  %11 = call ptr @_create_local_message_t()
  %12 = getelementptr inbounds i8, ptr %11, i64 -16
  store ptr %12, ptr @_memory, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %10, %0
  %14 = load ptr, ptr @_memory, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.mmt_memory_struct, ptr %14, i32 0, i32 2
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = load ptr, ptr @_memory, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.mmt_memory_struct, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 4, !tbaa !12
  %20 = zext i32 %19 to i64
  %21 = call ptr @mmt_mem_force_dup(ptr noundef %16, i64 noundef %20)
  store ptr %21, ptr %1, align 8, !tbaa !5
  %22 = load ptr, ptr %1, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.message_struct, ptr %22, i64 1
  %24 = load ptr, ptr %1, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.message_struct, ptr %24, i32 0, i32 3
  store ptr %23, ptr %25, align 8, !tbaa !13
  %26 = load ptr, ptr %1, align 8, !tbaa !5
  %27 = load ptr, ptr %1, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.message_struct, ptr %27, i32 0, i32 4
  %29 = load i16, ptr %28, align 32, !tbaa !18
  %30 = zext i16 %29 to i64
  %31 = mul i64 24, %30
  %32 = add i64 128, %31
  %33 = getelementptr inbounds i8, ptr %26, i64 %32
  %34 = load ptr, ptr %1, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.message_struct, ptr %34, i32 0, i32 6
  store ptr %33, ptr %35, align 8, !tbaa !19
  %36 = load ptr, ptr %1, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.message_struct, ptr %36, i32 0, i32 5
  call void @mmt_bit_init(ptr noundef %37)
  %38 = load ptr, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret ptr %38
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mmt_bit_init(ptr noundef) #3

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @_create_local_message_t() #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #3 = { 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 #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 8}
!10 = !{!"mmt_memory_struct", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!14, !6, i64 24}
!14 = !{!"message_struct", !15, i64 0, !15, i64 8, !15, i64 16, !6, i64 24, !16, i64 32, !17, i64 34, !6, i64 72, !11, i64 80, !11, i64 84, !6, i64 88}
!15 = !{!"long", !7, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!"", !7, i64 0}
!18 = !{!14, !16, i64 32}
!19 = !{!14, !6, i64 72}


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

@_memory = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @create_message_t() local_unnamed_addr #0 {
  %1 = load ptr, ptr @_memory, align 8, !tbaa !5
  %2 = icmp eq ptr %1, null
  br i1 %2, label %3, label %6, !prof !9

3:                                                ; preds = %0
  %4 = tail call ptr @_create_local_message_t()
  %5 = getelementptr inbounds i8, ptr %4, i64 -16
  store ptr %5, ptr @_memory, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %3, %0
  %7 = phi ptr [ %5, %3 ], [ %1, %0 ]
  %8 = getelementptr inbounds i8, ptr %7, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !10
  %10 = getelementptr inbounds i8, ptr %7, i64 4
  %11 = load i32, ptr %10, align 4, !tbaa !13
  %12 = zext i32 %11 to i64
  %13 = tail call ptr @mmt_mem_force_dup(ptr noundef %9, i64 noundef %12)
  %14 = getelementptr inbounds i8, ptr %13, i64 128
  %15 = getelementptr inbounds i8, ptr %13, i64 24
  store ptr %14, ptr %15, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %13, i64 32
  %17 = load i16, ptr %16, align 32, !tbaa !19
  %18 = zext i16 %17 to i64
  %19 = mul nuw nsw i64 %18, 24
  %20 = getelementptr inbounds i8, ptr %13, i64 %19
  %21 = getelementptr inbounds i8, ptr %20, i64 128
  %22 = getelementptr inbounds i8, ptr %13, i64 72
  store ptr %21, ptr %22, align 8, !tbaa !20
  %23 = getelementptr inbounds i8, ptr %13, i64 34
  tail call void @mmt_bit_init(ptr noundef nonnull %23)
  ret ptr %13
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mmt_bit_init(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @_create_local_message_t() 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" }

!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 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!10 = !{!11, !6, i64 8}
!11 = !{!"mmt_memory_struct", !12, i64 0, !12, i64 4, !6, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!11, !12, i64 4}
!14 = !{!15, !6, i64 24}
!15 = !{!"message_struct", !16, i64 0, !16, i64 8, !16, i64 16, !6, i64 24, !17, i64 32, !18, i64 34, !6, i64 72, !12, i64 80, !12, i64 84, !6, i64 88}
!16 = !{!"long", !7, i64 0}
!17 = !{!"short", !7, i64 0}
!18 = !{!"", !7, i64 0}
!19 = !{!15, !17, i64 32}
!20 = !{!15, !6, i64 72}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LowerExpectIntrinsicPass,SROAPass,TailCallElimPass