; LLVM IR from tangjz/acm-icpc :: TDL_training/2015-10-05/F - Fund Management - tjz.ll (Z3dfsiix)

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

@n = external dso_local global i32, align 4
@limit = external dso_local global i32, align 4
@tot = external dso_local global i32, align 4
@lim = external dso_local global [10 x i32], align 16
@que = external dso_local global [233333 x i64], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsiix(i32 noundef %0, i32 noundef %1, i64 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = icmp eq i32 %8, %9
  br i1 %10, label %11, label %17

11:                                               ; preds = %3
  %12 = load i64, ptr %6, align 8, !tbaa !9
  %13 = load i32, ptr @tot, align 4, !tbaa !5
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr @tot, align 4, !tbaa !5
  %15 = sext i32 %13 to i64
  %16 = getelementptr inbounds [233333 x i64], ptr @que, i64 0, i64 %15
  store i64 %12, ptr %16, align 8, !tbaa !9
  br label %51

17:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %48, %17
  %19 = load i32, ptr %7, align 4, !tbaa !5
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [10 x i32], ptr @lim, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = icmp sle i32 %19, %23
  br i1 %24, label %25, label %31

25:                                               ; preds = %18
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = add nsw i32 %26, %27
  %29 = load i32, ptr @limit, align 4, !tbaa !5
  %30 = icmp sle i32 %28, %29
  br label %31

31:                                               ; preds = %25, %18
  %32 = phi i1 [ false, %18 ], [ %30, %25 ]
  br i1 %32, label %34, label %33

33:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %51

34:                                               ; preds = %31
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = add nsw i32 %37, %38
  %40 = load i64, ptr %6, align 8, !tbaa !9
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = mul nsw i32 4, %43
  %45 = zext i32 %44 to i64
  %46 = shl i64 %42, %45
  %47 = or i64 %40, %46
  call void @_Z3dfsiix(i32 noundef %36, i32 noundef %39, i64 noundef %47)
  br label %48

48:                                               ; preds = %34
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %7, align 4, !tbaa !5
  br label %18, !llvm.loop !11

51:                                               ; preds = %33, %11
  ret void
}

; 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

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 = { 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 = !{!"long long", !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"

@n = external dso_local local_unnamed_addr global i32, align 4
@limit = external dso_local local_unnamed_addr global i32, align 4
@tot = external dso_local local_unnamed_addr global i32, align 4
@lim = external dso_local local_unnamed_addr global [10 x i32], align 16
@que = external dso_local local_unnamed_addr global [233333 x i64], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3dfsiix(i32 noundef %0, i32 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = icmp eq i32 %4, %0
  br i1 %5, label %13, label %.preheader

.preheader:                                       ; preds = %3
  %6 = sext i32 %0 to i64
  %7 = getelementptr inbounds [10 x i32], ptr @lim, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %.not16 = icmp slt i32 %8, 0
  br i1 %.not16, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %9 = add nsw i32 %0, 1
  %10 = shl nsw i32 %0, 2
  %11 = zext nneg i32 %10 to i64
  %12 = sext i32 %1 to i64
  br label %18

13:                                               ; preds = %3
  %14 = load i32, ptr @tot, align 4, !tbaa !5
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr @tot, align 4, !tbaa !5
  %16 = sext i32 %14 to i64
  %17 = getelementptr inbounds [233333 x i64], ptr @que, i64 0, i64 %16
  store i64 %2, ptr %17, align 8, !tbaa !9
  br label %.critedge

18:                                               ; preds = %.lr.ph, %22
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %22 ]
  %19 = add nsw i64 %indvars.iv, %12
  %20 = load i32, ptr @limit, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %.not15 = icmp sgt i64 %19, %21
  br i1 %.not15, label %.critedge, label %22

22:                                               ; preds = %18
  %23 = shl i64 %indvars.iv, %11
  %24 = or i64 %23, %2
  %25 = trunc nsw i64 %19 to i32
  tail call void @_Z3dfsiix(i32 noundef %9, i32 noundef %25, i64 noundef %24)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %.not.not = icmp slt i64 %indvars.iv, %27
  br i1 %.not.not, label %18, label %.critedge, !llvm.loop !11

.critedge:                                        ; preds = %22, %18, %.preheader, %13
  ret void
}

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}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass