; LLVM IR from howerj/shrink :: shrink (shrink_tests)

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

@__const.shrink_tests.ts = external hidden unnamed_addr constant [4 x ptr], align 16

; 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 i32 @shrink_tests() #1 {
  %1 = alloca i32, align 4
  %2 = alloca [4 x ptr], align 16
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 32, ptr %2) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %2, ptr align 16 @__const.shrink_tests.ts, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  store i64 0, ptr %3, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %41, %0
  %8 = load i64, ptr %3, align 8, !tbaa !5
  %9 = icmp ult i64 %8, 4
  br i1 %9, label %11, label %10

10:                                               ; preds = %7
  store i32 2, ptr %4, align 4
  br label %44

11:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %35, %11
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = icmp sle i32 %13, 4
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  store i32 5, ptr %4, align 4
  br label %38

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = load i64, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds [4 x ptr], ptr %2, i64 0, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = load i64, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds [4 x ptr], ptr %2, i64 0, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = call i64 @strlen(ptr noundef %23) #6
  %25 = add i64 %24, 1
  %26 = call i32 @test(i32 noundef %17, ptr noundef %20, i64 noundef %25)
  store i32 %26, ptr %6, align 4, !tbaa !9
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = icmp slt i32 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %16
  %30 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %30, ptr %1, align 4
  store i32 1, ptr %4, align 4
  br label %32

31:                                               ; preds = %16
  store i32 0, ptr %4, align 4
  br label %32

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

34:                                               ; preds = %32
  br label %35

35:                                               ; preds = %34
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %5, align 4, !tbaa !9
  br label %12, !llvm.loop !13

38:                                               ; preds = %32, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  %39 = load i32, ptr %4, align 4
  switch i32 %39, label %44 [
    i32 5, label %40
  ]

40:                                               ; preds = %38
  br label %41

41:                                               ; preds = %40
  %42 = load i64, ptr %3, align 8, !tbaa !5
  %43 = add i64 %42, 1
  store i64 %43, ptr %3, align 8, !tbaa !5
  br label %7, !llvm.loop !15

44:                                               ; preds = %38, %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  %45 = load i32, ptr %4, align 4
  switch i32 %45, label %47 [
    i32 2, label %46
  ]

46:                                               ; preds = %44
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  br label %47

47:                                               ; preds = %46, %44
  call void @llvm.lifetime.end.p0(i64 32, ptr %2) #5
  %48 = load i32, ptr %1, align 4
  ret i32 %48
}

; 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) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @test(i32 noundef, ptr noundef, i64 noundef) #3

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #4

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: readwrite) }
attributes #3 = { inlinehint 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 #4 = { nounwind willreturn memory(read) "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 = { nounwind willreturn memory(read) }

!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 = !{!"long", !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, !12, i64 0}
!12 = !{!"any pointer", !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"

@__const.shrink_tests.ts = external hidden unnamed_addr constant [4 x ptr], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @shrink_tests() local_unnamed_addr #0 {
.preheader:
  %0 = load ptr, ptr @__const.shrink_tests.ts, align 16, !tbaa !5
  %1 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #4
  %2 = add i64 %1, 1
  %3 = tail call i32 @test(i32 noundef 0, ptr noundef %0, i64 noundef %2)
  %4 = icmp sgt i32 %3, -1
  br i1 %4, label %5, label %.loopexit

5:                                                ; preds = %.preheader
  %6 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #4
  %7 = add i64 %6, 1
  %8 = tail call i32 @test(i32 noundef 1, ptr noundef %0, i64 noundef %7)
  %9 = icmp sgt i32 %8, -1
  br i1 %9, label %10, label %.loopexit

10:                                               ; preds = %5
  %11 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #4
  %12 = add i64 %11, 1
  %13 = tail call i32 @test(i32 noundef 2, ptr noundef %0, i64 noundef %12)
  %14 = icmp sgt i32 %13, -1
  br i1 %14, label %15, label %.loopexit

15:                                               ; preds = %10
  %16 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #4
  %17 = add i64 %16, 1
  %18 = tail call i32 @test(i32 noundef 3, ptr noundef %0, i64 noundef %17)
  %19 = icmp sgt i32 %18, -1
  br i1 %19, label %20, label %.loopexit

20:                                               ; preds = %15
  %21 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #4
  %22 = add i64 %21, 1
  %23 = tail call i32 @test(i32 noundef 4, ptr noundef %0, i64 noundef %22)
  %24 = icmp sgt i32 %23, -1
  br i1 %24, label %.preheader.1, label %.loopexit

.preheader.1:                                     ; preds = %20
  %25 = load ptr, ptr getelementptr inbounds (i8, ptr @__const.shrink_tests.ts, i64 8), align 8, !tbaa !5
  %26 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %25) #4
  %27 = add i64 %26, 1
  %28 = tail call i32 @test(i32 noundef 0, ptr noundef %25, i64 noundef %27)
  %29 = icmp sgt i32 %28, -1
  br i1 %29, label %30, label %.loopexit

30:                                               ; preds = %.preheader.1
  %31 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %25) #4
  %32 = add i64 %31, 1
  %33 = tail call i32 @test(i32 noundef 1, ptr noundef %25, i64 noundef %32)
  %34 = icmp sgt i32 %33, -1
  br i1 %34, label %35, label %.loopexit

35:                                               ; preds = %30
  %36 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %25) #4
  %37 = add i64 %36, 1
  %38 = tail call i32 @test(i32 noundef 2, ptr noundef %25, i64 noundef %37)
  %39 = icmp sgt i32 %38, -1
  br i1 %39, label %40, label %.loopexit

40:                                               ; preds = %35
  %41 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %25) #4
  %42 = add i64 %41, 1
  %43 = tail call i32 @test(i32 noundef 3, ptr noundef %25, i64 noundef %42)
  %44 = icmp sgt i32 %43, -1
  br i1 %44, label %45, label %.loopexit

45:                                               ; preds = %40
  %46 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %25) #4
  %47 = add i64 %46, 1
  %48 = tail call i32 @test(i32 noundef 4, ptr noundef %25, i64 noundef %47)
  %49 = icmp sgt i32 %48, -1
  br i1 %49, label %.preheader.2, label %.loopexit

.preheader.2:                                     ; preds = %45
  %50 = load ptr, ptr getelementptr inbounds (i8, ptr @__const.shrink_tests.ts, i64 16), align 16, !tbaa !5
  %51 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %50) #4
  %52 = add i64 %51, 1
  %53 = tail call i32 @test(i32 noundef 0, ptr noundef %50, i64 noundef %52)
  %54 = icmp sgt i32 %53, -1
  br i1 %54, label %55, label %.loopexit

55:                                               ; preds = %.preheader.2
  %56 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %50) #4
  %57 = add i64 %56, 1
  %58 = tail call i32 @test(i32 noundef 1, ptr noundef %50, i64 noundef %57)
  %59 = icmp sgt i32 %58, -1
  br i1 %59, label %60, label %.loopexit

60:                                               ; preds = %55
  %61 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %50) #4
  %62 = add i64 %61, 1
  %63 = tail call i32 @test(i32 noundef 2, ptr noundef %50, i64 noundef %62)
  %64 = icmp sgt i32 %63, -1
  br i1 %64, label %65, label %.loopexit

65:                                               ; preds = %60
  %66 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %50) #4
  %67 = add i64 %66, 1
  %68 = tail call i32 @test(i32 noundef 3, ptr noundef %50, i64 noundef %67)
  %69 = icmp sgt i32 %68, -1
  br i1 %69, label %70, label %.loopexit

70:                                               ; preds = %65
  %71 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %50) #4
  %72 = add i64 %71, 1
  %73 = tail call i32 @test(i32 noundef 4, ptr noundef %50, i64 noundef %72)
  %74 = icmp sgt i32 %73, -1
  br i1 %74, label %.preheader.3, label %.loopexit

.preheader.3:                                     ; preds = %70
  %75 = load ptr, ptr getelementptr inbounds (i8, ptr @__const.shrink_tests.ts, i64 24), align 8, !tbaa !5
  %76 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %75) #4
  %77 = add i64 %76, 1
  %78 = tail call i32 @test(i32 noundef 0, ptr noundef %75, i64 noundef %77)
  %79 = icmp sgt i32 %78, -1
  br i1 %79, label %80, label %.loopexit

80:                                               ; preds = %.preheader.3
  %81 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %75) #4
  %82 = add i64 %81, 1
  %83 = tail call i32 @test(i32 noundef 1, ptr noundef %75, i64 noundef %82)
  %84 = icmp sgt i32 %83, -1
  br i1 %84, label %85, label %.loopexit

85:                                               ; preds = %80
  %86 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %75) #4
  %87 = add i64 %86, 1
  %88 = tail call i32 @test(i32 noundef 2, ptr noundef %75, i64 noundef %87)
  %89 = icmp sgt i32 %88, -1
  br i1 %89, label %90, label %.loopexit

90:                                               ; preds = %85
  %91 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %75) #4
  %92 = add i64 %91, 1
  %93 = tail call i32 @test(i32 noundef 3, ptr noundef %75, i64 noundef %92)
  %94 = icmp sgt i32 %93, -1
  br i1 %94, label %95, label %.loopexit

95:                                               ; preds = %90
  %96 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %75) #4
  %97 = add i64 %96, 1
  %98 = tail call i32 @test(i32 noundef 4, ptr noundef %75, i64 noundef %97)
  %spec.select28 = tail call i32 @llvm.smin.i32(i32 %98, i32 0)
  br label %.loopexit

.loopexit:                                        ; preds = %95, %.preheader, %5, %10, %15, %20, %.preheader.1, %30, %35, %40, %45, %.preheader.2, %55, %60, %65, %70, %.preheader.3, %80, %85, %90
  %spec.select = phi i32 [ %3, %.preheader ], [ %8, %5 ], [ %13, %10 ], [ %18, %15 ], [ %23, %20 ], [ %28, %.preheader.1 ], [ %33, %30 ], [ %38, %35 ], [ %43, %40 ], [ %48, %45 ], [ %53, %.preheader.2 ], [ %58, %55 ], [ %63, %60 ], [ %68, %65 ], [ %73, %70 ], [ %78, %.preheader.3 ], [ %83, %80 ], [ %88, %85 ], [ %93, %90 ], [ %spec.select28, %95 ]
  ret i32 %spec.select
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @test(i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #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 = { inlinehint 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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind willreturn memory(read) }

!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"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass