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

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

@a = external dso_local global [200010 x [10 x i32]], align 16
@cnt = external dso_local global [500010 x i32], align 16
@tmp = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3pfsiiii(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
  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
  %9 = load i32, ptr %7, align 4, !tbaa !5
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [200010 x [10 x i32]], ptr @a, i64 0, i64 %11
  %13 = getelementptr inbounds [10 x i32], ptr %12, i64 0, i64 0
  %14 = load i32, ptr %13, align 8, !tbaa !5
  %15 = icmp eq i32 %9, %14
  br i1 %15, label %16, label %27

16:                                               ; preds = %4
  %17 = load i32, ptr %8, align 4, !tbaa !5
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %19, label %26

19:                                               ; preds = %16
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = load i32, ptr @tmp, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [500010 x i32], ptr @cnt, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = add nsw i32 %24, %20
  store i32 %25, ptr %23, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %19, %16
  br label %59

27:                                               ; preds = %4
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = load i32, ptr %7, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  %32 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z3pfsiiii(i32 noundef %28, i32 noundef %29, i32 noundef %31, i32 noundef %32)
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [200010 x [10 x i32]], ptr @a, i64 0, i64 %34
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [10 x i32], ptr %35, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = load i32, ptr @tmp, align 4, !tbaa !5
  %42 = mul nsw i32 %41, %40
  store i32 %42, ptr @tmp, align 4, !tbaa !5
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  %47 = load i32, ptr %8, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  call void @_Z3pfsiiii(i32 noundef %43, i32 noundef %44, i32 noundef %46, i32 noundef %48)
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [200010 x [10 x i32]], ptr @a, i64 0, i64 %50
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [10 x i32], ptr %51, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = load i32, ptr @tmp, align 4, !tbaa !5
  %58 = sdiv i32 %57, %56
  store i32 %58, ptr @tmp, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %27, %26
  ret void
}

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

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


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

@a = external dso_local local_unnamed_addr global [200010 x [10 x i32]], align 16
@cnt = external dso_local local_unnamed_addr global [500010 x i32], align 16
@tmp = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3pfsiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = sext i32 %0 to i64
  %6 = getelementptr inbounds [200010 x [10 x i32]], ptr @a, i64 0, i64 %5
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = icmp eq i32 %7, %2
  br i1 %8, label %9, label %17

9:                                                ; preds = %4
  %10 = icmp sgt i32 %3, 0
  br i1 %10, label %11, label %common.ret16

11:                                               ; preds = %9
  %12 = load i32, ptr @tmp, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [500010 x i32], ptr @cnt, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = add nsw i32 %15, %1
  store i32 %16, ptr %14, align 4, !tbaa !5
  br label %common.ret16

common.ret16:                                     ; preds = %9, %11, %17
  ret void

17:                                               ; preds = %4
  %18 = add nsw i32 %2, 1
  tail call void @_Z3pfsiiii(i32 noundef %0, i32 noundef %1, i32 noundef %18, i32 noundef %3)
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [200010 x [10 x i32]], ptr @a, i64 0, i64 %5, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = load i32, ptr @tmp, align 4, !tbaa !5
  %23 = mul nsw i32 %22, %21
  store i32 %23, ptr @tmp, align 4, !tbaa !5
  %24 = add nsw i32 %3, 1
  tail call void @_Z3pfsiiii(i32 noundef %0, i32 noundef %1, i32 noundef %18, i32 noundef %24)
  %25 = load i32, ptr %20, align 4, !tbaa !5
  %26 = load i32, ptr @tmp, align 4, !tbaa !5
  %27 = sdiv i32 %26, %25
  store i32 %27, ptr @tmp, align 4, !tbaa !5
  br label %common.ret16
}

attributes #0 = { mustprogress nofree 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"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass