; LLVM IR from tangjz/acm-icpc :: codeforces/complete/615C.ll (Z6insertiiii)

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

@tot = external dso_local global i32, align 4
@lnk = external dso_local global [4256233 x i32], align 16
@e = external dso_local global [4937284 x %struct.Hash], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6insertiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca %struct.Hash, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %13 = load i32, ptr %7, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = shl i64 %14, 31
  %16 = load i32, ptr %8, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = xor i64 %15, %17
  %19 = srem i64 %18, 4256233
  %20 = trunc i64 %19 to i32
  store i32 %20, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %21 = load i32, ptr %9, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [4256233 x i32], ptr @lnk, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  store i32 %24, ptr %10, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %47, %4
  %26 = load i32, ptr %10, align 4, !tbaa !5
  %27 = icmp ne i32 %26, -1
  br i1 %27, label %29, label %28

28:                                               ; preds = %25
  store i32 2, ptr %11, align 4
  br label %53

29:                                               ; preds = %25
  %30 = load i32, ptr %10, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [4937284 x %struct.Hash], ptr @e, i64 0, i64 %31
  %33 = getelementptr inbounds %struct.Hash, ptr %32, i32 0, i32 3
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = load i32, ptr %7, align 4, !tbaa !5
  %36 = icmp eq i32 %34, %35
  br i1 %36, label %37, label %46

37:                                               ; preds = %29
  %38 = load i32, ptr %10, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [4937284 x %struct.Hash], ptr @e, i64 0, i64 %39
  %41 = getelementptr inbounds %struct.Hash, ptr %40, i32 0, i32 4
  %42 = load i32, ptr %41, align 4, !tbaa !11
  %43 = load i32, ptr %8, align 4, !tbaa !5
  %44 = icmp eq i32 %42, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %37
  store i32 1, ptr %11, align 4
  br label %53

46:                                               ; preds = %37, %29
  br label %47

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

53:                                               ; preds = %45, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %54 = load i32, ptr %11, align 4
  switch i32 %54, label %77 [
    i32 2, label %55
  ]

55:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 20, ptr %12) #3
  %56 = getelementptr inbounds %struct.Hash, ptr %12, i32 0, i32 0
  %57 = load i32, ptr %9, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [4256233 x i32], ptr @lnk, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  store i32 %60, ptr %56, align 4, !tbaa !12
  %61 = getelementptr inbounds %struct.Hash, ptr %12, i32 0, i32 1
  %62 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %62, ptr %61, align 4, !tbaa !15
  %63 = getelementptr inbounds %struct.Hash, ptr %12, i32 0, i32 2
  %64 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %64, ptr %63, align 4, !tbaa !16
  %65 = getelementptr inbounds %struct.Hash, ptr %12, i32 0, i32 3
  %66 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %66, ptr %65, align 4, !tbaa !9
  %67 = getelementptr inbounds %struct.Hash, ptr %12, i32 0, i32 4
  %68 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %68, ptr %67, align 4, !tbaa !11
  %69 = load i32, ptr @tot, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [4937284 x %struct.Hash], ptr @e, i64 0, i64 %70
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %71, ptr align 4 %12, i64 20, i1 false), !tbaa.struct !17
  call void @llvm.lifetime.end.p0(i64 20, ptr %12) #3
  %72 = load i32, ptr @tot, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr @tot, align 4, !tbaa !5
  %74 = load i32, ptr %9, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [4256233 x i32], ptr @lnk, i64 0, i64 %75
  store i32 %72, ptr %76, align 4, !tbaa !5
  store i32 0, ptr %11, align 4
  br label %77

77:                                               ; preds = %55, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %78 = load i32, ptr %11, align 4
  switch i32 %78, label %80 [
    i32 0, label %79
    i32 1, label %79
  ]

79:                                               ; preds = %77, %77
  ret void

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

@tot = external dso_local local_unnamed_addr global i32, align 4
@lnk = external dso_local local_unnamed_addr global [4256233 x i32], align 16
@e = external dso_local local_unnamed_addr global [4937284 x %struct.Hash], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z6insertiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = sext i32 %2 to i64
  %6 = shl nsw i64 %5, 31
  %7 = sext i32 %3 to i64
  %8 = xor i64 %6, %7
  %9 = srem i64 %8, 4256233
  %10 = getelementptr inbounds [4256233 x i32], ptr @lnk, i64 0, i64 %9
  %.017 = load i32, ptr %10, align 4, !tbaa !5
  %.not18 = icmp eq i32 %.017, -1
  br i1 %.not18, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %4, %20
  %.019 = phi i32 [ %.0, %20 ], [ %.017, %4 ]
  %11 = sext i32 %.019 to i64
  %12 = getelementptr inbounds [4937284 x %struct.Hash], ptr @e, i64 0, i64 %11
  %13 = getelementptr inbounds i8, ptr %12, i64 12
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = icmp eq i32 %14, %2
  br i1 %15, label %16, label %20

16:                                               ; preds = %.lr.ph
  %17 = getelementptr inbounds i8, ptr %12, i64 16
  %18 = load i32, ptr %17, align 4, !tbaa !11
  %19 = icmp eq i32 %18, %3
  br i1 %19, label %.loopexit, label %20

20:                                               ; preds = %.lr.ph, %16
  %.0 = load i32, ptr %12, align 4, !tbaa !5
  %.not = icmp eq i32 %.0, -1
  br i1 %.not, label %.critedge, label %.lr.ph, !llvm.loop !12

.critedge:                                        ; preds = %20, %4
  %21 = load i32, ptr @tot, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [4937284 x %struct.Hash], ptr @e, i64 0, i64 %22
  store i32 %.017, ptr %23, align 4, !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
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %23, i64 8
  store i32 %1, ptr %.sroa.5.0..sroa_idx, align 4, !tbaa !5
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %23, i64 12
  store i32 %2, ptr %.sroa.6.0..sroa_idx, align 4, !tbaa !5
  %.sroa.7.0..sroa_idx = getelementptr inbounds i8, ptr %23, i64 16
  store i32 %3, ptr %.sroa.7.0..sroa_idx, align 4, !tbaa !5
  %24 = add nsw i32 %21, 1
  store i32 %24, ptr @tot, align 4, !tbaa !5
  store i32 %21, ptr %10, align 4, !tbaa !5
  br label %.loopexit

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, 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 12}
!10 = !{!"_ZTS4Hash", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16}
!11 = !{!10, !6, i64 16}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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