; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd/278.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 }

@t = external dso_local global i32, align 4
@tot = external dso_local global i32, align 4
@pre = external dso_local global [2333333 x i32], align 16
@tm = external dso_local global [2333333 x i32], align 16
@e = external dso_local global [1000001 x %struct.Hash], align 16

; Function Attrs: mustprogress nounwind 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 %struct.Hash, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = srem i32 %7, 2333333
  store i32 %8, ptr %3, align 4, !tbaa !5
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 0
  br i1 %10, label %11, label %14

11:                                               ; preds = %1
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = add nsw i32 %12, 2333333
  store i32 %13, ptr %3, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %11, %1
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [2333333 x i32], ptr @tm, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = load i32, ptr @t, align 4, !tbaa !5
  %20 = icmp ne i32 %18, %19
  br i1 %20, label %21, label %29

21:                                               ; preds = %14
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [2333333 x i32], ptr @pre, i64 0, i64 %23
  store i32 0, ptr %24, align 4, !tbaa !5
  %25 = load i32, ptr @t, align 4, !tbaa !5
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [2333333 x i32], ptr @tm, i64 0, i64 %27
  store i32 %25, ptr %28, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %21, %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [2333333 x i32], ptr @pre, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  store i32 %33, ptr %4, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %48, %29
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %38, label %37

37:                                               ; preds = %34
  store i32 2, ptr %5, align 4
  br label %54

38:                                               ; preds = %34
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [1000001 x %struct.Hash], ptr @e, i64 0, i64 %40
  %42 = getelementptr inbounds %struct.Hash, ptr %41, i32 0, i32 1
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = icmp eq i32 %43, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %38
  store i32 1, ptr %5, align 4
  br label %54

47:                                               ; preds = %38
  br label %48

48:                                               ; preds = %47
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [1000001 x %struct.Hash], ptr @e, i64 0, i64 %50
  %52 = getelementptr inbounds %struct.Hash, ptr %51, i32 0, i32 0
  %53 = load i32, ptr %52, align 8, !tbaa !11
  store i32 %53, ptr %4, align 4, !tbaa !5
  br label %34, !llvm.loop !12

54:                                               ; preds = %46, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %55 = load i32, ptr %5, align 4
  switch i32 %55, label %72 [
    i32 2, label %56
  ]

56:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %57 = getelementptr inbounds %struct.Hash, ptr %6, i32 0, i32 0
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [2333333 x i32], ptr @pre, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  store i32 %61, ptr %57, align 4, !tbaa !11
  %62 = getelementptr inbounds %struct.Hash, ptr %6, i32 0, i32 1
  %63 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %63, ptr %62, align 4, !tbaa !9
  %64 = load i32, ptr @tot, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr @tot, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [1000001 x %struct.Hash], ptr @e, i64 0, i64 %66
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %67, ptr align 4 %6, i64 8, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %68 = load i32, ptr @tot, align 4, !tbaa !5
  %69 = load i32, ptr %3, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [2333333 x i32], ptr @pre, i64 0, i64 %70
  store i32 %68, ptr %71, align 4, !tbaa !5
  store i32 0, ptr %5, align 4
  br label %72

72:                                               ; preds = %56, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  %73 = load i32, ptr %5, align 4
  switch i32 %73, label %75 [
    i32 0, label %74
    i32 1, label %74
  ]

74:                                               ; preds = %72, %72
  ret void

75:                                               ; preds = %72
  unreachable
}

; 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 }

@t = external dso_local local_unnamed_addr global i32, align 4
@tot = external dso_local local_unnamed_addr global i32, align 4
@pre = external dso_local local_unnamed_addr global [2333333 x i32], align 16
@tm = external dso_local local_unnamed_addr global [2333333 x i32], align 16
@e = external dso_local local_unnamed_addr global [1000001 x %struct.Hash], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: read, inaccessiblemem: none) uwtable
define dso_local void @_Z6inserti(i32 noundef %0) local_unnamed_addr #0 {
  %2 = srem i32 %0, 2333333
  %3 = icmp slt i32 %2, 0
  %4 = add nsw i32 %2, 2333333
  %spec.select = select i1 %3, i32 %4, i32 %2
  %5 = zext nneg i32 %spec.select to i64
  %6 = getelementptr inbounds [2333333 x i32], ptr @tm, i64 0, i64 %5
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = load i32, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %7, %8
  br i1 %.not, label %11, label %9

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

11:                                               ; preds = %9, %1
  %12 = getelementptr inbounds [2333333 x i32], ptr @pre, i64 0, i64 %5
  br label %13

13:                                               ; preds = %14, %11
  %.015.in = phi ptr [ %12, %11 ], [ %16, %14 ]
  %.015 = load i32, ptr %.015.in, align 4, !tbaa !5
  %.not18 = icmp eq i32 %.015, 0
  br i1 %.not18, label %.critedge, label %14

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

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

.loopexit:                                        ; preds = %14, %.critedge
  ret void
}

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,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass