; LLVM IR from stan-dev/math :: lib/boost_1.84.0/libs/serialization/src (archive_exception)

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

%"class.boost::archive::archive_exception" = type <{ %"class.std::exception", [128 x i8], i32, [4 x i8] }>
%"class.std::exception" = type { ptr }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN5boost7archive17archive_exception6appendEjPKc(ptr noundef nonnull align 8 dereferenceable(140) %0, i32 noundef %1, ptr noundef %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  br label %10

10:                                               ; preds = %31, %3
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = zext i32 %11 to i64
  %13 = icmp ult i64 %12, 127
  br i1 %13, label %14, label %32

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i32 1
  store ptr %16, ptr %6, align 8, !tbaa !5
  %17 = load i8, ptr %15, align 1, !tbaa !11
  store i8 %17, ptr %7, align 1, !tbaa !11
  %18 = load i8, ptr %7, align 1, !tbaa !11
  %19 = sext i8 %18 to i32
  %20 = icmp eq i32 0, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %14
  store i32 3, ptr %8, align 4
  br label %29

22:                                               ; preds = %14
  %23 = load i8, ptr %7, align 1, !tbaa !11
  %24 = getelementptr inbounds %"class.boost::archive::archive_exception", ptr %9, i32 0, i32 1
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = add i32 %25, 1
  store i32 %26, ptr %5, align 4, !tbaa !9
  %27 = zext i32 %25 to i64
  %28 = getelementptr inbounds [128 x i8], ptr %24, i64 0, i64 %27
  store i8 %23, ptr %28, align 1, !tbaa !11
  store i32 0, ptr %8, align 4
  br label %29

29:                                               ; preds = %22, %21
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  %30 = load i32, ptr %8, align 4
  switch i32 %30, label %38 [
    i32 0, label %31
    i32 3, label %32
  ]

31:                                               ; preds = %29
  br label %10, !llvm.loop !12

32:                                               ; preds = %29, %10
  %33 = getelementptr inbounds %"class.boost::archive::archive_exception", ptr %9, i32 0, i32 1
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds [128 x i8], ptr %33, i64 0, i64 %35
  store i8 0, ptr %36, align 1, !tbaa !11
  %37 = load i32, ptr %5, align 4, !tbaa !9
  ret i32 %37

38:                                               ; preds = %29
  unreachable
}

; 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(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { mustprogress 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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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 memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_ZN5boost7archive17archive_exception6appendEjPKc(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(140) %0, i32 noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 align 2 {
  %4 = icmp ult i32 %1, 127
  br i1 %4, label %.lr.ph, label %.thread

.lr.ph:                                           ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = zext nneg i32 %1 to i64
  br label %7

7:                                                ; preds = %.lr.ph, %10
  %indvars.iv = phi i64 [ %6, %.lr.ph ], [ %indvars.iv.next, %10 ]
  %.0914 = phi ptr [ %2, %.lr.ph ], [ %11, %10 ]
  %8 = load i8, ptr %.0914, align 1, !tbaa !5
  %9 = icmp eq i8 %8, 0
  br i1 %9, label %.thread.loopexit.split.loop.exit, label %10

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %.0914, i64 1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %12 = getelementptr inbounds [128 x i8], ptr %5, i64 0, i64 %indvars.iv
  store i8 %8, ptr %12, align 1, !tbaa !5
  %13 = and i64 %indvars.iv.next, 4294967295
  %exitcond.not = icmp eq i64 %13, 127
  br i1 %exitcond.not, label %.thread, label %7

.thread.loopexit.split.loop.exit:                 ; preds = %7
  %14 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.thread

.thread:                                          ; preds = %10, %.thread.loopexit.split.loop.exit, %3
  %.08.lcssa = phi i32 [ %1, %3 ], [ %14, %.thread.loopexit.split.loop.exit ], [ 127, %10 ]
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = zext i32 %.08.lcssa to i64
  %17 = getelementptr inbounds [128 x i8], ptr %15, i64 0, i64 %16
  store i8 0, ptr %17, align 1, !tbaa !5
  ret i32 %.08.lcssa
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(read, argmem: readwrite, 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass