; LLVM IR from upupming/algorithm :: acwing/算法竞赛进阶指南/0x14-Hash/137. 雪花雪花雪花.ll (Z6insertPii)

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

@snow = external dso_local global [100010 x [6 x i32]], align 16
@head = external dso_local global [100010 x i32], align 16
@nxt = external dso_local global [100010 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z1HPi(ptr noundef) #0

; 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: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z5equalPiS_(ptr noundef, ptr noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z6insertPii(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call noundef i32 @_Z1HPi(ptr noundef %9)
  store i32 %10, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [100010 x i32], ptr @head, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %14, ptr %7, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %28, %2
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  store i32 2, ptr %8, align 4
  br label %33

19:                                               ; preds = %15
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [100010 x [6 x i32]], ptr @snow, i64 0, i64 %22
  %24 = getelementptr inbounds [6 x i32], ptr %23, i64 0, i64 0
  %25 = call noundef zeroext i1 @_Z5equalPiS_(ptr noundef %20, ptr noundef %24)
  br i1 %25, label %26, label %27

26:                                               ; preds = %19
  store i1 true, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %33

27:                                               ; preds = %19
  br label %28

28:                                               ; preds = %27
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100010 x i32], ptr @nxt, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !9
  store i32 %32, ptr %7, align 4, !tbaa !9
  br label %15, !llvm.loop !11

33:                                               ; preds = %26, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  %34 = load i32, ptr %8, align 4
  switch i32 %34, label %47 [
    i32 2, label %35
  ]

35:                                               ; preds = %33
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100010 x i32], ptr @head, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [100010 x i32], ptr @nxt, i64 0, i64 %41
  store i32 %39, ptr %42, align 4, !tbaa !9
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100010 x i32], ptr @head, i64 0, i64 %45
  store i32 %43, ptr %46, align 4, !tbaa !9
  store i1 false, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %47

47:                                               ; preds = %35, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %48 = load i1, ptr %3, align 1
  ret i1 %48
}

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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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

@snow = external dso_local global [100010 x [6 x i32]], align 16
@head = external dso_local local_unnamed_addr global [100010 x i32], align 16
@nxt = external dso_local local_unnamed_addr global [100010 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z1HPi(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z5equalPiS_(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z6insertPii(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call noundef i32 @_Z1HPi(ptr noundef %0)
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [100010 x i32], ptr @head, i64 0, i64 %4
  %.01115 = load i32, ptr %5, align 4, !tbaa !5
  %.not16.not = icmp eq i32 %.01115, 0
  br i1 %.not16.not, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %9
  %.01117 = phi i32 [ %.011, %9 ], [ %.01115, %2 ]
  %6 = sext i32 %.01117 to i64
  %7 = getelementptr inbounds [100010 x [6 x i32]], ptr @snow, i64 0, i64 %6
  %8 = tail call noundef zeroext i1 @_Z5equalPiS_(ptr noundef %0, ptr noundef nonnull %7)
  br i1 %8, label %.loopexit, label %9

9:                                                ; preds = %.lr.ph
  %10 = getelementptr inbounds [100010 x i32], ptr @nxt, i64 0, i64 %6
  %.011 = load i32, ptr %10, align 4, !tbaa !5
  %.not.not = icmp eq i32 %.011, 0
  br i1 %.not.not, label %.critedge.loopexit, label %.lr.ph, !llvm.loop !9

.critedge.loopexit:                               ; preds = %9
  %.pre = load i32, ptr %5, align 4, !tbaa !5
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %2
  %11 = phi i32 [ %.pre, %.critedge.loopexit ], [ 0, %2 ]
  %12 = sext i32 %1 to i64
  %13 = getelementptr inbounds [100010 x i32], ptr @nxt, i64 0, i64 %12
  store i32 %11, ptr %13, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %.critedge
  %.not14 = phi i1 [ false, %.critedge ], [ true, %.lr.ph ]
  ret i1 %.not14
}

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

!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"}


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