; LLVM IR from mirohs/gc :: util (trim)

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

@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #0

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #1

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

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

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

13:                                               ; preds = %41, %2
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = getelementptr inbounds %struct.String, ptr %4, i32 0, i32 1
  %16 = load i32, ptr %15, align 8, !tbaa !9
  %17 = icmp slt i32 %14, %16
  br i1 %17, label %18, label %38

18:                                               ; preds = %13
  %19 = getelementptr inbounds %struct.String, ptr %4, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i8, ptr %20, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !13
  %25 = sext i8 %24 to i32
  %26 = icmp eq i32 %25, 32
  br i1 %26, label %36, label %27

27:                                               ; preds = %18
  %28 = getelementptr inbounds %struct.String, ptr %4, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !12
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i8, ptr %29, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !13
  %34 = sext i8 %33 to i32
  %35 = icmp eq i32 %34, 9
  br label %36

36:                                               ; preds = %27, %18
  %37 = phi i1 [ true, %18 ], [ %35, %27 ]
  br label %38

38:                                               ; preds = %36, %13
  %39 = phi i1 [ false, %13 ], [ %37, %36 ]
  br i1 %39, label %40, label %44

40:                                               ; preds = %38
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %5, align 4, !tbaa !5
  br label %13, !llvm.loop !14

44:                                               ; preds = %38
  br label %45

45:                                               ; preds = %72, %44
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = icmp sge i32 %46, %47
  br i1 %48, label %49, label %69

49:                                               ; preds = %45
  %50 = getelementptr inbounds %struct.String, ptr %4, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !12
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i8, ptr %51, i64 %53
  %55 = load i8, ptr %54, align 1, !tbaa !13
  %56 = sext i8 %55 to i32
  %57 = icmp eq i32 %56, 32
  br i1 %57, label %67, label %58

58:                                               ; preds = %49
  %59 = getelementptr inbounds %struct.String, ptr %4, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !12
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds i8, ptr %60, i64 %62
  %64 = load i8, ptr %63, align 1, !tbaa !13
  %65 = sext i8 %64 to i32
  %66 = icmp eq i32 %65, 9
  br label %67

67:                                               ; preds = %58, %49
  %68 = phi i1 [ true, %49 ], [ %66, %58 ]
  br label %69

69:                                               ; preds = %67, %45
  %70 = phi i1 [ false, %45 ], [ %68, %67 ]
  br i1 %70, label %71, label %75

71:                                               ; preds = %69
  br label %72

72:                                               ; preds = %71
  %73 = load i32, ptr %6, align 4, !tbaa !5
  %74 = add nsw i32 %73, -1
  store i32 %74, ptr %6, align 4, !tbaa !5
  br label %45, !llvm.loop !16

75:                                               ; preds = %69
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %76 = load i32, ptr %6, align 4, !tbaa !5
  %77 = load i32, ptr %5, align 4, !tbaa !5
  %78 = sub nsw i32 %76, %77
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %7, align 4, !tbaa !5
  %80 = load i32, ptr %7, align 4, !tbaa !5
  %81 = icmp sge i32 %80, 0
  br i1 %81, label %85, label %82

82:                                               ; preds = %75
  %83 = load ptr, ptr @stderr, align 8, !tbaa !17
  %84 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %83, ptr noundef @.str.28, ptr noundef @.str.1, i32 noundef 237, ptr noundef @.str.29, ptr noundef @.str.4) #4
  call void @exit(i32 noundef 1) #5
  unreachable

85:                                               ; preds = %75
  %86 = load i32, ptr %7, align 4, !tbaa !5
  %87 = getelementptr inbounds %struct.String, ptr %4, i32 0, i32 1
  %88 = load i32, ptr %87, align 8, !tbaa !9
  %89 = icmp sle i32 %86, %88
  br i1 %89, label %93, label %90

90:                                               ; preds = %85
  %91 = load ptr, ptr @stderr, align 8, !tbaa !17
  %92 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %91, ptr noundef @.str.28, ptr noundef @.str.1, i32 noundef 238, ptr noundef @.str.30, ptr noundef @.str.31) #4
  call void @exit(i32 noundef 1) #5
  unreachable

93:                                               ; preds = %85
  %94 = getelementptr inbounds %struct.String, ptr %3, i32 0, i32 0
  %95 = getelementptr inbounds %struct.String, ptr %4, i32 0, i32 0
  %96 = load ptr, ptr %95, align 8, !tbaa !12
  %97 = load i32, ptr %5, align 4, !tbaa !5
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds i8, ptr %96, i64 %98
  store ptr %99, ptr %94, align 8, !tbaa !12
  %100 = getelementptr inbounds %struct.String, ptr %3, i32 0, i32 1
  %101 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %101, ptr %100, align 8, !tbaa !9
  %102 = getelementptr inbounds %struct.String, ptr %3, i32 0, i32 2
  %103 = getelementptr inbounds %struct.String, ptr %4, i32 0, i32 2
  %104 = load i32, ptr %103, align 4, !tbaa !18
  %105 = load i32, ptr %5, align 4, !tbaa !5
  %106 = sub nsw i32 %104, %105
  store i32 %106, ptr %102, align 4, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  %107 = load { ptr, i64 }, ptr %3, align 8
  ret { ptr, i64 } %107
}

attributes #0 = { 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 #1 = { noreturn 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 }
attributes #5 = { noreturn 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, !6, i64 8}
!10 = !{!"String", !11, i64 0, !6, i64 8, !6, i64 12}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = !{!11, !11, i64 0}
!18 = !{!10, !6, i64 12}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [15 x i8], align 1

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local { ptr, i64 } @trim(ptr %0, i64 %1) local_unnamed_addr #2 {
  %.sroa.6.8.extract.trunc = trunc i64 %1 to i32
  %3 = icmp sgt i32 %.sroa.6.8.extract.trunc, 0
  br i1 %3, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = and i64 %1, 2147483647
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.critedge2
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.critedge2 ]
  %4 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %5 = load i8, ptr %4, align 1, !tbaa !5
  switch i8 %5, label %.critedge.loopexit [
    i8 32, label %.critedge2
    i8 9, label %.critedge2
  ]

.critedge2:                                       ; preds = %.lr.ph, %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.critedge.thread, label %.lr.ph, !llvm.loop !8

.critedge.thread:                                 ; preds = %.critedge2
  %.0293749 = add nsw i32 %.sroa.6.8.extract.trunc, -1
  br label %.critedge4

.critedge.loopexit:                               ; preds = %.lr.ph
  %6 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %2
  %.0.lcssa = phi i32 [ 0, %2 ], [ %6, %.critedge.loopexit ]
  %.02937 = add nsw i32 %.sroa.6.8.extract.trunc, -1
  %.not.not38 = icmp slt i32 %.0.lcssa, %.sroa.6.8.extract.trunc
  br i1 %.not.not38, label %.lr.ph40.preheader, label %.critedge4

.lr.ph40.preheader:                               ; preds = %.critedge
  %sext = shl i64 %1, 32
  %7 = ashr exact i64 %sext, 32
  %8 = sext i32 %.0.lcssa to i64
  %9 = add i32 %.0.lcssa, -1
  br label %.lr.ph40

.lr.ph40:                                         ; preds = %.lr.ph40.preheader, %.critedge6
  %indvars.iv45.in = phi i64 [ %7, %.lr.ph40.preheader ], [ %indvars.iv45, %.critedge6 ]
  %indvars.iv45 = add nsw i64 %indvars.iv45.in, -1
  %10 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv45
  %11 = load i8, ptr %10, align 1, !tbaa !5
  switch i8 %11, label %.critedge4.loopexit.split.loop.exit [
    i8 32, label %.critedge6
    i8 9, label %.critedge6
  ]

.critedge6:                                       ; preds = %.lr.ph40, %.lr.ph40
  %.not.not = icmp sgt i64 %indvars.iv45, %8
  br i1 %.not.not, label %.lr.ph40, label %.critedge4, !llvm.loop !10

.critedge4.loopexit.split.loop.exit:              ; preds = %.lr.ph40
  %12 = trunc nsw i64 %indvars.iv45 to i32
  br label %.critedge4

.critedge4:                                       ; preds = %.critedge6, %.critedge4.loopexit.split.loop.exit, %.critedge.thread, %.critedge
  %.0.lcssa51 = phi i32 [ %.0.lcssa, %.critedge ], [ %.sroa.6.8.extract.trunc, %.critedge.thread ], [ %.0.lcssa, %.critedge4.loopexit.split.loop.exit ], [ %.0.lcssa, %.critedge6 ]
  %.029.lcssa = phi i32 [ %.02937, %.critedge ], [ %.0293749, %.critedge.thread ], [ %12, %.critedge4.loopexit.split.loop.exit ], [ %9, %.critedge6 ]
  %13 = sub nsw i32 %.029.lcssa, %.0.lcssa51
  %14 = icmp sgt i32 %13, -2
  br i1 %14, label %18, label %15

15:                                               ; preds = %.critedge4
  %16 = load ptr, ptr @stderr, align 8, !tbaa !11
  %17 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str.28, ptr noundef nonnull @.str.1, i32 noundef 237, ptr noundef nonnull @.str.29, ptr noundef nonnull @.str.4) #3
  tail call void @exit(i32 noundef 1) #4
  unreachable

18:                                               ; preds = %.critedge4
  %.not.not33 = icmp slt i32 %13, %.sroa.6.8.extract.trunc
  br i1 %.not.not33, label %22, label %19

19:                                               ; preds = %18
  %20 = load ptr, ptr @stderr, align 8, !tbaa !11
  %21 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef nonnull @.str.28, ptr noundef nonnull @.str.1, i32 noundef 238, ptr noundef nonnull @.str.30, ptr noundef nonnull @.str.31) #3
  tail call void @exit(i32 noundef 1) #4
  unreachable

22:                                               ; preds = %18
  %23 = add nsw i32 %13, 1
  %.sroa.10.8.extract.shift = lshr i64 %1, 32
  %.sroa.10.8.extract.trunc = trunc nuw i64 %.sroa.10.8.extract.shift to i32
  %24 = zext nneg i32 %.0.lcssa51 to i64
  %25 = getelementptr inbounds i8, ptr %0, i64 %24
  %26 = sub nsw i32 %.sroa.10.8.extract.trunc, %.0.lcssa51
  %.fca.0.insert = insertvalue { ptr, i64 } poison, ptr %25, 0
  %.sroa.4.8.insert.ext = zext i32 %26 to i64
  %.sroa.4.8.insert.shift = shl nuw i64 %.sroa.4.8.insert.ext, 32
  %.sroa.2.8.insert.ext = zext nneg i32 %23 to i64
  %.sroa.2.8.insert.insert = or disjoint i64 %.sroa.4.8.insert.shift, %.sroa.2.8.insert.ext
  %.fca.1.insert = insertvalue { ptr, i64 } %.fca.0.insert, i64 %.sroa.2.8.insert.insert, 1
  ret { ptr, i64 } %.fca.1.insert
}

attributes #0 = { 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 #1 = { noreturn 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 #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 = { cold nounwind }
attributes #4 = { noreturn 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !6, i64 0}


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