; LLVM IR from AngoraFuzzer/Angora :: llvm_mode/dfsan_rt/sanitizer_common (sanitizer_stacktrace)

; 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.__sanitizer::StackTrace" = type { ptr, i32, i32 }
%"struct.__sanitizer::BufferedStackTrace" = type { %"struct.__sanitizer::StackTrace", [256 x i64], i64 }

@.str = external hidden unnamed_addr constant [113 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [21 x i8], align 1

; 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(none)
declare i64 @llvm.expect.i64(i64, i64) #1

; Function Attrs: noreturn
declare void @_ZN11__sanitizer11CheckFailedEPKciS1_yy(ptr noundef, i32 noundef, ptr noundef, i64 noundef, i64 noundef) #2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11__sanitizer18BufferedStackTrace14PopStackFramesEm(ptr noundef nonnull align 8 dereferenceable(2072) %0, i64 noundef %1) #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %8 = load ptr, ptr %3, align 8
  br label %9

9:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %10 = load i64, ptr %4, align 8, !tbaa !9
  store i64 %10, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %11 = getelementptr inbounds %"struct.__sanitizer::StackTrace", ptr %8, i32 0, i32 1
  %12 = load i32, ptr %11, align 8, !tbaa !13
  %13 = zext i32 %12 to i64
  store i64 %13, ptr %6, align 8, !tbaa !11
  %14 = load i64, ptr %5, align 8, !tbaa !11
  %15 = load i64, ptr %6, align 8, !tbaa !11
  %16 = icmp ult i64 %14, %15
  %17 = xor i1 %16, true
  %18 = xor i1 %17, true
  %19 = xor i1 %18, true
  %20 = zext i1 %19 to i64
  %21 = call i64 @llvm.expect.i64(i64 %20, i64 0)
  %22 = icmp ne i64 %21, 0
  br i1 %22, label %23, label %26

23:                                               ; preds = %9
  %24 = load i64, ptr %5, align 8, !tbaa !11
  %25 = load i64, ptr %6, align 8, !tbaa !11
  call void @_ZN11__sanitizer11CheckFailedEPKciS1_yy(ptr noundef @.str, i32 noundef 114, ptr noundef @.str.3, i64 noundef %24, i64 noundef %25) #5
  unreachable

26:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %27

27:                                               ; preds = %26
  %28 = load i64, ptr %4, align 8, !tbaa !9
  %29 = getelementptr inbounds %"struct.__sanitizer::StackTrace", ptr %8, i32 0, i32 1
  %30 = load i32, ptr %29, align 8, !tbaa !13
  %31 = zext i32 %30 to i64
  %32 = sub i64 %31, %28
  %33 = trunc i64 %32 to i32
  store i32 %33, ptr %29, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %51, %27
  %35 = load i64, ptr %7, align 8, !tbaa !9
  %36 = getelementptr inbounds %"struct.__sanitizer::StackTrace", ptr %8, i32 0, i32 1
  %37 = load i32, ptr %36, align 8, !tbaa !13
  %38 = zext i32 %37 to i64
  %39 = icmp ult i64 %35, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %54

41:                                               ; preds = %34
  %42 = getelementptr inbounds %"struct.__sanitizer::BufferedStackTrace", ptr %8, i32 0, i32 1
  %43 = load i64, ptr %7, align 8, !tbaa !9
  %44 = load i64, ptr %4, align 8, !tbaa !9
  %45 = add i64 %43, %44
  %46 = getelementptr inbounds [256 x i64], ptr %42, i64 0, i64 %45
  %47 = load i64, ptr %46, align 8, !tbaa !9
  %48 = getelementptr inbounds %"struct.__sanitizer::BufferedStackTrace", ptr %8, i32 0, i32 1
  %49 = load i64, ptr %7, align 8, !tbaa !9
  %50 = getelementptr inbounds [256 x i64], ptr %48, i64 0, i64 %49
  store i64 %47, ptr %50, align 8, !tbaa !9
  br label %51

51:                                               ; preds = %41
  %52 = load i64, ptr %7, align 8, !tbaa !9
  %53 = add i64 %52, 1
  store i64 %53, ptr %7, align 8, !tbaa !9
  br label %34, !llvm.loop !16

54:                                               ; preds = %40
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #2 = { noreturn "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 = { mustprogress 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 }
attributes #5 = { noreturn }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !15, i64 8}
!14 = !{!"_ZTSN11__sanitizer10StackTraceE", !6, i64 0, !15, i64 8, !15, i64 12}
!15 = !{!"int", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

@.str = external hidden unnamed_addr constant [113 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: noreturn
declare void @_ZN11__sanitizer11CheckFailedEPKciS1_yy(ptr noundef, i32 noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11__sanitizer18BufferedStackTrace14PopStackFramesEm(ptr nocapture noundef nonnull align 8 dereferenceable(2072) %0, i64 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = zext i32 %4 to i64
  %.not = icmp ugt i64 %5, %1
  br i1 %.not, label %7, label %6, !prof !11

6:                                                ; preds = %2
  tail call void @_ZN11__sanitizer11CheckFailedEPKciS1_yy(ptr noundef nonnull @.str, i32 noundef 114, ptr noundef nonnull @.str.3, i64 noundef %1, i64 noundef %5) #3
  unreachable

7:                                                ; preds = %2
  %8 = trunc i64 %1 to i32
  %9 = sub i32 %4, %8
  store i32 %9, ptr %3, align 8, !tbaa !5
  %.not12 = icmp eq i32 %4, %8
  br i1 %.not12, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %7
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = tail call i32 @llvm.umax.i32(i32 %9, i32 1)
  %umax = zext i32 %11 to i64
  %min.iters.check = icmp ult i32 %9, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %.011.ph = phi i64 [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %umax, 4294967292
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %12 = add i64 %index, %1
  %13 = getelementptr inbounds [256 x i64], ptr %10, i64 0, i64 %12
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  %wide.load = load <2 x i64>, ptr %13, align 8, !tbaa !12
  %wide.load13 = load <2 x i64>, ptr %14, align 8, !tbaa !12
  %15 = getelementptr inbounds [256 x i64], ptr %10, i64 0, i64 %index
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  store <2 x i64> %wide.load, ptr %15, align 8, !tbaa !12
  store <2 x i64> %wide.load13, ptr %16, align 8, !tbaa !12
  %index.next = add nuw i64 %index, 4
  %17 = icmp eq i64 %index.next, %n.vec
  br i1 %17, label %middle.block, label %vector.body, !llvm.loop !14

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %umax
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

._crit_edge:                                      ; preds = %scalar.ph, %middle.block, %7
  ret void

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.011 = phi i64 [ %22, %scalar.ph ], [ %.011.ph, %scalar.ph.preheader ]
  %18 = add i64 %.011, %1
  %19 = getelementptr inbounds [256 x i64], ptr %10, i64 0, i64 %18
  %20 = load i64, ptr %19, align 8, !tbaa !12
  %21 = getelementptr inbounds [256 x i64], ptr %10, i64 0, i64 %.011
  store i64 %20, ptr %21, align 8, !tbaa !12
  %22 = add nuw nsw i64 %.011, 1
  %exitcond.not = icmp eq i64 %22, %umax
  br i1 %exitcond.not, label %._crit_edge, label %scalar.ph, !llvm.loop !18
}

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

attributes #0 = { noreturn "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 = { mustprogress 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { noreturn }

!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, !10, i64 8}
!6 = !{!"_ZTSN11__sanitizer10StackTraceE", !7, i64 0, !10, i64 8, !10, i64 12}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = distinct !{!14, !15, !16, !17}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !15, !17, !16}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,LowerExpectIntrinsicPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass