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

; 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 }
%struct.dmon_watch_id = type { i32 }

@_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_unwatch = external hidden unnamed_addr constant [33 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [22 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
declare hidden void @_dmon_unwatch(ptr noundef) #2

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

; Function Attrs: nounwind
declare i32 @pthread_mutex_lock(ptr noundef) #3

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @dmon_unwatch(i32 %0) #2 {
  %2 = alloca %struct.dmon_watch_id, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = getelementptr inbounds %struct.dmon_watch_id, ptr %2, i32 0, i32 0
  store i32 %0, ptr %5, align 4
  %6 = load i8, ptr @_dmon_init, align 1, !tbaa !5, !range !9, !noundef !10
  %7 = trunc i8 %6 to i1
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  br label %10

9:                                                ; preds = %1
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 1308, ptr noundef @__PRETTY_FUNCTION__.dmon_unwatch) #4
  unreachable

10:                                               ; preds = %8
  %11 = getelementptr inbounds %struct.dmon_watch_id, ptr %2, i32 0, i32 0
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = icmp ugt i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %10
  br label %16

15:                                               ; preds = %10
  call void @__assert_fail(ptr noundef @.str.18, ptr noundef @.str.1, i32 noundef 1309, ptr noundef @__PRETTY_FUNCTION__.dmon_unwatch) #4
  unreachable

16:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  %17 = getelementptr inbounds %struct.dmon_watch_id, ptr %2, i32 0, i32 0
  %18 = load i32, ptr %17, align 4, !tbaa !11
  %19 = sub i32 %18, 1
  store i32 %19, ptr %3, align 4, !tbaa !14
  %20 = load i32, ptr %3, align 4, !tbaa !14
  %21 = icmp slt i32 %20, 64
  br i1 %21, label %22, label %23

22:                                               ; preds = %16
  br label %24

23:                                               ; preds = %16
  call void @__assert_fail(ptr noundef @.str.19, ptr noundef @.str.1, i32 noundef 1311, ptr noundef @__PRETTY_FUNCTION__.dmon_unwatch) #4
  unreachable

24:                                               ; preds = %22
  %25 = load i32, ptr %3, align 4, !tbaa !14
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [64 x ptr], ptr @_dmon, i64 0, i64 %26
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %31

30:                                               ; preds = %24
  br label %32

31:                                               ; preds = %24
  call void @__assert_fail(ptr noundef @.str.20, ptr noundef @.str.1, i32 noundef 1312, ptr noundef @__PRETTY_FUNCTION__.dmon_unwatch) #4
  unreachable

32:                                               ; preds = %30
  %33 = load i32, ptr getelementptr inbounds (%struct.dmon__state, ptr @_dmon, i32 0, i32 3), align 8, !tbaa !17
  %34 = icmp sgt i32 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %32
  br label %37

36:                                               ; preds = %32
  call void @__assert_fail(ptr noundef @.str.21, ptr noundef @.str.1, i32 noundef 1313, ptr noundef @__PRETTY_FUNCTION__.dmon_unwatch) #4
  unreachable

37:                                               ; preds = %35
  %38 = load i32, ptr %3, align 4, !tbaa !14
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [64 x ptr], ptr @_dmon, i64 0, i64 %39
  %41 = load ptr, ptr %40, align 8, !tbaa !15
  %42 = icmp ne ptr %41, null
  br i1 %42, label %43, label %66

43:                                               ; preds = %37
  %44 = call i32 @pthread_mutex_lock(ptr noundef getelementptr inbounds (%struct.dmon__state, ptr @_dmon, i32 0, i32 5)) #5
  %45 = load i32, ptr %3, align 4, !tbaa !14
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [64 x ptr], ptr @_dmon, i64 0, i64 %46
  %48 = load ptr, ptr %47, align 8, !tbaa !15
  call void @_dmon_unwatch(ptr noundef %48)
  %49 = load i32, ptr %3, align 4, !tbaa !14
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [64 x ptr], ptr @_dmon, i64 0, i64 %50
  %52 = load ptr, ptr %51, align 8, !tbaa !15
  call void @free(ptr noundef %52) #5
  %53 = load i32, ptr %3, align 4, !tbaa !14
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [64 x ptr], ptr @_dmon, i64 0, i64 %54
  store ptr null, ptr %55, align 8, !tbaa !15
  %56 = load i32, ptr getelementptr inbounds (%struct.dmon__state, ptr @_dmon, i32 0, i32 3), align 8, !tbaa !17
  %57 = add nsw i32 %56, -1
  store i32 %57, ptr getelementptr inbounds (%struct.dmon__state, ptr @_dmon, i32 0, i32 3), align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %58 = load i32, ptr getelementptr inbounds (%struct.dmon__state, ptr @_dmon, i32 0, i32 3), align 8, !tbaa !17
  %59 = sub nsw i32 64, %58
  store i32 %59, ptr %4, align 4, !tbaa !14
  %60 = load i32, ptr %3, align 4, !tbaa !14
  %61 = load i32, ptr %4, align 4, !tbaa !14
  %62 = sub nsw i32 %61, 1
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [64 x i32], ptr getelementptr inbounds (%struct.dmon__state, ptr @_dmon, i32 0, i32 1), i64 0, i64 %63
  store i32 %60, ptr %64, align 4, !tbaa !14
  %65 = call i32 @pthread_mutex_unlock(ptr noundef getelementptr inbounds (%struct.dmon__state, ptr @_dmon, i32 0, i32 5)) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %66

66:                                               ; preds = %43, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret void
}

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 = { 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 #4 = { noreturn nounwind }
attributes #5 = { 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, !13, i64 0}
!12 = !{!"", !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"any pointer", !7, i64 0}
!17 = !{!18, !13, i64 776}
!18 = !{!"dmon__state", !7, i64 0, !7, i64 512, !16, i64 768, !13, i64 776, !19, i64 784, !7, i64 792, !6, i64 832}
!19 = !{!"long", !7, i64 0}


; 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_unwatch = external hidden unnamed_addr constant [33 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [22 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
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 #2

; Function Attrs: nounwind
declare i32 @pthread_mutex_lock(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) local_unnamed_addr #3

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

4:                                                ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 1308, ptr noundef nonnull @__PRETTY_FUNCTION__.dmon_unwatch) #4
  unreachable

5:                                                ; preds = %1
  %.not = icmp eq i32 %0, 0
  br i1 %.not, label %6, label %7

6:                                                ; preds = %5
  tail call void @__assert_fail(ptr noundef nonnull @.str.18, ptr noundef nonnull @.str.1, i32 noundef 1309, ptr noundef nonnull @__PRETTY_FUNCTION__.dmon_unwatch) #4
  unreachable

7:                                                ; preds = %5
  %8 = add i32 %0, -1
  %9 = icmp slt i32 %8, 64
  br i1 %9, label %11, label %10

10:                                               ; preds = %7
  tail call void @__assert_fail(ptr noundef nonnull @.str.19, ptr noundef nonnull @.str.1, i32 noundef 1311, ptr noundef nonnull @__PRETTY_FUNCTION__.dmon_unwatch) #4
  unreachable

11:                                               ; preds = %7
  %12 = sext i32 %8 to i64
  %13 = getelementptr inbounds [64 x ptr], ptr @_dmon, i64 0, i64 %12
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %.not10 = icmp eq ptr %14, null
  br i1 %.not10, label %15, label %16

15:                                               ; preds = %11
  tail call void @__assert_fail(ptr noundef nonnull @.str.20, ptr noundef nonnull @.str.1, i32 noundef 1312, ptr noundef nonnull @__PRETTY_FUNCTION__.dmon_unwatch) #4
  unreachable

16:                                               ; preds = %11
  %17 = load i32, ptr getelementptr inbounds (i8, ptr @_dmon, i64 776), align 8, !tbaa !13
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %20, label %19

19:                                               ; preds = %16
  tail call void @__assert_fail(ptr noundef nonnull @.str.21, ptr noundef nonnull @.str.1, i32 noundef 1313, ptr noundef nonnull @__PRETTY_FUNCTION__.dmon_unwatch) #4
  unreachable

20:                                               ; preds = %16
  %21 = tail call i32 @pthread_mutex_lock(ptr noundef nonnull getelementptr inbounds (i8, ptr @_dmon, i64 792)) #5
  %22 = load ptr, ptr %13, align 8, !tbaa !11
  tail call void @_dmon_unwatch(ptr noundef %22)
  %23 = load ptr, ptr %13, align 8, !tbaa !11
  tail call void @free(ptr noundef %23) #5
  store ptr null, ptr %13, align 8, !tbaa !11
  %24 = load i32, ptr getelementptr inbounds (i8, ptr @_dmon, i64 776), align 8, !tbaa !13
  %25 = add nsw i32 %24, -1
  store i32 %25, ptr getelementptr inbounds (i8, ptr @_dmon, i64 776), align 8, !tbaa !13
  %26 = sub i32 64, %24
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [64 x i32], ptr getelementptr inbounds (i8, ptr @_dmon, i64 512), i64 0, i64 %27
  store i32 %8, ptr %28, align 4, !tbaa !17
  %29 = tail call i32 @pthread_mutex_unlock(ptr noundef nonnull getelementptr inbounds (i8, ptr @_dmon, i64 792)) #5
  ret void
}

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 = { 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 #3 = { 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 #4 = { noreturn nounwind }
attributes #5 = { 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, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !15, i64 776}
!14 = !{!"dmon__state", !7, i64 0, !7, i64 512, !12, i64 768, !15, i64 776, !16, i64 784, !7, i64 792, !6, i64 832}
!15 = !{!"int", !7, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!15, !15, i64 0}


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