; LLVM IR from tangjz/acm-icpc :: hdu/5790.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.Trie = type { [26 x i32] }

@tot = external dso_local global i32, align 4
@lim = external dso_local global [100001 x i32], align 16
@seq = external dso_local global [100001 x i32], align 16
@tim = external dso_local global i32, align 4
@pos = external dso_local global [100001 x i32], align 16
@mx = external dso_local global i32, align 4
@e = external dso_local global [100001 x %struct.Trie], align 16
@_ZZ6insertiE3str = external hidden global [100001 x i8], 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
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @_ZZ6insertiE3str)
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %90, %1
  %7 = load i32, ptr %4, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [100001 x i8], ptr @_ZZ6insertiE3str, i64 0, i64 %8
  %10 = load i8, ptr %9, align 1, !tbaa !9
  %11 = icmp ne i8 %10, 0
  br i1 %11, label %12, label %93

12:                                               ; preds = %6
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [100001 x i8], ptr @_ZZ6insertiE3str, i64 0, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = sext i8 %16 to i32
  %18 = sub nsw i32 %17, 97
  %19 = trunc i32 %18 to i8
  store i8 %19, ptr %15, align 1, !tbaa !9
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [100001 x %struct.Trie], ptr @e, i64 0, i64 %21
  %23 = getelementptr inbounds %struct.Trie, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [100001 x i8], ptr @_ZZ6insertiE3str, i64 0, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !9
  %28 = sext i8 %27 to i32
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [26 x i32], ptr %23, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %53, label %33

33:                                               ; preds = %12
  %34 = load i32, ptr @tot, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [100001 x i32], ptr @pos, i64 0, i64 %35
  store i32 0, ptr %36, align 4, !tbaa !5
  %37 = load i32, ptr @tot, align 4, !tbaa !5
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [100001 x %struct.Trie], ptr @e, i64 0, i64 %39
  %41 = getelementptr inbounds %struct.Trie, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [100001 x i8], ptr @_ZZ6insertiE3str, i64 0, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !9
  %46 = sext i8 %45 to i32
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [26 x i32], ptr %41, i64 0, i64 %47
  store i32 %37, ptr %48, align 4, !tbaa !5
  %49 = load i32, ptr @tot, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr @tot, align 4, !tbaa !5
  %51 = sext i32 %49 to i64
  %52 = getelementptr inbounds %struct.Trie, ptr @e, i64 %51
  call void @llvm.memset.p0.i64(ptr align 4 %52, i8 0, i64 104, i1 false)
  br label %53

53:                                               ; preds = %33, %12
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [100001 x %struct.Trie], ptr @e, i64 0, i64 %55
  %57 = getelementptr inbounds %struct.Trie, ptr %56, i32 0, i32 0
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [100001 x i8], ptr @_ZZ6insertiE3str, i64 0, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !9
  %62 = sext i8 %61 to i32
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [26 x i32], ptr %57, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  store i32 %65, ptr %3, align 4, !tbaa !5
  %66 = load i32, ptr %3, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [100001 x i32], ptr @pos, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = load i32, ptr @tim, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr @tim, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [100001 x i32], ptr @seq, i64 0, i64 %72
  store i32 %69, ptr %73, align 4, !tbaa !5
  %74 = load i32, ptr @mx, align 4, !tbaa !5
  %75 = load i32, ptr %3, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [100001 x i32], ptr @pos, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !5
  %79 = icmp slt i32 %74, %78
  br i1 %79, label %80, label %85

80:                                               ; preds = %53
  %81 = load i32, ptr %3, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [100001 x i32], ptr @pos, i64 0, i64 %82
  %84 = load i32, ptr %83, align 4, !tbaa !5
  store i32 %84, ptr @mx, align 4, !tbaa !5
  br label %85

85:                                               ; preds = %80, %53
  %86 = load i32, ptr @tim, align 4, !tbaa !5
  %87 = load i32, ptr %3, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [100001 x i32], ptr @pos, i64 0, i64 %88
  store i32 %86, ptr %89, align 4, !tbaa !5
  br label %90

90:                                               ; preds = %85
  %91 = load i32, ptr %4, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %4, align 4, !tbaa !5
  br label %6, !llvm.loop !10

93:                                               ; preds = %6
  %94 = load i32, ptr %2, align 4, !tbaa !5
  %95 = sub nsw i32 %94, 1
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [100001 x i32], ptr @lim, i64 0, i64 %96
  %98 = load i32, ptr %97, align 4, !tbaa !5
  %99 = load i32, ptr %4, align 4, !tbaa !5
  %100 = add nsw i32 %98, %99
  %101 = load i32, ptr %2, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [100001 x i32], ptr @lim, i64 0, i64 %102
  store i32 %100, ptr %103, align 4, !tbaa !5
  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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { "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 nounwind willreturn memory(argmem: write) }
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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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.Trie = type { [26 x i32] }

@tot = external dso_local local_unnamed_addr global i32, align 4
@lim = external dso_local local_unnamed_addr global [100001 x i32], align 16
@seq = external dso_local local_unnamed_addr global [100001 x i32], align 16
@tim = external dso_local local_unnamed_addr global i32, align 4
@pos = external dso_local local_unnamed_addr global [100001 x i32], align 16
@mx = external dso_local local_unnamed_addr global i32, align 4
@e = external dso_local local_unnamed_addr global [100001 x %struct.Trie], align 16
@_ZZ6insertiE3str = external hidden global [100001 x i8], 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 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @_ZZ6insertiE3str)
  %3 = load i8, ptr @_ZZ6insertiE3str, align 16, !tbaa !5
  %.not20 = icmp eq i8 %3, 0
  br i1 %.not20, label %35, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %mx.promoted = load i32, ptr @mx, align 4, !tbaa !8
  %tim.promoted = load i32, ptr @tim, align 4, !tbaa !8
  %tot.promoted = load i32, ptr @tot, align 4, !tbaa !8
  %4 = sext i32 %tim.promoted to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %29
  %indvars.iv24 = phi i64 [ %4, %.lr.ph.preheader ], [ %indvars.iv.next25, %29 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %29 ]
  %5 = phi i8 [ %3, %.lr.ph.preheader ], [ %33, %29 ]
  %6 = phi ptr [ @_ZZ6insertiE3str, %.lr.ph.preheader ], [ %32, %29 ]
  %.01621 = phi i32 [ 0, %.lr.ph.preheader ], [ %21, %29 ]
  %7 = phi i32 [ %tot.promoted, %.lr.ph.preheader ], [ %22, %29 ]
  %8 = phi i32 [ %mx.promoted, %.lr.ph.preheader ], [ %30, %29 ]
  %9 = add i8 %5, -97
  store i8 %9, ptr %6, align 1, !tbaa !5
  %10 = sext i32 %.01621 to i64
  %11 = getelementptr inbounds [100001 x %struct.Trie], ptr @e, i64 0, i64 %10
  %12 = sext i8 %9 to i64
  %13 = getelementptr inbounds [26 x i32], ptr %11, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !8
  %.not19 = icmp eq i32 %14, 0
  br i1 %.not19, label %15, label %20

15:                                               ; preds = %.lr.ph
  %16 = sext i32 %7 to i64
  %17 = getelementptr inbounds [100001 x i32], ptr @pos, i64 0, i64 %16
  store i32 0, ptr %17, align 4, !tbaa !8
  store i32 %7, ptr %13, align 4, !tbaa !8
  %18 = add nsw i32 %7, 1
  store i32 %18, ptr @tot, align 4, !tbaa !8
  %19 = getelementptr inbounds %struct.Trie, ptr @e, i64 %16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(104) %19, i8 0, i64 104, i1 false)
  %.pre = load i32, ptr %13, align 4, !tbaa !8
  br label %20

20:                                               ; preds = %15, %.lr.ph
  %21 = phi i32 [ %.pre, %15 ], [ %14, %.lr.ph ]
  %22 = phi i32 [ %18, %15 ], [ %7, %.lr.ph ]
  %23 = sext i32 %21 to i64
  %24 = getelementptr inbounds [100001 x i32], ptr @pos, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !8
  %indvars.iv.next25 = add nsw i64 %indvars.iv24, 1
  %26 = getelementptr inbounds [100001 x i32], ptr @seq, i64 0, i64 %indvars.iv.next25
  store i32 %25, ptr %26, align 4, !tbaa !8
  %27 = icmp slt i32 %8, %25
  br i1 %27, label %28, label %29

28:                                               ; preds = %20
  store i32 %25, ptr @mx, align 4, !tbaa !8
  br label %29

29:                                               ; preds = %28, %20
  %30 = phi i32 [ %25, %28 ], [ %8, %20 ]
  %31 = trunc nsw i64 %indvars.iv.next25 to i32
  store i32 %31, ptr %24, align 4, !tbaa !8
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %32 = getelementptr inbounds [100001 x i8], ptr @_ZZ6insertiE3str, i64 0, i64 %indvars.iv.next
  %33 = load i8, ptr %32, align 1, !tbaa !5
  %.not = icmp eq i8 %33, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %29
  %34 = trunc nuw nsw i64 %indvars.iv.next to i32
  store i32 %31, ptr @tim, align 4, !tbaa !8
  br label %35

35:                                               ; preds = %._crit_edge, %1
  %.0.lcssa = phi i32 [ %34, %._crit_edge ], [ 0, %1 ]
  %36 = add nsw i32 %0, -1
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100001 x i32], ptr @lim, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !8
  %40 = add nsw i32 %39, %.0.lcssa
  %41 = sext i32 %0 to i64
  %42 = getelementptr inbounds [100001 x i32], ptr @lim, i64 0, i64 %41
  store i32 %40, ptr %42, align 4, !tbaa !8
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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

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

!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++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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