; LLVM IR from tangjz/acm-icpc :: TDL_training/2016-04-04/G - Surface Area of Cubes - dby.ll (Z3chkiiii)

; 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 i64, align 8
@B = external dso_local global i64, align 8
@C = external dso_local global i64, align 8
@x = external dso_local global [1009 x i32], align 16
@y = external dso_local global [1009 x i32], align 16
@z = external dso_local global [1009 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z3chkiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca i1, align 1
  %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
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !5
  %12 = load i32, ptr %7, align 4, !tbaa !5
  %13 = icmp sge i32 %12, 0
  br i1 %13, label %14, label %70

14:                                               ; preds = %4
  %15 = load i32, ptr %7, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = load i64, ptr @A, align 8, !tbaa !9
  %18 = icmp slt i64 %16, %17
  br i1 %18, label %19, label %70

19:                                               ; preds = %14
  %20 = load i32, ptr %8, align 4, !tbaa !5
  %21 = icmp sge i32 %20, 0
  br i1 %21, label %22, label %70

22:                                               ; preds = %19
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = load i64, ptr @B, align 8, !tbaa !9
  %26 = icmp slt i64 %24, %25
  br i1 %26, label %27, label %70

27:                                               ; preds = %22
  %28 = load i32, ptr %9, align 4, !tbaa !5
  %29 = icmp sge i32 %28, 0
  br i1 %29, label %30, label %70

30:                                               ; preds = %27
  %31 = load i32, ptr %9, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = load i64, ptr @C, align 8, !tbaa !9
  %34 = icmp slt i64 %32, %33
  br i1 %34, label %35, label %70

35:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %64, %35
  %37 = load i32, ptr %10, align 4, !tbaa !5
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  store i32 2, ptr %11, align 4
  br label %67

41:                                               ; preds = %36
  %42 = load i32, ptr %10, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [1009 x i32], ptr @x, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = icmp eq i32 %45, %46
  br i1 %47, label %48, label %63

48:                                               ; preds = %41
  %49 = load i32, ptr %10, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [1009 x i32], ptr @y, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = load i32, ptr %8, align 4, !tbaa !5
  %54 = icmp eq i32 %52, %53
  br i1 %54, label %55, label %63

55:                                               ; preds = %48
  %56 = load i32, ptr %10, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [1009 x i32], ptr @z, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = load i32, ptr %9, align 4, !tbaa !5
  %61 = icmp eq i32 %59, %60
  br i1 %61, label %62, label %63

62:                                               ; preds = %55
  store i1 false, ptr %5, align 1
  store i32 1, ptr %11, align 4
  br label %67

63:                                               ; preds = %55, %48, %41
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %10, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %10, align 4, !tbaa !5
  br label %36, !llvm.loop !11

67:                                               ; preds = %62, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %68 = load i32, ptr %11, align 4
  switch i32 %68, label %73 [
    i32 2, label %69
    i32 1, label %71
  ]

69:                                               ; preds = %67
  store i1 true, ptr %5, align 1
  br label %71

70:                                               ; preds = %30, %27, %22, %19, %14, %4
  store i1 false, ptr %5, align 1
  br label %71

71:                                               ; preds = %70, %69, %67
  %72 = load i1, ptr %5, align 1
  ret i1 %72

73:                                               ; preds = %67
  unreachable
}

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

@A = external dso_local local_unnamed_addr global i64, align 8
@B = external dso_local local_unnamed_addr global i64, align 8
@C = external dso_local local_unnamed_addr global i64, align 8
@x = external dso_local local_unnamed_addr global [1009 x i32], align 16
@y = external dso_local local_unnamed_addr global [1009 x i32], align 16
@z = external dso_local local_unnamed_addr global [1009 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z3chkiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp sgt i32 %1, -1
  br i1 %5, label %6, label %.loopexit

6:                                                ; preds = %4
  %7 = zext nneg i32 %1 to i64
  %8 = load i64, ptr @A, align 8, !tbaa !5
  %9 = icmp sgt i64 %8, %7
  %10 = icmp sgt i32 %2, -1
  %or.cond = and i1 %10, %9
  br i1 %or.cond, label %11, label %.loopexit

11:                                               ; preds = %6
  %12 = zext nneg i32 %2 to i64
  %13 = load i64, ptr @B, align 8, !tbaa !5
  %14 = icmp sgt i64 %13, %12
  %15 = icmp sgt i32 %3, -1
  %or.cond3 = and i1 %15, %14
  %16 = zext nneg i32 %3 to i64
  %17 = load i64, ptr @C, align 8
  %18 = icmp sgt i64 %17, %16
  %or.cond26 = select i1 %or.cond3, i1 %18, i1 false
  br i1 %or.cond26, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %11
  %19 = icmp slt i32 %0, 1
  br i1 %19, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %20 = zext nneg i32 %0 to i64
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %32
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %32 ]
  %21 = getelementptr inbounds [1009 x i32], ptr @x, i64 0, i64 %indvars.iv
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = icmp eq i32 %22, %1
  br i1 %23, label %24, label %32

24:                                               ; preds = %.lr.ph
  %25 = getelementptr inbounds [1009 x i32], ptr @y, i64 0, i64 %indvars.iv
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = icmp eq i32 %26, %2
  br i1 %27, label %28, label %32

28:                                               ; preds = %24
  %29 = getelementptr inbounds [1009 x i32], ptr @z, i64 0, i64 %indvars.iv
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = icmp eq i32 %30, %3
  br i1 %31, label %.loopexit, label %32

32:                                               ; preds = %.lr.ph, %24, %28
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond, label %.loopexit.loopexit.split.loop.exit, label %.lr.ph, !llvm.loop !11

.loopexit.loopexit.split.loop.exit:               ; preds = %32
  %33 = icmp uge i64 %indvars.iv.next, %20
  br label %.loopexit

.loopexit:                                        ; preds = %28, %.loopexit.loopexit.split.loop.exit, %.preheader, %4, %6, %11
  %.1 = phi i1 [ false, %11 ], [ false, %6 ], [ false, %4 ], [ true, %.preheader ], [ %33, %.loopexit.loopexit.split.loop.exit ], [ false, %28 ]
  ret i1 %.1
}

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


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass