; LLVM IR from humz2k/sugaryc :: ext/bdwgc/tests (threadleak)

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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [32 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca [5 x i64], align 16
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 40, ptr %4) #5
  call void @GC_set_find_leak(i32 noundef 1)
  call void @GC_init()
  call void @GC_allow_register_threads()
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %36, %0
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 5
  br i1 %10, label %11, label %39

11:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %12 = getelementptr inbounds [5 x i64], ptr %4, i64 0, i64 0
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i64, ptr %12, i64 %14
  %16 = call i32 @GC_pthread_create(ptr noundef %15, ptr noundef null, ptr noundef @test, ptr noundef null)
  store i32 %16, ptr %5, align 4, !tbaa !5
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %32

19:                                               ; preds = %11
  %20 = load ptr, ptr @stderr, align 8, !tbaa !9
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = call ptr @strerror(i32 noundef %22) #5
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef @.str, i32 noundef %21, ptr noundef %23) #5
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = icmp sgt i32 %25, 1
  br i1 %26, label %27, label %31

27:                                               ; preds = %19
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = icmp eq i32 11, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %27
  store i32 2, ptr %6, align 4
  br label %33

31:                                               ; preds = %27, %19
  call void @exit(i32 noundef 2) #6
  unreachable

32:                                               ; preds = %11
  store i32 0, ptr %6, align 4
  br label %33

33:                                               ; preds = %32, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  %34 = load i32, ptr %6, align 4
  switch i32 %34, label %65 [
    i32 0, label %35
    i32 2, label %39
  ]

35:                                               ; preds = %33
  br label %36

36:                                               ; preds = %35
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !11

39:                                               ; preds = %33, %8
  %40 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %40, ptr %3, align 4, !tbaa !5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %59, %39
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = icmp slt i32 %42, %43
  br i1 %44, label %45, label %62

45:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [5 x i64], ptr %4, i64 0, i64 %47
  %49 = load i64, ptr %48, align 8, !tbaa !13
  %50 = call i32 @GC_pthread_join(i64 noundef %49, ptr noundef null)
  store i32 %50, ptr %7, align 4, !tbaa !5
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %58

53:                                               ; preds = %45
  %54 = load ptr, ptr @stderr, align 8, !tbaa !9
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %54, ptr noundef @.str.1, i32 noundef %55, i32 noundef %56) #5
  call void @exit(i32 noundef 2) #6
  unreachable

58:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %2, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %2, align 4, !tbaa !5
  br label %41, !llvm.loop !15

62:                                               ; preds = %41
  call void @GC_gcollect()
  call void @GC_gcollect()
  call void @GC_gcollect()
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 40, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  %64 = load i32, ptr %1, align 4
  ret i32 %64

65:                                               ; preds = %33
  unreachable
}

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

declare void @GC_set_find_leak(i32 noundef) #2

declare void @GC_init() #2

declare void @GC_allow_register_threads() #2

declare i32 @GC_pthread_create(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @test(ptr noundef) #0

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #4

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

declare i32 @GC_pthread_join(i64 noundef, ptr noundef) #2

declare void @GC_gcollect() #2

declare i32 @printf(ptr noundef, ...) #2

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 = { "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 "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 = { nounwind }
attributes #6 = { noreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !12}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [32 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca [5 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %1) #6
  tail call void @GC_set_find_leak(i32 noundef 1) #6
  tail call void @GC_init() #6
  tail call void @GC_allow_register_threads() #6
  %2 = call i32 @GC_pthread_create(ptr noundef nonnull %1, ptr noundef null, ptr noundef nonnull @test, ptr noundef null) #6
  %.not.not = icmp eq i32 %2, 0
  br i1 %.not.not, label %10, label %3

3:                                                ; preds = %19, %16, %13, %10, %0
  %4 = phi i1 [ false, %0 ], [ false, %10 ], [ true, %13 ], [ true, %16 ], [ true, %19 ]
  %.01929.lcssa.wide = phi i32 [ 0, %0 ], [ 1, %10 ], [ 2, %13 ], [ 3, %16 ], [ 4, %19 ]
  %.lcssa34 = phi i32 [ %2, %0 ], [ %12, %10 ], [ %15, %13 ], [ %18, %16 ], [ %21, %19 ]
  %5 = load ptr, ptr @stderr, align 8, !tbaa !5
  %6 = call ptr @strerror(i32 noundef %.lcssa34) #6
  %7 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str, i32 noundef %.01929.lcssa.wide, ptr noundef %6) #7
  %8 = icmp eq i32 %.lcssa34, 11
  %or.cond = and i1 %4, %8
  br i1 %or.cond, label %.loopexit, label %9

9:                                                ; preds = %3
  call void @exit(i32 noundef 2) #8
  unreachable

10:                                               ; preds = %0
  %11 = getelementptr inbounds i8, ptr %1, i64 8
  %12 = call i32 @GC_pthread_create(ptr noundef nonnull %11, ptr noundef null, ptr noundef nonnull @test, ptr noundef null) #6
  %.not.1 = icmp eq i32 %12, 0
  br i1 %.not.1, label %13, label %3

13:                                               ; preds = %10
  %14 = getelementptr inbounds i8, ptr %1, i64 16
  %15 = call i32 @GC_pthread_create(ptr noundef nonnull %14, ptr noundef null, ptr noundef nonnull @test, ptr noundef null) #6
  %.not.2 = icmp eq i32 %15, 0
  br i1 %.not.2, label %16, label %3

16:                                               ; preds = %13
  %17 = getelementptr inbounds i8, ptr %1, i64 24
  %18 = call i32 @GC_pthread_create(ptr noundef nonnull %17, ptr noundef null, ptr noundef nonnull @test, ptr noundef null) #6
  %.not.3 = icmp eq i32 %18, 0
  br i1 %.not.3, label %19, label %3

19:                                               ; preds = %16
  %20 = getelementptr inbounds i8, ptr %1, i64 32
  %21 = call i32 @GC_pthread_create(ptr noundef nonnull %20, ptr noundef null, ptr noundef nonnull @test, ptr noundef null) #6
  %.not.4 = icmp eq i32 %21, 0
  br i1 %.not.4, label %.lr.ph.preheader, label %3

.loopexit:                                        ; preds = %3
  br i1 %.not.not, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %19, %.loopexit
  %.0192742 = phi i32 [ %.01929.lcssa.wide, %.loopexit ], [ 5, %19 ]
  %wide.trip.count = zext nneg i32 %.0192742 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %29
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %29 ]
  %22 = getelementptr inbounds [5 x i64], ptr %1, i64 0, i64 %indvars.iv
  %23 = load i64, ptr %22, align 8, !tbaa !9
  %24 = call i32 @GC_pthread_join(i64 noundef %23, ptr noundef null) #6
  %.not22 = icmp eq i32 %24, 0
  br i1 %.not22, label %29, label %25

25:                                               ; preds = %.lr.ph
  %26 = trunc nuw nsw i64 %indvars.iv to i32
  %27 = load ptr, ptr @stderr, align 8, !tbaa !5
  %28 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef nonnull @.str.1, i32 noundef %26, i32 noundef %24) #7
  call void @exit(i32 noundef 2) #8
  unreachable

29:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %29, %.loopexit
  call void @GC_gcollect() #6
  call void @GC_gcollect() #6
  call void @GC_gcollect() #6
  %30 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %1) #6
  ret i32 0
}

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

declare void @GC_set_find_leak(i32 noundef) local_unnamed_addr #2

declare void @GC_init() local_unnamed_addr #2

declare void @GC_allow_register_threads() local_unnamed_addr #2

declare i32 @GC_pthread_create(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden ptr @test(ptr noundef) #0

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #5

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

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

declare void @GC_gcollect() local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nofree 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 = { 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 = { 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 #6 = { nounwind }
attributes #7 = { cold nounwind }
attributes #8 = { noreturn 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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