; LLVM IR from tangjz/acm-icpc :: lydsy/3067.ll (Z6insertx)

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

@tot = external dso_local global i32, align 4
@pre = external dso_local global [8388608 x i32], align 16
@e = external dso_local global [300002 x %struct.Hash], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6insertx(i64 noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca %struct.Hash, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %7 = load i64, ptr %2, align 8, !tbaa !5
  %8 = and i64 %7, 8388607
  %9 = trunc i64 %8 to i32
  store i32 %9, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %10 = load i32, ptr %3, align 4, !tbaa !9
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [8388608 x i32], ptr @pre, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %13, ptr %4, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %34, %1
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %18, label %17

17:                                               ; preds = %14
  store i32 2, ptr %5, align 4
  br label %40

18:                                               ; preds = %14
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [300002 x %struct.Hash], ptr @e, i64 0, i64 %20
  %22 = getelementptr inbounds %struct.Hash, ptr %21, i32 0, i32 2
  %23 = load i64, ptr %22, align 8, !tbaa !11
  %24 = load i64, ptr %2, align 8, !tbaa !5
  %25 = icmp eq i64 %23, %24
  br i1 %25, label %26, label %33

26:                                               ; preds = %18
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [300002 x %struct.Hash], ptr @e, i64 0, i64 %28
  %30 = getelementptr inbounds %struct.Hash, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 4, !tbaa !13
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %30, align 4, !tbaa !13
  store i32 1, ptr %5, align 4
  br label %40

33:                                               ; preds = %18
  br label %34

34:                                               ; preds = %33
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [300002 x %struct.Hash], ptr @e, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.Hash, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 16, !tbaa !14
  store i32 %39, ptr %4, align 4, !tbaa !9
  br label %14, !llvm.loop !15

40:                                               ; preds = %26, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %41 = load i32, ptr %5, align 4
  switch i32 %41, label %59 [
    i32 2, label %42
  ]

42:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #3
  %43 = getelementptr inbounds %struct.Hash, ptr %6, i32 0, i32 0
  %44 = load i32, ptr %3, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [8388608 x i32], ptr @pre, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !9
  store i32 %47, ptr %43, align 8, !tbaa !14
  %48 = getelementptr inbounds %struct.Hash, ptr %6, i32 0, i32 1
  store i32 1, ptr %48, align 4, !tbaa !13
  %49 = getelementptr inbounds %struct.Hash, ptr %6, i32 0, i32 2
  %50 = load i64, ptr %2, align 8, !tbaa !5
  store i64 %50, ptr %49, align 8, !tbaa !11
  %51 = load i32, ptr @tot, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr @tot, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [300002 x %struct.Hash], ptr @e, i64 0, i64 %53
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %54, ptr align 8 %6, i64 16, i1 false), !tbaa.struct !17
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #3
  %55 = load i32, ptr @tot, align 4, !tbaa !9
  %56 = load i32, ptr %3, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [8388608 x i32], ptr @pre, i64 0, i64 %57
  store i32 %55, ptr %58, align 4, !tbaa !9
  store i32 0, ptr %5, align 4
  br label %59

59:                                               ; preds = %42, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  %60 = load i32, ptr %5, align 4
  switch i32 %60, label %62 [
    i32 0, label %61
    i32 1, label %61
  ]

61:                                               ; preds = %59, %59
  ret void

62:                                               ; preds = %59
  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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTS4Hash", !10, i64 0, !10, i64 4, !6, i64 8}
!13 = !{!12, !10, i64 4}
!14 = !{!12, !10, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 8, !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, i64 }

@tot = external dso_local local_unnamed_addr global i32, align 4
@pre = external dso_local local_unnamed_addr global [8388608 x i32], align 16
@e = external dso_local local_unnamed_addr global [300002 x %struct.Hash], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: read, inaccessiblemem: none) uwtable
define dso_local void @_Z6insertx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = and i64 %0, 8388607
  %3 = getelementptr inbounds [8388608 x i32], ptr @pre, i64 0, i64 %2
  br label %4

4:                                                ; preds = %5, %1
  %.0.in = phi ptr [ %3, %1 ], [ %7, %5 ]
  %.0 = load i32, ptr %.0.in, align 4, !tbaa !5
  %.not = icmp eq i32 %.0, 0
  br i1 %.not, label %.critedge, label %5

5:                                                ; preds = %4
  %6 = sext i32 %.0 to i64
  %7 = getelementptr inbounds [300002 x %struct.Hash], ptr @e, i64 0, i64 %6
  %8 = getelementptr inbounds i8, ptr %7, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %10 = icmp eq i64 %9, %0
  br i1 %10, label %11, label %4, !llvm.loop !12

11:                                               ; preds = %5
  %12 = getelementptr inbounds i8, ptr %7, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !14
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr %12, align 4, !tbaa !14
  br label %20

.critedge:                                        ; preds = %4
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = load i32, ptr @tot, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr @tot, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [300002 x %struct.Hash], ptr @e, i64 0, i64 %18
  store i32 %15, ptr %19, align 16, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %19, i64 4
  store i32 1, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %19, i64 8
  store i64 %0, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !15
  store i32 %17, ptr %3, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %11, %.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, !11, i64 8}
!10 = !{!"_ZTS4Hash", !6, i64 0, !6, i64 4, !11, i64 8}
!11 = !{!"long long", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!10, !6, i64 4}
!15 = !{!11, !11, i64 0}


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