; LLVM IR from 0intro/wmii :: lib/libstuff/util (grep)

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

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

12:                                               ; preds = %44, %3
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %47

16:                                               ; preds = %12
  store i32 0, ptr %9, align 4, !tbaa !9
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %24

19:                                               ; preds = %16
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  %23 = call i32 @regexec9(ptr noundef %20, ptr noundef %22, ptr noundef null, i32 noundef 0)
  store i32 %23, ptr %9, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %19, %16
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %31

27:                                               ; preds = %24
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = and i32 %28, 1
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %38

31:                                               ; preds = %27, %24
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %43, label %34

34:                                               ; preds = %31
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = and i32 %35, 1
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %43

38:                                               ; preds = %34, %27
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds ptr, ptr %41, i32 1
  store ptr %42, ptr %8, align 8, !tbaa !5
  store ptr %40, ptr %41, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %38, %34, %31
  br label %44

44:                                               ; preds = %43
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds ptr, ptr %45, i32 1
  store ptr %46, ptr %7, align 8, !tbaa !5
  br label %12, !llvm.loop !11

47:                                               ; preds = %12
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr null, ptr %48, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

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

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

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

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 }

!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 = distinct !{!11, !12}
!12 = !{!"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: nounwind uwtable
define dso_local void @grep(ptr nocapture noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %.not30 = icmp eq ptr %4, null
  br i1 %.not30, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %.not17 = icmp eq ptr %1, null
  %5 = and i32 %2, 1
  %.not1926 = icmp eq i32 %5, 0
  br i1 %.not17, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph
  br i1 %.not1926, label %._crit_edge, label %.thread.us

.thread.us:                                       ; preds = %.lr.ph.split.us, %.thread.us
  %6 = phi ptr [ %8, %.thread.us ], [ %4, %.lr.ph.split.us ]
  %.01332.us = phi ptr [ %7, %.thread.us ], [ %0, %.lr.ph.split.us ]
  %7 = getelementptr i8, ptr %.01332.us, i64 8
  store ptr %6, ptr %.01332.us, align 8, !tbaa !5
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %.not.us = icmp eq ptr %8, null
  br i1 %.not.us, label %._crit_edge, label %.thread.us, !llvm.loop !9

.lr.ph.split:                                     ; preds = %.lr.ph
  br i1 %.not1926, label %.lr.ph.split.split, label %.lr.ph.split.split.us

.lr.ph.split.split.us:                            ; preds = %.lr.ph.split, %14
  %9 = phi ptr [ %16, %14 ], [ %4, %.lr.ph.split ]
  %.01332.us33 = phi ptr [ %.1.us36, %14 ], [ %0, %.lr.ph.split ]
  %.01431.us34 = phi ptr [ %15, %14 ], [ %0, %.lr.ph.split ]
  %10 = tail call i32 @regexec9(ptr noundef nonnull %1, ptr noundef nonnull %9, ptr noundef null, i32 noundef 0) #2
  %.not18.us.not = icmp eq i32 %10, 0
  br i1 %.not18.us.not, label %11, label %14

11:                                               ; preds = %.lr.ph.split.split.us
  %12 = load ptr, ptr %.01431.us34, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %.01332.us33, i64 8
  store ptr %12, ptr %.01332.us33, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %11, %.lr.ph.split.split.us
  %.1.us36 = phi ptr [ %.01332.us33, %.lr.ph.split.split.us ], [ %13, %11 ]
  %15 = getelementptr inbounds i8, ptr %.01431.us34, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %.not.us37 = icmp eq ptr %16, null
  br i1 %.not.us37, label %._crit_edge, label %.lr.ph.split.split.us, !llvm.loop !9

.lr.ph.split.split:                               ; preds = %.lr.ph.split, %22
  %17 = phi ptr [ %24, %22 ], [ %4, %.lr.ph.split ]
  %.01332 = phi ptr [ %.1, %22 ], [ %0, %.lr.ph.split ]
  %.01431 = phi ptr [ %23, %22 ], [ %0, %.lr.ph.split ]
  %18 = tail call i32 @regexec9(ptr noundef nonnull %1, ptr noundef nonnull %17, ptr noundef null, i32 noundef 0) #2
  %.not18.not = icmp eq i32 %18, 0
  br i1 %.not18.not, label %22, label %19

19:                                               ; preds = %.lr.ph.split.split
  %20 = load ptr, ptr %.01431, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %.01332, i64 8
  store ptr %20, ptr %.01332, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %.lr.ph.split.split, %19
  %.1 = phi ptr [ %21, %19 ], [ %.01332, %.lr.ph.split.split ]
  %23 = getelementptr inbounds i8, ptr %.01431, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %.not = icmp eq ptr %24, null
  br i1 %.not, label %._crit_edge, label %.lr.ph.split.split, !llvm.loop !9

._crit_edge:                                      ; preds = %14, %22, %.thread.us, %.lr.ph.split.us, %3
  %.013.lcssa = phi ptr [ %0, %3 ], [ %0, %.lr.ph.split.us ], [ %7, %.thread.us ], [ %.1, %22 ], [ %.1.us36, %14 ]
  store ptr null, ptr %.013.lcssa, align 8, !tbaa !5
  ret void
}

declare i32 @regexec9(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

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 = { "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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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