; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ/1671.ll (Z6InsertPc)

; 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.node = type { i8, [10 x i32] }

@x = external dso_local global i8, align 1
@ptr = external dso_local global i32, align 4
@list = external dso_local global [100000 x %struct.node], 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: mustprogress nounwind uwtable
define dso_local void @_Z6InsertPc(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  store i8 0, ptr %3, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  store i8 0, ptr %4, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = call i64 @strlen(ptr noundef %8) #4
  %10 = trunc i64 %9 to i32
  store i32 %10, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %11

11:                                               ; preds = %73, %1
  %12 = load i32, ptr %7, align 4, !tbaa !11
  %13 = load i32, ptr %6, align 4, !tbaa !11
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %76

16:                                               ; preds = %11
  %17 = load i32, ptr %5, align 4, !tbaa !11
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [100000 x %struct.node], ptr @list, i64 0, i64 %18
  %20 = getelementptr inbounds %struct.node, ptr %19, i32 0, i32 1
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = load i32, ptr %7, align 4, !tbaa !11
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %21, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !13
  %26 = sext i8 %25 to i32
  %27 = sub nsw i32 %26, 48
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [10 x i32], ptr %20, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %31 = icmp eq i32 %30, -1
  br i1 %31, label %32, label %49

32:                                               ; preds = %16
  store i8 1, ptr %3, align 1, !tbaa !9
  %33 = load i32, ptr @ptr, align 4, !tbaa !11
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr @ptr, align 4, !tbaa !11
  %35 = load i32, ptr %5, align 4, !tbaa !11
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [100000 x %struct.node], ptr @list, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.node, ptr %37, i32 0, i32 1
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = load i32, ptr %7, align 4, !tbaa !11
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i8, ptr %39, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !13
  %44 = sext i8 %43 to i32
  %45 = sub nsw i32 %44, 48
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [10 x i32], ptr %38, i64 0, i64 %46
  store i32 %34, ptr %47, align 4, !tbaa !11
  %48 = load i32, ptr @ptr, align 4, !tbaa !11
  store i32 %48, ptr %5, align 4, !tbaa !11
  br label %72

49:                                               ; preds = %16
  %50 = load i32, ptr %5, align 4, !tbaa !11
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [100000 x %struct.node], ptr @list, i64 0, i64 %51
  %53 = getelementptr inbounds %struct.node, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = load i32, ptr %7, align 4, !tbaa !11
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i8, ptr %54, i64 %56
  %58 = load i8, ptr %57, align 1, !tbaa !13
  %59 = sext i8 %58 to i32
  %60 = sub nsw i32 %59, 48
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [10 x i32], ptr %53, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !11
  store i32 %63, ptr %5, align 4, !tbaa !11
  %64 = load i32, ptr %5, align 4, !tbaa !11
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [100000 x %struct.node], ptr @list, i64 0, i64 %65
  %67 = getelementptr inbounds %struct.node, ptr %66, i32 0, i32 0
  %68 = load i8, ptr %67, align 4, !tbaa !14, !range !16, !noundef !17
  %69 = trunc i8 %68 to i1
  br i1 %69, label %70, label %71

70:                                               ; preds = %49
  store i8 1, ptr %4, align 1, !tbaa !9
  br label %71

71:                                               ; preds = %70, %49
  br label %72

72:                                               ; preds = %71, %32
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %7, align 4, !tbaa !11
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %7, align 4, !tbaa !11
  br label %11, !llvm.loop !18

76:                                               ; preds = %15
  %77 = load i32, ptr %5, align 4, !tbaa !11
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [100000 x %struct.node], ptr @list, i64 0, i64 %78
  %80 = getelementptr inbounds %struct.node, ptr %79, i32 0, i32 0
  store i8 1, ptr %80, align 4, !tbaa !14
  %81 = load i8, ptr %4, align 1, !tbaa !9, !range !16, !noundef !17
  %82 = trunc i8 %81 to i1
  br i1 %82, label %86, label %83

83:                                               ; preds = %76
  %84 = load i8, ptr %3, align 1, !tbaa !9, !range !16, !noundef !17
  %85 = trunc i8 %84 to i1
  br label %86

86:                                               ; preds = %83, %76
  %87 = phi i1 [ false, %76 ], [ %85, %83 ]
  %88 = zext i1 %87 to i8
  store i8 %88, ptr @x, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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 #3 = { nounwind }
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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !10, i64 0}
!15 = !{!"_ZTS4node", !10, i64 0, !7, i64 4}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !19}
!19 = !{!"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"

%struct.node = type { i8, [10 x i32] }

@x = external dso_local local_unnamed_addr global i8, align 1
@ptr = external dso_local local_unnamed_addr global i32, align 4
@list = external dso_local local_unnamed_addr global [100000 x %struct.node], align 16

; Function Attrs: mustprogress nofree nounwind memory(readwrite, argmem: read, inaccessiblemem: none) uwtable
define dso_local void @_Z6InsertPc(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #2
  %3 = trunc i64 %2 to i32
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %1
  %ptr.promoted = load i32, ptr @ptr, align 4, !tbaa !5
  %wide.trip.count = and i64 %2, 2147483647
  br label %.lr.ph

._crit_edge.loopexit:                             ; preds = %29
  %5 = sext i32 %.118 to i64
  %6 = and i8 %.1, 1
  %7 = select i1 %.120, i8 0, i8 %6
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %.019.lcssa = phi i8 [ 0, %1 ], [ %7, %._crit_edge.loopexit ]
  %.017.lcssa = phi i64 [ 0, %1 ], [ %5, %._crit_edge.loopexit ]
  %8 = getelementptr inbounds [100000 x %struct.node], ptr @list, i64 0, i64 %.017.lcssa
  store i8 1, ptr %8, align 4, !tbaa !9
  store i8 %.019.lcssa, ptr @x, align 1, !tbaa !12
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %29
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %29 ]
  %.01624 = phi i8 [ 0, %.lr.ph.preheader ], [ %.1, %29 ]
  %.01723 = phi i32 [ 0, %.lr.ph.preheader ], [ %.118, %29 ]
  %.01922 = phi i1 [ false, %.lr.ph.preheader ], [ %.120, %29 ]
  %9 = phi i32 [ %ptr.promoted, %.lr.ph.preheader ], [ %30, %29 ]
  %10 = sext i32 %.01723 to i64
  %11 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %12 = load i8, ptr %11, align 1, !tbaa !13
  %13 = sext i8 %12 to i64
  %14 = add nsw i64 %13, -48
  %15 = getelementptr inbounds [100000 x %struct.node], ptr @list, i64 0, i64 %10, i32 1, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = icmp eq i32 %16, -1
  br i1 %17, label %18, label %24

18:                                               ; preds = %.lr.ph
  %19 = add nsw i32 %9, 1
  store i32 %19, ptr @ptr, align 4, !tbaa !5
  %20 = load i8, ptr %11, align 1, !tbaa !13
  %21 = sext i8 %20 to i64
  %22 = add nsw i64 %21, -48
  %23 = getelementptr inbounds [100000 x %struct.node], ptr @list, i64 0, i64 %10, i32 1, i64 %22
  store i32 %19, ptr %23, align 4, !tbaa !5
  br label %29

24:                                               ; preds = %.lr.ph
  %25 = sext i32 %16 to i64
  %26 = getelementptr inbounds [100000 x %struct.node], ptr @list, i64 0, i64 %25
  %27 = load i8, ptr %26, align 4, !tbaa !9, !range !14, !noundef !15
  %28 = trunc nuw i8 %27 to i1
  %spec.select = select i1 %28, i1 true, i1 %.01922
  br label %29

29:                                               ; preds = %24, %18
  %30 = phi i32 [ %19, %18 ], [ %9, %24 ]
  %.120 = phi i1 [ %.01922, %18 ], [ %spec.select, %24 ]
  %.118 = phi i32 [ %19, %18 ], [ %16, %24 ]
  %.1 = phi i8 [ 1, %18 ], [ %.01624, %24 ]
  %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 %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !16
}

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

attributes #0 = { mustprogress nofree nounwind memory(readwrite, argmem: read, 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" }
attributes #1 = { 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 #2 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS4node", !11, i64 0, !7, i64 4}
!11 = !{!"bool", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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