; LLVM IR from tangjz/acm-icpc :: lydsy/2081.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.Hash = type { i32, i32 }

@tot = external dso_local global i32, align 4
@tt = external dso_local global i32, align 4
@tm = external dso_local global [1048576 x i32], align 16
@lnk = external dso_local global [1048576 x i32], align 16
@e = external dso_local global [200010 x %struct.Hash], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z6inserti(i32 noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.Hash, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = and i32 %8, 1048575
  store i32 %9, ptr %4, align 4, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [1048576 x i32], ptr @tm, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = load i32, ptr @tt, align 4, !tbaa !5
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %16, label %24

16:                                               ; preds = %1
  %17 = load i32, ptr @tt, align 4, !tbaa !5
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [1048576 x i32], ptr @tm, i64 0, i64 %19
  store i32 %17, ptr %20, align 4, !tbaa !5
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1048576 x i32], ptr @lnk, i64 0, i64 %22
  store i32 0, ptr %23, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %16, %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [1048576 x i32], ptr @lnk, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  store i32 %28, ptr %5, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %43, %24
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %33, label %32

32:                                               ; preds = %29
  store i32 2, ptr %6, align 4
  br label %49

33:                                               ; preds = %29
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [200010 x %struct.Hash], ptr @e, i64 0, i64 %35
  %37 = getelementptr inbounds %struct.Hash, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = icmp eq i32 %38, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %33
  store i1 false, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %49

42:                                               ; preds = %33
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [200010 x %struct.Hash], ptr @e, i64 0, i64 %45
  %47 = getelementptr inbounds %struct.Hash, ptr %46, i32 0, i32 0
  %48 = load i32, ptr %47, align 8, !tbaa !11
  store i32 %48, ptr %5, align 4, !tbaa !5
  br label %29, !llvm.loop !12

49:                                               ; preds = %41, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %50 = load i32, ptr %6, align 4
  switch i32 %50, label %67 [
    i32 2, label %51
  ]

51:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %52 = getelementptr inbounds %struct.Hash, ptr %7, i32 0, i32 0
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [1048576 x i32], ptr @lnk, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  store i32 %56, ptr %52, align 4, !tbaa !11
  %57 = getelementptr inbounds %struct.Hash, ptr %7, i32 0, i32 1
  %58 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %58, ptr %57, align 4, !tbaa !9
  %59 = load i32, ptr @tot, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr @tot, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [200010 x %struct.Hash], ptr @e, i64 0, i64 %61
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %62, ptr align 4 %7, i64 8, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %63 = load i32, ptr @tot, align 4, !tbaa !5
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [1048576 x i32], ptr @lnk, i64 0, i64 %65
  store i32 %63, ptr %66, align 4, !tbaa !5
  store i1 true, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %67

67:                                               ; preds = %51, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %68 = load i1, ptr %2, align 1
  ret i1 %68
}

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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


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

@tot = external dso_local local_unnamed_addr global i32, align 4
@tt = external dso_local local_unnamed_addr global i32, align 4
@tm = external dso_local local_unnamed_addr global [1048576 x i32], align 16
@lnk = external dso_local local_unnamed_addr global [1048576 x i32], align 16
@e = external dso_local local_unnamed_addr global [200010 x %struct.Hash], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: read, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z6inserti(i32 noundef %0) local_unnamed_addr #0 {
  %2 = and i32 %0, 1048575
  %3 = zext nneg i32 %2 to i64
  %4 = getelementptr inbounds [1048576 x i32], ptr @tm, i64 0, i64 %3
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = load i32, ptr @tt, align 4, !tbaa !5
  %7 = icmp slt i32 %5, %6
  br i1 %7, label %8, label %10

8:                                                ; preds = %1
  store i32 %6, ptr %4, align 4, !tbaa !5
  %9 = getelementptr inbounds [1048576 x i32], ptr @lnk, i64 0, i64 %3
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %8, %1
  %11 = getelementptr inbounds [1048576 x i32], ptr @lnk, i64 0, i64 %3
  br label %12

12:                                               ; preds = %13, %10
  %.013.in = phi ptr [ %11, %10 ], [ %15, %13 ]
  %.013 = load i32, ptr %.013.in, align 4, !tbaa !5
  %.not = icmp eq i32 %.013, 0
  br i1 %.not, label %.critedge, label %13

13:                                               ; preds = %12
  %14 = sext i32 %.013 to i64
  %15 = getelementptr inbounds [200010 x %struct.Hash], ptr @e, i64 0, i64 %14
  %16 = getelementptr inbounds i8, ptr %15, i64 4
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = icmp eq i32 %17, %0
  br i1 %18, label %.loopexit, label %12, !llvm.loop !11

.critedge:                                        ; preds = %12
  %19 = load i32, ptr %11, align 4, !tbaa !5
  %20 = load i32, ptr @tot, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr @tot, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [200010 x %struct.Hash], ptr @e, i64 0, i64 %22
  store i32 %19, ptr %23, align 8, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %23, i64 4
  store i32 %0, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !5
  store i32 %21, ptr %11, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %13, %.critedge
  ret i1 %.not
}

attributes #0 = { mustprogress nofree norecurse nosync 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" }

!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, !6, i64 4}
!10 = !{!"_ZTS4Hash", !6, i64 0, !6, i64 4}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass