; LLVM IR from tangjz/acm-icpc :: TDL_training/2015-10-05 (L - Language Recognition - tjz)

; 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], i8 }

@n = external dso_local global i32, align 4
@tot = external dso_local global i32, align 4
@ord = external dso_local global [155031 x i32], align 16
@e = external dso_local global [155031 x %struct.Trie], align 16
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6insertv() #0

; 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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsi(i32 noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z3cmpRKiS0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z5equivRKiS0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #4 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %6

6:                                                ; preds = %59, %0
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n)
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %9, label %62

9:                                                ; preds = %6
  store i32 1, ptr @tot, align 4, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 16 @e, i8 0, i64 108, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %16, %9
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  br label %19

15:                                               ; preds = %10
  call void @_Z6insertv()
  br label %16

16:                                               ; preds = %15
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %2, align 4, !tbaa !5
  br label %10, !llvm.loop !9

19:                                               ; preds = %14
  call void @_Z3dfsi(i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %30, %19
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = load i32, ptr @tot, align 4, !tbaa !5
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  br label %33

25:                                               ; preds = %20
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [155031 x i32], ptr @ord, i64 0, i64 %28
  store i32 %26, ptr %29, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %25
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %3, align 4, !tbaa !5
  br label %20, !llvm.loop !11

33:                                               ; preds = %24
  %34 = load i32, ptr @tot, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds i32, ptr @ord, i64 %35
  call void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef @ord, ptr noundef %36, ptr noundef @_Z3cmpRKiS0_)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  %37 = load i32, ptr @tot, align 4, !tbaa !5
  store i32 %37, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %56, %33
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = load i32, ptr @tot, align 4, !tbaa !5
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %59

43:                                               ; preds = %38
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = sub nsw i32 %44, 1
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [155031 x i32], ptr @ord, i64 0, i64 %46
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [155031 x i32], ptr @ord, i64 0, i64 %49
  %51 = call noundef zeroext i1 @_Z5equivRKiS0_(ptr noundef nonnull align 4 dereferenceable(4) %47, ptr noundef nonnull align 4 dereferenceable(4) %50)
  br i1 %51, label %52, label %55

52:                                               ; preds = %43
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = add nsw i32 %53, -1
  store i32 %54, ptr %4, align 4, !tbaa !5
  br label %55

55:                                               ; preds = %52, %43
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %5, align 4, !tbaa !5
  br label %38, !llvm.loop !12

59:                                               ; preds = %42
  %60 = load i32, ptr %4, align 4, !tbaa !5
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %60)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  br label %6, !llvm.loop !13

62:                                               ; preds = %6
  ret i32 0
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef, ptr noundef, ptr noundef) #5

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

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 = { mustprogress norecurse 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 #5 = { inlinehint 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 #6 = { 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 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


; 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], i8 }

@n = external dso_local global i32, align 4
@tot = external dso_local local_unnamed_addr global i32, align 4
@ord = external dso_local global [155031 x i32], align 16
@e = external dso_local local_unnamed_addr global [155031 x %struct.Trie], align 16
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6insertv() local_unnamed_addr #0

; 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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z3cmpRKiS0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z5equivRKiS0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n)
  %2 = icmp eq i32 %1, 1
  br i1 %2, label %.lr.ph28, label %._crit_edge29

.lr.ph28:                                         ; preds = %0, %._crit_edge25
  store i32 1, ptr @tot, align 4, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(108) @e, i8 0, i64 108, i1 false)
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph28
  tail call void @_Z3dfsi(i32 noundef 0)
  %5 = load i32, ptr @tot, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph19.preheader, label %._crit_edge20

.lr.ph19.preheader:                               ; preds = %._crit_edge
  %wide.trip.count = zext nneg i32 %5 to i64
  %min.iters.check = icmp ult i32 %5, 8
  br i1 %min.iters.check, label %.lr.ph19.preheader35, label %vector.ph

.lr.ph19.preheader35:                             ; preds = %middle.block, %.lr.ph19.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph19.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph19

vector.ph:                                        ; preds = %.lr.ph19.preheader
  %n.vec = and i64 %wide.trip.count, 2147483640
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %step.add = add <4 x i32> %vec.ind, <i32 4, i32 4, i32 4, i32 4>
  %7 = getelementptr inbounds [155031 x i32], ptr @ord, i64 0, i64 %index
  %8 = getelementptr inbounds i8, ptr %7, i64 16
  store <4 x i32> %vec.ind, ptr %7, align 16, !tbaa !5
  store <4 x i32> %step.add, ptr %8, align 16, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %vec.ind.next = add <4 x i32> %vec.ind, <i32 8, i32 8, i32 8, i32 8>
  %9 = icmp eq i64 %index.next, %n.vec
  br i1 %9, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge20, label %.lr.ph19.preheader35

.lr.ph:                                           ; preds = %.lr.ph28, %.lr.ph
  %.01416 = phi i32 [ %10, %.lr.ph ], [ 0, %.lr.ph28 ]
  tail call void @_Z6insertv()
  %10 = add nuw nsw i32 %.01416, 1
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge20:                                    ; preds = %.lr.ph19, %middle.block, %._crit_edge
  %13 = sext i32 %5 to i64
  %14 = getelementptr inbounds i32, ptr @ord, i64 %13
  tail call void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef nonnull @ord, ptr noundef nonnull %14, ptr noundef nonnull @_Z3cmpRKiS0_)
  %15 = load i32, ptr @tot, align 4, !tbaa !5
  %16 = icmp sgt i32 %15, 1
  br i1 %16, label %.lr.ph24, label %._crit_edge25

.lr.ph19:                                         ; preds = %.lr.ph19.preheader35, %.lr.ph19
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph19 ], [ %indvars.iv.ph, %.lr.ph19.preheader35 ]
  %17 = getelementptr inbounds [155031 x i32], ptr @ord, i64 0, i64 %indvars.iv
  %18 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %18, ptr %17, align 4, !tbaa !5
  %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_edge20, label %.lr.ph19, !llvm.loop !14

._crit_edge25:                                    ; preds = %.lr.ph24, %._crit_edge20
  %.012.lcssa = phi i32 [ %15, %._crit_edge20 ], [ %spec.select, %.lr.ph24 ]
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.012.lcssa)
  %20 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n)
  %21 = icmp eq i32 %20, 1
  br i1 %21, label %.lr.ph28, label %._crit_edge29, !llvm.loop !15

.lr.ph24:                                         ; preds = %._crit_edge20, %.lr.ph24
  %indvars.iv31 = phi i64 [ %indvars.iv.next32, %.lr.ph24 ], [ 1, %._crit_edge20 ]
  %.01221 = phi i32 [ %spec.select, %.lr.ph24 ], [ %15, %._crit_edge20 ]
  %22 = add nsw i64 %indvars.iv31, -1
  %23 = getelementptr inbounds [155031 x i32], ptr @ord, i64 0, i64 %22
  %24 = getelementptr inbounds [155031 x i32], ptr @ord, i64 0, i64 %indvars.iv31
  %25 = tail call noundef zeroext i1 @_Z5equivRKiS0_(ptr noundef nonnull align 4 dereferenceable(4) %23, ptr noundef nonnull align 4 dereferenceable(4) %24)
  %26 = sext i1 %25 to i32
  %spec.select = add nsw i32 %.01221, %26
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %27 = load i32, ptr @tot, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = icmp slt i64 %indvars.iv.next32, %28
  br i1 %29, label %.lr.ph24, label %._crit_edge25, !llvm.loop !16

._crit_edge29:                                    ; preds = %._crit_edge25, %0
  ret i32 0
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { 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) }
attributes #3 = { mustprogress norecurse 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 = { inlinehint 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" }

!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, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10, !12, !11}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass