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

; 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

; 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 noundef i64 @_Z3sumiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 0, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %12 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %12, ptr %8, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %56, %3
  %14 = load i32, ptr %8, align 4, !tbaa !5
  %15 = icmp sge i32 %14, 0
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %62

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

19:                                               ; preds = %49, %17
  %20 = load i32, ptr %10, align 4, !tbaa !5
  %21 = icmp sge i32 %20, 0
  br i1 %21, label %23, label %22

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

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

25:                                               ; preds = %42, %23
  %26 = load i32, ptr %11, align 4, !tbaa !5
  %27 = icmp sge i32 %26, 0
  br i1 %27, label %29, label %28

28:                                               ; preds = %25
  store i32 8, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %48

29:                                               ; preds = %25
  %30 = load i32, ptr %8, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [128 x [128 x [128 x i64]]], ptr @t, i64 0, i64 %31
  %33 = load i32, ptr %10, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [128 x [128 x i64]], ptr %32, i64 0, i64 %34
  %36 = load i32, ptr %11, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [128 x i64], ptr %35, i64 0, i64 %37
  %39 = load i64, ptr %38, align 8, !tbaa !9
  %40 = load i64, ptr %7, align 8, !tbaa !9
  %41 = add nsw i64 %40, %39
  store i64 %41, ptr %7, align 8, !tbaa !9
  br label %42

42:                                               ; preds = %29
  %43 = load i32, ptr %11, align 4, !tbaa !5
  %44 = load i32, ptr %11, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  %46 = and i32 %43, %45
  %47 = sub nsw i32 %46, 1
  store i32 %47, ptr %11, align 4, !tbaa !5
  br label %25, !llvm.loop !11

48:                                               ; preds = %28
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %10, align 4, !tbaa !5
  %51 = load i32, ptr %10, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  %53 = and i32 %50, %52
  %54 = sub nsw i32 %53, 1
  store i32 %54, ptr %10, align 4, !tbaa !5
  br label %19, !llvm.loop !13

55:                                               ; preds = %22
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %8, align 4, !tbaa !5
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  %60 = and i32 %57, %59
  %61 = sub nsw i32 %60, 1
  store i32 %61, ptr %8, align 4, !tbaa !5
  br label %13, !llvm.loop !14

62:                                               ; preds = %16
  %63 = load i64, ptr %7, align 8, !tbaa !9
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret i64 %63
}

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i64 @_Z3sumiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = or i32 %0, %1
  %5 = or i32 %4, %2
  %or.cond37 = icmp sgt i32 %5, -1
  br i1 %or.cond37, label %.preheader20.us.us, label %._crit_edge

.preheader20.us.us:                               ; preds = %3, %._crit_edge25.split.us.us.us
  %.01828.us.us = phi i32 [ %23, %._crit_edge25.split.us.us.us ], [ %0, %3 ]
  %.01927.us.us = phi i64 [ %12, %._crit_edge25.split.us.us.us ], [ 0, %3 ]
  %6 = zext nneg i32 %.01828.us.us to i64
  br label %.preheader.us.us.us

.preheader.us.us.us:                              ; preds = %._crit_edge.us.us.us, %.preheader20.us.us
  %.01724.us.us.us = phi i32 [ %1, %.preheader20.us.us ], [ %19, %._crit_edge.us.us.us ]
  %.123.us.us.us = phi i64 [ %.01927.us.us, %.preheader20.us.us ], [ %12, %._crit_edge.us.us.us ]
  %7 = zext nneg i32 %.01724.us.us.us to i64
  br label %8

8:                                                ; preds = %8, %.preheader.us.us.us
  %.022.us.us.us = phi i32 [ %2, %.preheader.us.us.us ], [ %15, %8 ]
  %.221.us.us.us = phi i64 [ %.123.us.us.us, %.preheader.us.us.us ], [ %12, %8 ]
  %9 = zext nneg i32 %.022.us.us.us to i64
  %10 = getelementptr inbounds [128 x [128 x [128 x i64]]], ptr @t, i64 0, i64 %6, i64 %7, i64 %9
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %12 = add nsw i64 %11, %.221.us.us.us
  %13 = add nuw nsw i32 %.022.us.us.us, 1
  %14 = and i32 %13, %.022.us.us.us
  %15 = add nsw i32 %14, -1
  %16 = icmp sgt i32 %14, 0
  br i1 %16, label %8, label %._crit_edge.us.us.us, !llvm.loop !9

._crit_edge.us.us.us:                             ; preds = %8
  %17 = add nuw nsw i32 %.01724.us.us.us, 1
  %18 = and i32 %17, %.01724.us.us.us
  %19 = add nsw i32 %18, -1
  %20 = icmp sgt i32 %18, 0
  br i1 %20, label %.preheader.us.us.us, label %._crit_edge25.split.us.us.us, !llvm.loop !11

._crit_edge25.split.us.us.us:                     ; preds = %._crit_edge.us.us.us
  %21 = add nuw nsw i32 %.01828.us.us, 1
  %22 = and i32 %21, %.01828.us.us
  %23 = add nsw i32 %22, -1
  %24 = icmp sgt i32 %22, 0
  br i1 %24, label %.preheader20.us.us, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %._crit_edge25.split.us.us.us, %3
  %.019.lcssa = phi i64 [ 0, %3 ], [ %12, %._crit_edge25.split.us.us.us ]
  ret i64 %.019.lcssa
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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