; LLVM IR from 0intro/wmii :: lib/libregexp/regaux.ll (renewemptythread)

; 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.Relist = type { ptr, %struct.Resublist }
%struct.Resublist = type { [32 x %struct.Resub] }
%struct.Resub = type { %union.anon, %union.anon.0 }
%union.anon = type { ptr }
%union.anon.0 = type { ptr }

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

; Function Attrs: nounwind uwtable
define dso_local ptr @_renewemptythread(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %12, ptr %10, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %48, %4
  %14 = load ptr, ptr %10, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.Relist, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %51

18:                                               ; preds = %13
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Relist, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = icmp eq ptr %21, %22
  br i1 %23, label %24, label %47

24:                                               ; preds = %18
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.Relist, ptr %26, i32 0, i32 1
  %28 = getelementptr inbounds %struct.Resublist, ptr %27, i32 0, i32 0
  %29 = getelementptr inbounds [32 x %struct.Resub], ptr %28, i64 0, i64 0
  %30 = getelementptr inbounds %struct.Resub, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !14
  %32 = icmp ult ptr %25, %31
  br i1 %32, label %33, label %46

33:                                               ; preds = %24
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = icmp sgt i32 %34, 1
  br i1 %35, label %36, label %39

36:                                               ; preds = %33
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.Relist, ptr %37, i32 0, i32 1
  call void @llvm.memset.p0.i64(ptr align 8 %38, i8 0, i64 512, i1 false)
  br label %39

39:                                               ; preds = %36, %33
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.Relist, ptr %41, i32 0, i32 1
  %43 = getelementptr inbounds %struct.Resublist, ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds [32 x %struct.Resub], ptr %43, i64 0, i64 0
  %45 = getelementptr inbounds %struct.Resub, ptr %44, i32 0, i32 0
  store ptr %40, ptr %45, align 8, !tbaa !14
  br label %46

46:                                               ; preds = %39, %24
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %71

47:                                               ; preds = %18
  br label %48

48:                                               ; preds = %47
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.Relist, ptr %49, i32 1
  store ptr %50, ptr %10, align 8, !tbaa !5
  br label %13, !llvm.loop !15

51:                                               ; preds = %13
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.Relist, ptr %53, i32 0, i32 0
  store ptr %52, ptr %54, align 8, !tbaa !11
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = icmp sgt i32 %55, 1
  br i1 %56, label %57, label %60

57:                                               ; preds = %51
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.Relist, ptr %58, i32 0, i32 1
  call void @llvm.memset.p0.i64(ptr align 8 %59, i8 0, i64 512, i1 false)
  br label %60

60:                                               ; preds = %57, %51
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.Relist, ptr %62, i32 0, i32 1
  %64 = getelementptr inbounds %struct.Resublist, ptr %63, i32 0, i32 0
  %65 = getelementptr inbounds [32 x %struct.Resub], ptr %64, i64 0, i64 0
  %66 = getelementptr inbounds %struct.Resub, ptr %65, i32 0, i32 0
  store ptr %61, ptr %66, align 8, !tbaa !14
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.Relist, ptr %67, i32 1
  store ptr %68, ptr %10, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.Relist, ptr %68, i32 0, i32 0
  store ptr null, ptr %69, align 8, !tbaa !11
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %70, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %71

71:                                               ; preds = %60, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %72 = load ptr, ptr %5, align 8
  ret ptr %72
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"Relist", !6, i64 0, !13, i64 8}
!13 = !{!"Resublist", !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef ptr @_renewemptythread(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %.not23 = icmp eq ptr %5, null
  br i1 %.not23, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4, %16
  %6 = phi ptr [ %18, %16 ], [ %5, %4 ]
  %.024 = phi ptr [ %17, %16 ], [ %0, %4 ]
  %7 = icmp eq ptr %6, %1
  br i1 %7, label %8, label %16

8:                                                ; preds = %.lr.ph
  %9 = getelementptr inbounds i8, ptr %.024, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = icmp ugt ptr %10, %3
  br i1 %11, label %12, label %25

12:                                               ; preds = %8
  %13 = icmp sgt i32 %2, 1
  br i1 %13, label %14, label %15

14:                                               ; preds = %12
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(512) %9, i8 0, i64 512, i1 false)
  br label %15

15:                                               ; preds = %14, %12
  store ptr %3, ptr %9, align 8, !tbaa !11
  br label %25

16:                                               ; preds = %.lr.ph
  %17 = getelementptr inbounds i8, ptr %.024, i64 520
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  %.not = icmp eq ptr %18, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %16, %4
  %.0.lcssa = phi ptr [ %0, %4 ], [ %17, %16 ]
  store ptr %1, ptr %.0.lcssa, align 8, !tbaa !5
  %19 = icmp sgt i32 %2, 1
  br i1 %19, label %20, label %22

20:                                               ; preds = %._crit_edge
  %21 = getelementptr inbounds i8, ptr %.0.lcssa, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(512) %21, i8 0, i64 504, i1 false)
  br label %22

22:                                               ; preds = %20, %._crit_edge
  %23 = getelementptr inbounds i8, ptr %.0.lcssa, i64 8
  store ptr %3, ptr %23, align 8, !tbaa !11
  %24 = getelementptr inbounds i8, ptr %.0.lcssa, i64 520
  store ptr null, ptr %24, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %8, %15, %22
  %.019 = phi ptr [ %24, %22 ], [ null, %15 ], [ null, %8 ]
  ret ptr %.019
}

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

attributes #0 = { nofree norecurse nosync nounwind memory(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" }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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, !7, i64 0}
!6 = !{!"Relist", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"Resublist", !8, i64 0}
!11 = !{!8, !8, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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