; LLVM IR from tangjz/acm-icpc :: 51nod/1408.ll (Z4bsgsiiiiR9HashTable)

; 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.HashTable = type { i32, i32, [5552263 x i32], [2000010 x i32], [2000010 x i32], [2000010 x i32] }

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z7mod_invii(i32 noundef, i32 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 i32 @_Z7mod_powiii(i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z4bsgsiiiiR9HashTable(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef nonnull align 4 dereferenceable(46209180) %4) #0 {
  %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 ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !9
  %19 = load i32, ptr %8, align 4, !tbaa !5
  %20 = icmp eq i32 %19, 1
  br i1 %20, label %21, label %22

21:                                               ; preds = %5
  store i32 1, ptr %6, align 4
  br label %74

22:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %23 = load ptr, ptr %11, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.HashTable, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !11
  store i32 %25, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %26 = load i32, ptr %10, align 4, !tbaa !5
  %27 = load i32, ptr %12, align 4, !tbaa !5
  %28 = sdiv i32 %26, %27
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 0, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %30 = load i32, ptr %7, align 4, !tbaa !5
  %31 = load i32, ptr %12, align 4, !tbaa !5
  %32 = load i32, ptr %8, align 4, !tbaa !5
  %33 = call noundef i32 @_Z7mod_powiii(i32 noundef %30, i32 noundef %31, i32 noundef %32)
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = call noundef i32 @_Z7mod_invii(i32 noundef %33, i32 noundef %34)
  store i32 %35, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %36 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %36, ptr %16, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %58, %22
  %38 = load i32, ptr %14, align 4, !tbaa !5
  %39 = load i32, ptr %13, align 4, !tbaa !5
  %40 = icmp sle i32 %38, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %37
  store i32 2, ptr %17, align 4
  br label %70

42:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  %43 = load ptr, ptr %11, align 8, !tbaa !9
  %44 = load i32, ptr %16, align 4, !tbaa !5
  %45 = call noundef i32 @_ZN9HashTable4findEi(ptr noundef nonnull align 4 dereferenceable(46209180) %43, i32 noundef %44)
  store i32 %45, ptr %18, align 4, !tbaa !5
  %46 = load i32, ptr %18, align 4, !tbaa !5
  %47 = icmp ne i32 %46, -1
  br i1 %47, label %48, label %54

48:                                               ; preds = %42
  %49 = load i32, ptr %14, align 4, !tbaa !5
  %50 = load i32, ptr %12, align 4, !tbaa !5
  %51 = mul nsw i32 %49, %50
  %52 = load i32, ptr %18, align 4, !tbaa !5
  %53 = add nsw i32 %51, %52
  store i32 %53, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %55

54:                                               ; preds = %42
  store i32 0, ptr %17, align 4
  br label %55

55:                                               ; preds = %54, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  %56 = load i32, ptr %17, align 4
  switch i32 %56, label %70 [
    i32 0, label %57
  ]

57:                                               ; preds = %55
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %14, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %14, align 4, !tbaa !5
  %61 = load i32, ptr %16, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = load i32, ptr %15, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = mul nsw i64 %62, %64
  %66 = load i32, ptr %8, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = srem i64 %65, %67
  %69 = trunc i64 %68 to i32
  store i32 %69, ptr %16, align 4, !tbaa !5
  br label %37, !llvm.loop !13

70:                                               ; preds = %55, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  %71 = load i32, ptr %17, align 4
  switch i32 %71, label %73 [
    i32 2, label %72
  ]

72:                                               ; preds = %70
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %73

73:                                               ; preds = %72, %70
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %74

74:                                               ; preds = %73, %21
  %75 = load i32, ptr %6, align 4
  ret i32 %75
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN9HashTable4findEi(ptr noundef nonnull align 4 dereferenceable(46209180), i32 noundef) #2 align 2

attributes #0 = { mustprogress 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 = { 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 #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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 4}
!12 = !{!"_ZTS9HashTable", !6, i64 0, !6, i64 4, !7, i64 8, !7, i64 22209060, !7, i64 30209100, !7, i64 38209140}
!13 = distinct !{!13, !14}
!14 = !{!"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 uwtable
declare dso_local noundef i32 @_Z7mod_invii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7mod_powiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z4bsgsiiiiR9HashTable(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef nonnull align 4 dereferenceable(46209180) %4) local_unnamed_addr #0 {
  %6 = icmp eq i32 %1, 1
  br i1 %6, label %.loopexit, label %7

7:                                                ; preds = %5
  %8 = getelementptr inbounds i8, ptr %4, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = sdiv i32 %3, %9
  %11 = tail call noundef i32 @_Z7mod_powiii(i32 noundef %0, i32 noundef %9, i32 noundef %1)
  %12 = tail call noundef i32 @_Z7mod_invii(i32 noundef %11, i32 noundef %1)
  %.not34 = icmp slt i32 %10, -1
  br i1 %.not34, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %7
  %13 = sext i32 %12 to i64
  %14 = sext i32 %1 to i64
  %15 = add i32 %10, 1
  br label %16

16:                                               ; preds = %.lr.ph, %18
  %.02636 = phi i32 [ %2, %.lr.ph ], [ %23, %18 ]
  %.02735 = phi i32 [ 0, %.lr.ph ], [ %19, %18 ]
  %17 = tail call noundef i32 @_ZN9HashTable4findEi(ptr noundef nonnull align 4 dereferenceable(46209180) %4, i32 noundef %.02636)
  %.not30 = icmp eq i32 %17, -1
  br i1 %.not30, label %18, label %.loopexit.split.loop.exit31

18:                                               ; preds = %16
  %19 = add nuw i32 %.02735, 1
  %20 = sext i32 %.02636 to i64
  %21 = mul nsw i64 %20, %13
  %22 = srem i64 %21, %14
  %23 = trunc nsw i64 %22 to i32
  %exitcond = icmp eq i32 %.02735, %15
  br i1 %exitcond, label %.loopexit, label %16, !llvm.loop !10

.loopexit.split.loop.exit31:                      ; preds = %16
  %24 = mul nsw i32 %.02735, %9
  %25 = add nsw i32 %17, %24
  br label %.loopexit

.loopexit:                                        ; preds = %18, %.loopexit.split.loop.exit31, %7, %5
  %.4 = phi i32 [ 1, %5 ], [ %25, %.loopexit.split.loop.exit31 ], [ -1, %7 ], [ -1, %18 ]
  ret i32 %.4
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN9HashTable4findEi(ptr noundef nonnull align 4 dereferenceable(46209180), i32 noundef) local_unnamed_addr #1 align 2

attributes #0 = { mustprogress 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 = { 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, !7, i64 4}
!6 = !{!"_ZTS9HashTable", !7, i64 0, !7, i64 4, !8, i64 8, !8, i64 22209060, !8, i64 30209100, !8, i64 38209140}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass