; LLVM IR from kostya/crystal-benchmarks-game :: regexdna (regexdna)

; 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.fbuf = type { ptr, i64, i64 }

@stdin = external global ptr, align 8
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [1 x i8], align 1
@variants = external hidden global [10 x ptr], align 16
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@subst = external hidden global [23 x ptr], align 16
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca [2 x %struct.fbuf], align 16
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 48, ptr %6) #3
  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 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %12 = getelementptr inbounds [2 x %struct.fbuf], ptr %6, i64 0, i64 0
  call void @fb_init(ptr noundef %12)
  %13 = getelementptr inbounds [2 x %struct.fbuf], ptr %6, i64 0, i64 1
  call void @fb_init(ptr noundef %13)
  %14 = getelementptr inbounds [2 x %struct.fbuf], ptr %6, i64 0, i64 0
  %15 = load ptr, ptr @stdin, align 8, !tbaa !9
  %16 = call i64 @fb_readall(ptr noundef %14, ptr noundef %15)
  store i64 %16, ptr %8, align 8, !tbaa !11
  %17 = getelementptr inbounds [2 x %struct.fbuf], ptr %6, i64 0, i64 1
  %18 = getelementptr inbounds [2 x %struct.fbuf], ptr %6, i64 0, i64 0
  %19 = call i64 @fb_subst(ptr noundef %17, ptr noundef %18, ptr noundef @.str, ptr noundef @.str.1)
  store i64 %19, ptr %9, align 8, !tbaa !11
  store ptr @variants, ptr %7, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %32, %2
  %21 = load ptr, ptr %7, align 8, !tbaa !9
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %35

24:                                               ; preds = %20
  %25 = load ptr, ptr %7, align 8, !tbaa !9
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  %27 = getelementptr inbounds [2 x %struct.fbuf], ptr %6, i64 0, i64 1
  %28 = load ptr, ptr %7, align 8, !tbaa !9
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = call i32 @fb_countmatches(ptr noundef %27, ptr noundef %29)
  %31 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %26, i32 noundef %30)
  br label %32

32:                                               ; preds = %24
  %33 = load ptr, ptr %7, align 8, !tbaa !9
  %34 = getelementptr inbounds ptr, ptr %33, i32 1
  store ptr %34, ptr %7, align 8, !tbaa !9
  br label %20, !llvm.loop !13

35:                                               ; preds = %20
  store i64 0, ptr %10, align 8, !tbaa !11
  store i32 1, ptr %11, align 4, !tbaa !5
  store ptr @subst, ptr %7, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %54, %35
  %37 = load ptr, ptr %7, align 8, !tbaa !9
  %38 = load ptr, ptr %37, align 8, !tbaa !9
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %59

40:                                               ; preds = %36
  %41 = load i32, ptr %11, align 4, !tbaa !5
  %42 = sub nsw i32 1, %41
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [2 x %struct.fbuf], ptr %6, i64 0, i64 %43
  %45 = load i32, ptr %11, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [2 x %struct.fbuf], ptr %6, i64 0, i64 %46
  %48 = load ptr, ptr %7, align 8, !tbaa !9
  %49 = load ptr, ptr %48, align 8, !tbaa !9
  %50 = load ptr, ptr %7, align 8, !tbaa !9
  %51 = getelementptr inbounds ptr, ptr %50, i64 1
  %52 = load ptr, ptr %51, align 8, !tbaa !9
  %53 = call i64 @fb_subst(ptr noundef %44, ptr noundef %47, ptr noundef %49, ptr noundef %52)
  store i64 %53, ptr %10, align 8, !tbaa !11
  br label %54

54:                                               ; preds = %40
  %55 = load ptr, ptr %7, align 8, !tbaa !9
  %56 = getelementptr inbounds ptr, ptr %55, i64 2
  store ptr %56, ptr %7, align 8, !tbaa !9
  %57 = load i32, ptr %11, align 4, !tbaa !5
  %58 = sub nsw i32 1, %57
  store i32 %58, ptr %11, align 4, !tbaa !5
  br label %36, !llvm.loop !15

59:                                               ; preds = %36
  %60 = load i64, ptr %8, align 8, !tbaa !11
  %61 = load i64, ptr %9, align 8, !tbaa !11
  %62 = load i64, ptr %10, align 8, !tbaa !11
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %60, i64 noundef %61, i64 noundef %62)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, 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
  call void @llvm.lifetime.end.p0(i64 48, ptr %6) #3
  ret i32 0
}

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

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

; Function Attrs: nounwind uwtable
declare hidden i64 @fb_readall(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i64 @fb_subst(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #0

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

; Function Attrs: nounwind uwtable
declare hidden i32 @fb_countmatches(ptr noundef, ptr noundef) #0

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


; 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.fbuf = type { ptr, i64, i64 }

@stdin = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [1 x i8], align 1
@variants = external hidden local_unnamed_addr global [10 x ptr], align 16
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@subst = external hidden local_unnamed_addr global [23 x ptr], align 16
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = alloca [2 x %struct.fbuf], align 16
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %3) #3
  call void @fb_init(ptr noundef nonnull %3)
  %4 = getelementptr inbounds i8, ptr %3, i64 24
  call void @fb_init(ptr noundef nonnull %4)
  %5 = load ptr, ptr @stdin, align 8, !tbaa !5
  %6 = call i64 @fb_readall(ptr noundef nonnull %3, ptr noundef %5)
  %7 = call i64 @fb_subst(ptr noundef nonnull %4, ptr noundef nonnull %3, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1)
  %8 = load ptr, ptr @variants, align 16, !tbaa !5
  %.not18 = icmp eq ptr %8, null
  br i1 %.not18, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %2
  %9 = load ptr, ptr @subst, align 16, !tbaa !5
  %.not1720 = icmp eq ptr %9, null
  br i1 %.not1720, label %._crit_edge, label %.lr.ph23

.lr.ph:                                           ; preds = %2, %.lr.ph
  %10 = phi ptr [ %14, %.lr.ph ], [ %8, %2 ]
  %.01419 = phi ptr [ %13, %.lr.ph ], [ @variants, %2 ]
  %11 = call i32 @fb_countmatches(ptr noundef nonnull %4, ptr noundef nonnull %10)
  %12 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef nonnull %10, i32 noundef %11)
  %13 = getelementptr inbounds i8, ptr %.01419, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %.not = icmp eq ptr %14, null
  br i1 %.not, label %.preheader, label %.lr.ph, !llvm.loop !9

.lr.ph23:                                         ; preds = %.preheader, %.lr.ph23
  %15 = phi ptr [ %25, %.lr.ph23 ], [ %9, %.preheader ]
  %.022 = phi i32 [ %16, %.lr.ph23 ], [ 1, %.preheader ]
  %.121 = phi ptr [ %24, %.lr.ph23 ], [ @subst, %.preheader ]
  %16 = sub nuw nsw i32 1, %.022
  %17 = zext nneg i32 %16 to i64
  %18 = getelementptr inbounds [2 x %struct.fbuf], ptr %3, i64 0, i64 %17
  %19 = zext nneg i32 %.022 to i64
  %20 = getelementptr inbounds [2 x %struct.fbuf], ptr %3, i64 0, i64 %19
  %21 = getelementptr inbounds i8, ptr %.121, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  %23 = call i64 @fb_subst(ptr noundef nonnull %18, ptr noundef nonnull %20, ptr noundef nonnull %15, ptr noundef %22)
  %24 = getelementptr inbounds i8, ptr %.121, i64 16
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %.not17 = icmp eq ptr %25, null
  br i1 %.not17, label %._crit_edge, label %.lr.ph23, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph23, %.preheader
  %.013.lcssa = phi i64 [ 0, %.preheader ], [ %23, %.lr.ph23 ]
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %6, i64 noundef %7, i64 noundef %.013.lcssa)
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %3) #3
  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

; Function Attrs: nounwind uwtable
declare hidden void @fb_init(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i64 @fb_readall(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i64 @fb_subst(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare hidden i32 @fb_countmatches(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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