; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd/1087.ll (Z6inserti)

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

@tot = external dso_local global i32, align 4
@trie = external dso_local global [50 x %struct.AC], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6inserti(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca [10 x i32], align 16
  %7 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  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 40, ptr %6) #4
  call void @llvm.memset.p0.i64(ptr align 16 %6, i8 0, i64 40, i1 false)
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  br label %9

9:                                                ; preds = %12, %1
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %21

12:                                               ; preds = %9
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = srem i32 %13, 10
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %5, align 4, !tbaa !5
  %17 = sext i32 %15 to i64
  %18 = getelementptr inbounds [10 x i32], ptr %6, i64 0, i64 %17
  store i32 %14, ptr %18, align 4, !tbaa !5
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sdiv i32 %19, 10
  store i32 %20, ptr %3, align 4, !tbaa !5
  br label %9, !llvm.loop !9

21:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = sub nsw i32 %22, 1
  store i32 %23, ptr %7, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %66, %21
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = icmp sge i32 %25, 0
  br i1 %26, label %28, label %27

27:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %69

28:                                               ; preds = %24
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [50 x %struct.AC], ptr @trie, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.AC, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [10 x i32], ptr %6, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [10 x i32], ptr %32, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %54, label %41

41:                                               ; preds = %28
  %42 = load i32, ptr @tot, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr @tot, align 4, !tbaa !5
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [50 x %struct.AC], ptr @trie, i64 0, i64 %45
  %47 = getelementptr inbounds %struct.AC, ptr %46, i32 0, i32 0
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [10 x i32], ptr %6, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [10 x i32], ptr %47, i64 0, i64 %52
  store i32 %43, ptr %53, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %41, %28
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [50 x %struct.AC], ptr @trie, i64 0, i64 %56
  %58 = getelementptr inbounds %struct.AC, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [10 x i32], ptr %6, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [10 x i32], ptr %58, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  store i32 %65, ptr %4, align 4, !tbaa !5
  br label %66

66:                                               ; preds = %54
  %67 = load i32, ptr %7, align 4, !tbaa !5
  %68 = add nsw i32 %67, -1
  store i32 %68, ptr %7, align 4, !tbaa !5
  br label %24, !llvm.loop !11

69:                                               ; preds = %27
  %70 = load i32, ptr %2, align 4, !tbaa !5
  %71 = load i32, ptr %4, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [50 x %struct.AC], ptr @trie, i64 0, i64 %72
  %74 = getelementptr inbounds %struct.AC, ptr %73, i32 0, i32 3
  store i32 %70, ptr %74, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 40, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret void
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare i32 @__isoc99_scanf(ptr noundef, ...) #3

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

attributes #0 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = !{!13, !6, i64 48}
!13 = !{!"_ZTS2AC", !7, i64 0, !6, i64 40, !6, i64 44, !6, i64 48}


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

@tot = external dso_local local_unnamed_addr global i32, align 4
@trie = external dso_local local_unnamed_addr global [50 x %struct.AC], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_Z6inserti(i32 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i32, align 4
  %3 = alloca [10 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %3) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) %3, i8 0, i64 40, i1 false)
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %.pr = load i32, ptr %2, align 4, !tbaa !5
  %.not16 = icmp eq i32 %.pr, 0
  br i1 %.not16, label %._crit_edge, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph
  %5 = trunc nuw i64 %indvars.iv.next to i32
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph21.preheader, label %._crit_edge

.lr.ph21.preheader:                               ; preds = %.preheader
  %tot.promoted = load i32, ptr @tot, align 4, !tbaa !5
  %7 = and i64 %indvars.iv.next, 2147483647
  br label %.lr.ph21

.lr.ph:                                           ; preds = %1, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %1 ]
  %8 = phi i32 [ %11, %.lr.ph ], [ %.pr, %1 ]
  %9 = srem i32 %8, 10
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = getelementptr inbounds [10 x i32], ptr %3, i64 0, i64 %indvars.iv
  store i32 %9, ptr %10, align 4, !tbaa !5
  %11 = sdiv i32 %8, 10
  %.off = add i32 %8, 9
  %.not = icmp ult i32 %.off, 19
  br i1 %.not, label %.preheader, label %.lr.ph, !llvm.loop !9

._crit_edge.loopexit:                             ; preds = %24
  %12 = sext i32 %25 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %1, %._crit_edge.loopexit, %.preheader
  %.013.lcssa = phi i64 [ 0, %.preheader ], [ %12, %._crit_edge.loopexit ], [ 0, %1 ]
  %13 = getelementptr inbounds [50 x %struct.AC], ptr @trie, i64 0, i64 %.013.lcssa, i32 3
  store i32 %0, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  ret void

.lr.ph21:                                         ; preds = %.lr.ph21.preheader, %24
  %indvars.iv26 = phi i64 [ %7, %.lr.ph21.preheader ], [ %indvars.iv.next27, %24 ]
  %.01319 = phi i32 [ 0, %.lr.ph21.preheader ], [ %25, %24 ]
  %14 = phi i32 [ %tot.promoted, %.lr.ph21.preheader ], [ %26, %24 ]
  %indvars.iv.next27 = add nsw i64 %indvars.iv26, -1
  %15 = sext i32 %.01319 to i64
  %16 = getelementptr inbounds [50 x %struct.AC], ptr @trie, i64 0, i64 %15
  %17 = getelementptr inbounds [10 x i32], ptr %3, i64 0, i64 %indvars.iv.next27
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [10 x i32], ptr %16, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %.not15 = icmp eq i32 %21, 0
  br i1 %.not15, label %22, label %24

22:                                               ; preds = %.lr.ph21
  %23 = add nsw i32 %14, 1
  store i32 %23, ptr @tot, align 4, !tbaa !5
  store i32 %23, ptr %20, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %22, %.lr.ph21
  %25 = phi i32 [ %23, %22 ], [ %21, %.lr.ph21 ]
  %26 = phi i32 [ %23, %22 ], [ %14, %.lr.ph21 ]
  %27 = icmp ugt i64 %indvars.iv26, 1
  br i1 %27, label %.lr.ph21, label %._crit_edge.loopexit, !llvm.loop !13
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

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

attributes #0 = { mustprogress nofree 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { 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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 48}
!12 = !{!"_ZTS2AC", !7, i64 0, !6, i64 40, !6, i64 44, !6, i64 48}
!13 = distinct !{!13, !10}


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