; LLVM IR from septag/dmon :: test-incremental (dmon_deinit)

; 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.dmon__state = type { [64 x ptr], [64 x i32], ptr, i32, i64, %union.pthread_mutex_t, i8 }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }

@_dmon_init = external hidden global i8, align 1
@.str.1 = external hidden unnamed_addr constant [52 x i8], align 1
@_dmon = external hidden global %struct.dmon__state, align 8
@.str.4 = external hidden unnamed_addr constant [11 x i8], align 1
@__PRETTY_FUNCTION__.dmon_deinit = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

; 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

; Function Attrs: nounwind uwtable
define dso_local void @dmon_deinit() #2 {
  %1 = alloca i32, align 4
  %2 = load i8, ptr @_dmon_init, align 1, !tbaa !5, !range !9, !noundef !10
  %3 = trunc i8 %2 to i1
  br i1 %3, label %4, label %5

4:                                                ; preds = %0
  br label %6

5:                                                ; preds = %0
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 1181, ptr noundef @__PRETTY_FUNCTION__.dmon_deinit) #6
  unreachable

6:                                                ; preds = %4
  %7 = atomicrmw xchg ptr getelementptr inbounds (%struct.dmon__state, ptr @_dmon, i32 0, i32 6), i8 1 seq_cst, align 8
  %8 = trunc i8 %7 to i1
  %9 = load i64, ptr getelementptr inbounds (%struct.dmon__state, ptr @_dmon, i32 0, i32 4), align 8, !tbaa !11
  %10 = call i32 @pthread_join(i64 noundef %9, ptr noundef null)
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #7
  store i32 0, ptr %1, align 4, !tbaa !16
  br label %11

11:                                               ; preds = %31, %6
  %12 = load i32, ptr %1, align 4, !tbaa !16
  %13 = load i32, ptr getelementptr inbounds (%struct.dmon__state, ptr @_dmon, i32 0, i32 3), align 8, !tbaa !17
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %15, label %34

15:                                               ; preds = %11
  %16 = load i32, ptr %1, align 4, !tbaa !16
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [64 x ptr], ptr @_dmon, i64 0, i64 %17
  %19 = load ptr, ptr %18, align 8, !tbaa !18
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %30

21:                                               ; preds = %15
  %22 = load i32, ptr %1, align 4, !tbaa !16
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [64 x ptr], ptr @_dmon, i64 0, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !18
  call void @_dmon_unwatch(ptr noundef %25)
  %26 = load i32, ptr %1, align 4, !tbaa !16
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [64 x ptr], ptr @_dmon, i64 0, i64 %27
  %29 = load ptr, ptr %28, align 8, !tbaa !18
  call void @free(ptr noundef %29) #7
  br label %30

30:                                               ; preds = %21, %15
  br label %31

31:                                               ; preds = %30
  %32 = load i32, ptr %1, align 4, !tbaa !16
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %1, align 4, !tbaa !16
  br label %11, !llvm.loop !19

34:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #7
  %35 = call i32 @pthread_mutex_destroy(ptr noundef getelementptr inbounds (%struct.dmon__state, ptr @_dmon, i32 0, i32 5)) #7
  %36 = load ptr, ptr getelementptr inbounds (%struct.dmon__state, ptr @_dmon, i32 0, i32 2), align 8, !tbaa !21
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %41

38:                                               ; preds = %34
  %39 = load ptr, ptr getelementptr inbounds (%struct.dmon__state, ptr @_dmon, i32 0, i32 2), align 8, !tbaa !21
  %40 = getelementptr inbounds i32, ptr %39, i64 -2
  call void @free(ptr noundef %40) #7
  br label %42

41:                                               ; preds = %34
  br label %42

42:                                               ; preds = %41, %38
  %43 = phi i32 [ 0, %38 ], [ 0, %41 ]
  call void @llvm.memset.p0.i64(ptr align 8 @_dmon, i8 0, i64 840, i1 false)
  store i8 0, ptr @_dmon_init, align 1, !tbaa !5
  ret void
}

declare i32 @pthread_join(i64 noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden void @_dmon_unwatch(ptr noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

; Function Attrs: nounwind
declare i32 @pthread_mutex_destroy(ptr noundef) #4

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

attributes #0 = { noreturn nounwind "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 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 = { "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 "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 #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { noreturn nounwind }
attributes #7 = { 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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !15, i64 784}
!12 = !{!"dmon__state", !7, i64 0, !7, i64 512, !13, i64 768, !14, i64 776, !15, i64 784, !7, i64 792, !6, i64 832}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!14, !14, i64 0}
!17 = !{!12, !14, i64 776}
!18 = !{!13, !13, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!12, !13, i64 768}


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

%struct.dmon__state = type { [64 x ptr], [64 x i32], ptr, i32, i64, %union.pthread_mutex_t, i8 }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }

@_dmon_init = external hidden local_unnamed_addr global i8, align 1
@.str.1 = external hidden unnamed_addr constant [52 x i8], align 1
@_dmon = external hidden global %struct.dmon__state, align 8
@.str.4 = external hidden unnamed_addr constant [11 x i8], align 1
@__PRETTY_FUNCTION__.dmon_deinit = external hidden unnamed_addr constant [23 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local void @dmon_deinit() local_unnamed_addr #1 {
  %1 = load i8, ptr @_dmon_init, align 1, !tbaa !5, !range !9, !noundef !10
  %2 = trunc nuw i8 %1 to i1
  br i1 %2, label %4, label %3

3:                                                ; preds = %0
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 1181, ptr noundef nonnull @__PRETTY_FUNCTION__.dmon_deinit) #6
  unreachable

4:                                                ; preds = %0
  %5 = atomicrmw xchg ptr getelementptr inbounds (i8, ptr @_dmon, i64 832), i8 1 seq_cst, align 8
  %6 = load i64, ptr getelementptr inbounds (i8, ptr @_dmon, i64 784), align 8, !tbaa !11
  %7 = tail call i32 @pthread_join(i64 noundef %6, ptr noundef null) #7
  %8 = load i32, ptr getelementptr inbounds (i8, ptr @_dmon, i64 776), align 8, !tbaa !16
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4, %15
  %10 = phi i32 [ %16, %15 ], [ %8, %4 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %15 ], [ 0, %4 ]
  %11 = getelementptr inbounds [64 x ptr], ptr @_dmon, i64 0, i64 %indvars.iv
  %12 = load ptr, ptr %11, align 8, !tbaa !17
  %.not7 = icmp eq ptr %12, null
  br i1 %.not7, label %15, label %13

13:                                               ; preds = %.lr.ph
  tail call void @_dmon_unwatch(ptr noundef nonnull %12)
  %14 = load ptr, ptr %11, align 8, !tbaa !17
  tail call void @free(ptr noundef %14) #7
  %.pre = load i32, ptr getelementptr inbounds (i8, ptr @_dmon, i64 776), align 8, !tbaa !16
  br label %15

15:                                               ; preds = %.lr.ph, %13
  %16 = phi i32 [ %10, %.lr.ph ], [ %.pre, %13 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = sext i32 %16 to i64
  %18 = icmp slt i64 %indvars.iv.next, %17
  br i1 %18, label %.lr.ph, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %15, %4
  %19 = tail call i32 @pthread_mutex_destroy(ptr noundef nonnull getelementptr inbounds (i8, ptr @_dmon, i64 792)) #7
  %20 = load ptr, ptr getelementptr inbounds (i8, ptr @_dmon, i64 768), align 8, !tbaa !20
  %.not = icmp eq ptr %20, null
  br i1 %.not, label %23, label %21

21:                                               ; preds = %._crit_edge
  %22 = getelementptr inbounds i8, ptr %20, i64 -8
  tail call void @free(ptr noundef nonnull %22) #7
  br label %23

23:                                               ; preds = %._crit_edge, %21
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(840) @_dmon, i8 0, i64 840, i1 false)
  store i8 0, ptr @_dmon_init, align 1, !tbaa !5
  ret void
}

declare i32 @pthread_join(i64 noundef, ptr noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare i32 @pthread_mutex_destroy(ptr noundef) local_unnamed_addr #4

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

attributes #0 = { noreturn nounwind "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 = { 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 = { "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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 "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 #5 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { noreturn nounwind }
attributes #7 = { 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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !15, i64 784}
!12 = !{!"dmon__state", !7, i64 0, !7, i64 512, !13, i64 768, !14, i64 776, !15, i64 784, !7, i64 792, !6, i64 832}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!12, !14, i64 776}
!17 = !{!13, !13, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!12, !13, i64 768}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass