; LLVM IR from Izaron/ACM-ICPC :: Timus Online Judge/Volume 5/1470. UFOs.ll (Z3inciiii)

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

@t = external dso_local global [128 x [128 x [128 x i64]]], align 16
@n = external dso_local global i32, align 4

; 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 nounwind uwtable
define dso_local void @_Z3inciiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca i32, align 4
  %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 i32, align 4
  %12 = 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %13 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %13, ptr %9, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %59, %4
  %15 = load i32, ptr %9, align 4, !tbaa !5
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %64

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %20 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %20, ptr %11, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %53, %19
  %22 = load i32, ptr %11, align 4, !tbaa !5
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %58

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %27 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %27, ptr %12, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %47, %26
  %29 = load i32, ptr %12, align 4, !tbaa !5
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  store i32 8, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  br label %52

33:                                               ; preds = %28
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = load i32, ptr %9, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [128 x [128 x [128 x i64]]], ptr @t, i64 0, i64 %37
  %39 = load i32, ptr %11, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [128 x [128 x i64]], ptr %38, i64 0, i64 %40
  %42 = load i32, ptr %12, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [128 x i64], ptr %41, i64 0, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !9
  %46 = add nsw i64 %45, %35
  store i64 %46, ptr %44, align 8, !tbaa !9
  br label %47

47:                                               ; preds = %33
  %48 = load i32, ptr %12, align 4, !tbaa !5
  %49 = load i32, ptr %12, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  %51 = or i32 %48, %50
  store i32 %51, ptr %12, align 4, !tbaa !5
  br label %28, !llvm.loop !11

52:                                               ; preds = %32
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %11, align 4, !tbaa !5
  %55 = load i32, ptr %11, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  %57 = or i32 %54, %56
  store i32 %57, ptr %11, align 4, !tbaa !5
  br label %21, !llvm.loop !13

58:                                               ; preds = %25
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %9, align 4, !tbaa !5
  %61 = load i32, ptr %9, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  %63 = or i32 %60, %62
  store i32 %63, ptr %9, align 4, !tbaa !5
  br label %14, !llvm.loop !14

64:                                               ; preds = %18
  ret void
}

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


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

@t = external dso_local local_unnamed_addr global [128 x [128 x [128 x i64]]], align 16
@n = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3inciiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, %0
  br i1 %6, label %.preheader18.lr.ph, label %._crit_edge

.preheader18.lr.ph:                               ; preds = %4
  %7 = icmp sgt i32 %5, %1
  %8 = sext i32 %3 to i64
  %9 = icmp sgt i32 %5, %2
  %or.cond = and i1 %7, %9
  br i1 %or.cond, label %.preheader18.us.us, label %._crit_edge

.preheader18.us.us:                               ; preds = %.preheader18.lr.ph, %._crit_edge21.split.us.us.us
  %.01722.us.us = phi i32 [ %24, %._crit_edge21.split.us.us.us ], [ %0, %.preheader18.lr.ph ]
  %10 = sext i32 %.01722.us.us to i64
  br label %.preheader.us.us.us

.preheader.us.us.us:                              ; preds = %._crit_edge.us.us.us, %.preheader18.us.us
  %.01620.us.us.us = phi i32 [ %1, %.preheader18.us.us ], [ %21, %._crit_edge.us.us.us ]
  %11 = sext i32 %.01620.us.us.us to i64
  br label %12

12:                                               ; preds = %12, %.preheader.us.us.us
  %.019.us.us.us = phi i32 [ %2, %.preheader.us.us.us ], [ %18, %12 ]
  %13 = sext i32 %.019.us.us.us to i64
  %14 = getelementptr inbounds [128 x [128 x [128 x i64]]], ptr @t, i64 0, i64 %10, i64 %11, i64 %13
  %15 = load i64, ptr %14, align 8, !tbaa !9
  %16 = add nsw i64 %15, %8
  store i64 %16, ptr %14, align 8, !tbaa !9
  %17 = add nsw i32 %.019.us.us.us, 1
  %18 = or i32 %17, %.019.us.us.us
  %19 = icmp slt i32 %18, %5
  br i1 %19, label %12, label %._crit_edge.us.us.us, !llvm.loop !11

._crit_edge.us.us.us:                             ; preds = %12
  %20 = add nsw i32 %.01620.us.us.us, 1
  %21 = or i32 %20, %.01620.us.us.us
  %22 = icmp slt i32 %21, %5
  br i1 %22, label %.preheader.us.us.us, label %._crit_edge21.split.us.us.us, !llvm.loop !13

._crit_edge21.split.us.us.us:                     ; preds = %._crit_edge.us.us.us
  %23 = add nsw i32 %.01722.us.us, 1
  %24 = or i32 %23, %.01722.us.us
  %25 = icmp slt i32 %24, %5
  br i1 %25, label %.preheader18.us.us, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %._crit_edge21.split.us.us.us, %.preheader18.lr.ph, %4
  ret void
}

attributes #0 = { mustprogress nofree norecurse 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"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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