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

; 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
@tmpcnt = external dso_local global i64, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %7 = load i32, ptr %5, align 4, !tbaa !5
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [200010 x [10 x i32]], ptr @a, i64 0, i64 %9
  %11 = getelementptr inbounds [10 x i32], ptr %10, i64 0, i64 0
  %12 = load i32, ptr %11, align 8, !tbaa !5
  %13 = icmp eq i32 %7, %12
  br i1 %13, label %14, label %39

14:                                               ; preds = %3
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %17, label %38

17:                                               ; preds = %14
  %18 = load i32, ptr %6, align 4, !tbaa !5
  %19 = and i32 %18, 1
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %29

21:                                               ; preds = %17
  %22 = load i32, ptr @tmp, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [500010 x i32], ptr @cnt, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = load i64, ptr @tmpcnt, align 8, !tbaa !9
  %28 = add nsw i64 %27, %26
  store i64 %28, ptr @tmpcnt, align 8, !tbaa !9
  br label %37

29:                                               ; preds = %17
  %30 = load i32, ptr @tmp, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [500010 x i32], ptr @cnt, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = load i64, ptr @tmpcnt, align 8, !tbaa !9
  %36 = sub nsw i64 %35, %34
  store i64 %36, ptr @tmpcnt, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %29, %21
  br label %38

38:                                               ; preds = %37, %14
  br label %69

39:                                               ; preds = %3
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  %43 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z3dfsiii(i32 noundef %40, i32 noundef %42, i32 noundef %43)
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [200010 x [10 x i32]], ptr @a, i64 0, i64 %45
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [10 x i32], ptr %46, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = load i32, ptr @tmp, align 4, !tbaa !5
  %53 = mul nsw i32 %52, %51
  store i32 %53, ptr @tmp, align 4, !tbaa !5
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  %57 = load i32, ptr %6, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  call void @_Z3dfsiii(i32 noundef %54, i32 noundef %56, i32 noundef %58)
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [200010 x [10 x i32]], ptr @a, i64 0, i64 %60
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [10 x i32], ptr %61, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = load i32, ptr @tmp, align 4, !tbaa !5
  %68 = sdiv i32 %67, %66
  store i32 %68, ptr @tmp, align 4, !tbaa !5
  br label %69

69:                                               ; preds = %39, %38
  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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}


; 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
@tmpcnt = external dso_local local_unnamed_addr global i64, align 8

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

8:                                                ; preds = %3
  %9 = icmp sgt i32 %2, 0
  br i1 %9, label %10, label %common.ret15

10:                                               ; preds = %8
  %11 = and i32 %2, 1
  %.not = icmp eq i32 %11, 0
  %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 = sext i32 %15 to i64
  %17 = load i64, ptr @tmpcnt, align 8, !tbaa !9
  br i1 %.not, label %20, label %18

18:                                               ; preds = %10
  %19 = add nsw i64 %17, %16
  store i64 %19, ptr @tmpcnt, align 8, !tbaa !9
  br label %common.ret15

20:                                               ; preds = %10
  %21 = sub nsw i64 %17, %16
  store i64 %21, ptr @tmpcnt, align 8, !tbaa !9
  br label %common.ret15

common.ret15:                                     ; preds = %8, %20, %18, %22
  ret void

22:                                               ; preds = %3
  %23 = add nsw i32 %1, 1
  tail call void @_Z3dfsiii(i32 noundef %0, i32 noundef %23, i32 noundef %2)
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [200010 x [10 x i32]], ptr @a, i64 0, i64 %4, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = load i32, ptr @tmp, align 4, !tbaa !5
  %28 = mul nsw i32 %27, %26
  store i32 %28, ptr @tmp, align 4, !tbaa !5
  %29 = add nsw i32 %2, 1
  tail call void @_Z3dfsiii(i32 noundef %0, i32 noundef %23, i32 noundef %29)
  %30 = load i32, ptr %25, align 4, !tbaa !5
  %31 = load i32, ptr @tmp, align 4, !tbaa !5
  %32 = sdiv i32 %31, %30
  store i32 %32, ptr @tmp, align 4, !tbaa !5
  br label %common.ret15
}

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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}


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