; LLVM IR from tangjz/acm-icpc :: codeforces/complete/819C.ll (Z3dfsix)

; 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.Factor = type { i64, i32, [23 x i32], [23 x i32] }

@ans = external dso_local global i64, align 8
@N = external dso_local global %struct.Factor, align 8
@S = external dso_local global %struct.Factor, align 8

; 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 uwtable
define dso_local void @_Z3dfsix(i32 noundef %0, i64 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %6 = load i64, ptr %4, align 8, !tbaa !9
  %7 = load i64, ptr @N, align 8, !tbaa !11
  %8 = icmp sgt i64 %6, %7
  br i1 %8, label %9, label %10

9:                                                ; preds = %2
  br label %42

10:                                               ; preds = %2
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = load i32, ptr getelementptr inbounds (%struct.Factor, ptr @S, i32 0, i32 1), align 8, !tbaa !13
  %13 = icmp eq i32 %11, %12
  br i1 %13, label %14, label %17

14:                                               ; preds = %10
  %15 = load i64, ptr @ans, align 8, !tbaa !9
  %16 = add nsw i64 %15, 1
  store i64 %16, ptr @ans, align 8, !tbaa !9
  br label %42

17:                                               ; preds = %10
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  %20 = load i64, ptr %4, align 8, !tbaa !9
  call void @_Z3dfsix(i32 noundef %19, i64 noundef %20)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %39, %17
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [23 x i32], ptr getelementptr inbounds (%struct.Factor, ptr @S, i32 0, i32 3), i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = icmp sle i32 %22, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %42

29:                                               ; preds = %21
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [23 x i32], ptr getelementptr inbounds (%struct.Factor, ptr @S, i32 0, i32 2), i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = load i64, ptr %4, align 8, !tbaa !9
  %38 = mul nsw i64 %37, %36
  store i64 %38, ptr %4, align 8, !tbaa !9
  call void @_Z3dfsix(i32 noundef %31, i64 noundef %38)
  br label %39

39:                                               ; preds = %29
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %5, align 4, !tbaa !5
  br label %21, !llvm.loop !14

42:                                               ; preds = %28, %14, %9
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!12, !10, i64 0}
!12 = !{!"_ZTS6Factor", !10, i64 0, !6, i64 8, !7, i64 12, !7, i64 104}
!13 = !{!12, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"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"

%struct.Factor = type { i64, i32, [23 x i32], [23 x i32] }

@ans = external dso_local local_unnamed_addr global i64, align 8
@N = external dso_local local_unnamed_addr global %struct.Factor, align 8
@S = external dso_local local_unnamed_addr global %struct.Factor, align 8

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3dfsix(i32 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = load i64, ptr @N, align 8, !tbaa !5
  %4 = icmp slt i64 %3, %1
  br i1 %4, label %.loopexit, label %5

5:                                                ; preds = %2
  %6 = load i32, ptr getelementptr inbounds (i8, ptr @S, i64 8), align 8, !tbaa !11
  %7 = icmp eq i32 %6, %0
  br i1 %7, label %8, label %11

8:                                                ; preds = %5
  %9 = load i64, ptr @ans, align 8, !tbaa !12
  %10 = add nsw i64 %9, 1
  store i64 %10, ptr @ans, align 8, !tbaa !12
  br label %.loopexit

11:                                               ; preds = %5
  %12 = add nsw i32 %0, 1
  tail call void @_Z3dfsix(i32 noundef %12, i64 noundef %1)
  %13 = sext i32 %0 to i64
  %14 = getelementptr inbounds [23 x i32], ptr getelementptr inbounds (i8, ptr @S, i64 104), i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !13
  %.not13 = icmp slt i32 %15, 1
  br i1 %.not13, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %11
  %16 = getelementptr inbounds [23 x i32], ptr getelementptr inbounds (i8, ptr @S, i64 12), i64 0, i64 %13
  br label %17

17:                                               ; preds = %.lr.ph, %17
  %.015 = phi i32 [ 1, %.lr.ph ], [ %21, %17 ]
  %.01014 = phi i64 [ %1, %.lr.ph ], [ %20, %17 ]
  %18 = load i32, ptr %16, align 4, !tbaa !13
  %19 = sext i32 %18 to i64
  %20 = mul nsw i64 %.01014, %19
  tail call void @_Z3dfsix(i32 noundef %12, i64 noundef %20)
  %21 = add nuw nsw i32 %.015, 1
  %22 = load i32, ptr %14, align 4, !tbaa !13
  %.not.not = icmp slt i32 %.015, %22
  br i1 %.not.not, label %17, label %.loopexit, !llvm.loop !14

.loopexit:                                        ; preds = %17, %11, %2, %8
  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, !7, i64 0}
!6 = !{!"_ZTS6Factor", !7, i64 0, !10, i64 8, !8, i64 12, !8, i64 104}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!7, !7, i64 0}
!13 = !{!10, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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