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

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; 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 @_renewthread(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #2 {
  %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 = %55, %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 %58

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 %54

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

37:                                               ; preds = %24
  %38 = load i32, ptr %8, align 4, !tbaa !9
  %39 = icmp sgt i32 %38, 1
  br i1 %39, label %40, label %44

40:                                               ; preds = %37
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.Relist, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %42, ptr align 8 %43, i64 512, i1 false), !tbaa.struct !15
  br label %52

44:                                               ; preds = %37
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.Relist, ptr %45, i32 0, i32 1
  %47 = getelementptr inbounds %struct.Resublist, ptr %46, i32 0, i32 0
  %48 = getelementptr inbounds [32 x %struct.Resub], ptr %47, i64 0, i64 0
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.Resublist, ptr %49, i32 0, i32 0
  %51 = getelementptr inbounds [32 x %struct.Resub], ptr %50, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %48, ptr align 8 %51, i64 16, i1 false), !tbaa.struct !16
  br label %52

52:                                               ; preds = %44, %40
  br label %53

53:                                               ; preds = %52, %24
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %81

54:                                               ; preds = %18
  br label %55

55:                                               ; preds = %54
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.Relist, ptr %56, i32 1
  store ptr %57, ptr %10, align 8, !tbaa !5
  br label %13, !llvm.loop !17

58:                                               ; preds = %13
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.Relist, ptr %60, i32 0, i32 0
  store ptr %59, ptr %61, align 8, !tbaa !11
  %62 = load i32, ptr %8, align 4, !tbaa !9
  %63 = icmp sgt i32 %62, 1
  br i1 %63, label %64, label %68

64:                                               ; preds = %58
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.Relist, ptr %65, i32 0, i32 1
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %66, ptr align 8 %67, i64 512, i1 false), !tbaa.struct !15
  br label %76

68:                                               ; preds = %58
  %69 = load ptr, ptr %10, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.Relist, ptr %69, i32 0, i32 1
  %71 = getelementptr inbounds %struct.Resublist, ptr %70, i32 0, i32 0
  %72 = getelementptr inbounds [32 x %struct.Resub], ptr %71, i64 0, i64 0
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.Resublist, ptr %73, i32 0, i32 0
  %75 = getelementptr inbounds [32 x %struct.Resub], ptr %74, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %72, ptr align 8 %75, i64 16, i1 false), !tbaa.struct !16
  br label %76

76:                                               ; preds = %68, %64
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.Relist, ptr %77, i32 1
  store ptr %78, ptr %10, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.Relist, ptr %78, i32 0, i32 0
  store ptr null, ptr %79, align 8, !tbaa !11
  %80 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %80, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %81

81:                                               ; preds = %76, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %82 = load ptr, ptr %5, align 8
  ret ptr %82
}

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

!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 = !{i64 0, i64 512, !14}
!16 = !{i64 0, i64 8, !14, i64 8, i64 8, !14}
!17 = distinct !{!17, !18}
!18 = !{!"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: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef ptr @_renewthread(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #1 {
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %.not24 = icmp eq ptr %5, null
  br i1 %.not24, label %._crit_edge, label %.lr.ph

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

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

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

15:                                               ; preds = %13
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(512) %10, ptr noundef nonnull align 8 dereferenceable(512) %3, i64 512, i1 false), !tbaa.struct !12
  br label %26

16:                                               ; preds = %13
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %10, ptr noundef nonnull align 8 dereferenceable(16) %3, i64 16, i1 false), !tbaa.struct !13
  br label %26

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

._crit_edge:                                      ; preds = %17, %4
  %.0.lcssa = phi ptr [ %0, %4 ], [ %18, %17 ]
  store ptr %1, ptr %.0.lcssa, align 8, !tbaa !5
  %20 = icmp sgt i32 %2, 1
  %21 = getelementptr inbounds i8, ptr %.0.lcssa, i64 8
  br i1 %20, label %22, label %23

22:                                               ; preds = %._crit_edge
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(512) %21, ptr noundef nonnull align 8 dereferenceable(512) %3, i64 512, i1 false), !tbaa.struct !12
  br label %24

23:                                               ; preds = %._crit_edge
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %21, ptr noundef nonnull align 8 dereferenceable(16) %3, i64 16, i1 false), !tbaa.struct !13
  br label %24

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

26:                                               ; preds = %8, %16, %15, %24
  %.021 = phi ptr [ %25, %24 ], [ null, %15 ], [ null, %16 ], [ null, %8 ]
  ret ptr %.021
}

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

!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 = !{i64 0, i64 512, !11}
!13 = !{i64 0, i64 8, !11, i64 8, i64 8, !11}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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