; LLVM IR from tangjz/acm-icpc :: codeforces/gym/103957H.ll (Z8getFlushPi)

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z8getFlushPi(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds i32, ptr %8, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = ashr i32 %10, 2
  store i32 %11, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds i32, ptr %12, i64 4
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = and i32 %14, 3
  store i32 %15, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 3, ptr %6, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %40, %1
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = icmp sge i32 %17, 0
  br i1 %18, label %20, label %19

19:                                               ; preds = %16
  store i32 2, ptr %7, align 4
  br label %43

20:                                               ; preds = %16
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr %21, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = and i32 %25, 3
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = icmp ne i32 %26, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %20
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %43

30:                                               ; preds = %20
  %31 = load i32, ptr %4, align 4, !tbaa !9
  %32 = shl i32 %31, 4
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds i32, ptr %33, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %38 = ashr i32 %37, 2
  %39 = or i32 %32, %38
  store i32 %39, ptr %4, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %30
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = add nsw i32 %41, -1
  store i32 %42, ptr %6, align 4, !tbaa !9
  br label %16, !llvm.loop !11

43:                                               ; preds = %29, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %44 = load i32, ptr %7, align 4
  switch i32 %44, label %47 [
    i32 2, label %45
  ]

45:                                               ; preds = %43
  %46 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %46, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %47

47:                                               ; preds = %45, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %48 = load i32, ptr %2, align 4
  ret i32 %48
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef i32 @_Z8getFlushPi(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 12
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = xor i32 %5, %3
  %7 = and i32 %6, 3
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %8, label %36

8:                                                ; preds = %1
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = xor i32 %10, %3
  %12 = and i32 %11, 3
  %.not.1 = icmp eq i32 %12, 0
  br i1 %.not.1, label %13, label %36

13:                                               ; preds = %8
  %14 = getelementptr inbounds i8, ptr %0, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = xor i32 %15, %3
  %17 = and i32 %16, 3
  %.not.2 = icmp eq i32 %17, 0
  br i1 %.not.2, label %18, label %36

18:                                               ; preds = %13
  %19 = load i32, ptr %0, align 4, !tbaa !5
  %20 = xor i32 %19, %3
  %21 = and i32 %20, 3
  %.not.3 = icmp eq i32 %21, 0
  br i1 %.not.3, label %22, label %36

22:                                               ; preds = %18
  %23 = lshr i32 %15, 2
  %24 = lshr i32 %5, 2
  %25 = shl i32 %3, 2
  %26 = and i32 %25, 1048560
  %27 = or i32 %24, %26
  %28 = shl i32 %27, 8
  %29 = shl i32 %10, 2
  %30 = and i32 %29, 268435440
  %31 = or i32 %28, %30
  %32 = or i32 %23, %31
  %33 = shl i32 %32, 4
  %34 = ashr i32 %19, 2
  %35 = or i32 %34, %33
  br label %36

36:                                               ; preds = %22, %18, %13, %8, %1
  %spec.select = phi i32 [ 0, %1 ], [ 0, %8 ], [ 0, %13 ], [ 0, %18 ], [ %35, %22 ]
  ret i32 %spec.select
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass