; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2012-13/Open 2013/13 Open G3.ll (Z6genlstv)

; 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
@lst = external dso_local global [300 x [300 x [300 x i16]]], align 16
@grid = external dso_local global [300 x [300 x i8]], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3getiii(i32 noundef, i32 noundef, i32 noundef) #0

; 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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6genlstv() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i16, align 2
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  %6 = load i32, ptr @N, align 4, !tbaa !5
  %7 = sub nsw i32 %6, 1
  store i32 %7, ptr %1, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %119, %0
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = icmp sge i32 %9, 0
  br i1 %10, label %12, label %11

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

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

13:                                               ; preds = %115, %12
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = load i32, ptr @N, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  store i32 5, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %118

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

21:                                               ; preds = %111, %18
  %22 = load i32, ptr %4, 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 8, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %114

26:                                               ; preds = %21
  %27 = load i32, ptr %1, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [300 x [300 x [300 x i16]]], ptr @lst, i64 0, i64 %28
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [300 x [300 x i16]], ptr %29, i64 0, i64 %31
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [300 x i16], ptr %32, i64 0, i64 %34
  store i16 -500, ptr %35, align 2, !tbaa !9
  %36 = load i32, ptr %1, align 4, !tbaa !5
  %37 = load i32, ptr @N, align 4, !tbaa !5
  %38 = sub nsw i32 %37, 1
  %39 = icmp slt i32 %36, %38
  br i1 %39, label %40, label %81

40:                                               ; preds = %26
  %41 = load i32, ptr %1, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [300 x [300 x i8]], ptr @grid, i64 0, i64 %42
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [300 x i8], ptr %43, i64 0, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !11
  %48 = sext i8 %47 to i32
  %49 = icmp eq i32 %48, 46
  br i1 %49, label %50, label %81

50:                                               ; preds = %40
  %51 = load i32, ptr %1, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [300 x [300 x i8]], ptr @grid, i64 0, i64 %52
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [300 x i8], ptr %53, i64 0, i64 %55
  %57 = load i8, ptr %56, align 1, !tbaa !11
  %58 = sext i8 %57 to i32
  %59 = icmp eq i32 %58, 46
  br i1 %59, label %60, label %81

60:                                               ; preds = %50
  %61 = load i32, ptr %1, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [300 x [300 x [300 x i16]]], ptr @lst, i64 0, i64 %63
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [300 x [300 x i16]], ptr %64, i64 0, i64 %66
  %68 = load i32, ptr %4, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [300 x i16], ptr %67, i64 0, i64 %69
  %71 = load i16, ptr %70, align 2, !tbaa !9
  %72 = load i32, ptr %1, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [300 x [300 x [300 x i16]]], ptr @lst, i64 0, i64 %73
  %75 = load i32, ptr %3, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [300 x [300 x i16]], ptr %74, i64 0, i64 %76
  %78 = load i32, ptr %4, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [300 x i16], ptr %77, i64 0, i64 %79
  store i16 %71, ptr %80, align 2, !tbaa !9
  br label %81

81:                                               ; preds = %60, %50, %40, %26
  %82 = load i32, ptr %1, align 4, !tbaa !5
  %83 = load i32, ptr %3, align 4, !tbaa !5
  %84 = load i32, ptr %4, align 4, !tbaa !5
  %85 = call noundef i32 @_Z3getiii(i32 noundef %82, i32 noundef %83, i32 noundef %84)
  %86 = icmp eq i32 %85, 0
  br i1 %86, label %87, label %110

87:                                               ; preds = %81
  %88 = load i32, ptr %1, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [300 x [300 x [300 x i16]]], ptr @lst, i64 0, i64 %89
  %91 = load i32, ptr %3, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [300 x [300 x i16]], ptr %90, i64 0, i64 %92
  %94 = load i32, ptr %4, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [300 x i16], ptr %93, i64 0, i64 %95
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #4
  %97 = load i32, ptr %1, align 4, !tbaa !5
  %98 = trunc i32 %97 to i16
  store i16 %98, ptr %5, align 2, !tbaa !9
  %99 = call noundef nonnull align 2 dereferenceable(2) ptr @_ZSt3maxIsERKT_S2_S2_(ptr noundef nonnull align 2 dereferenceable(2) %96, ptr noundef nonnull align 2 dereferenceable(2) %5)
  %100 = load i16, ptr %99, align 2, !tbaa !9
  %101 = load i32, ptr %1, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [300 x [300 x [300 x i16]]], ptr @lst, i64 0, i64 %102
  %104 = load i32, ptr %3, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [300 x [300 x i16]], ptr %103, i64 0, i64 %105
  %107 = load i32, ptr %4, align 4, !tbaa !5
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds [300 x i16], ptr %106, i64 0, i64 %108
  store i16 %100, ptr %109, align 2, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #4
  br label %110

110:                                              ; preds = %87, %81
  br label %111

111:                                              ; preds = %110
  %112 = load i32, ptr %4, align 4, !tbaa !5
  %113 = add nsw i32 %112, 1
  store i32 %113, ptr %4, align 4, !tbaa !5
  br label %21, !llvm.loop !12

114:                                              ; preds = %25
  br label %115

115:                                              ; preds = %114
  %116 = load i32, ptr %3, align 4, !tbaa !5
  %117 = add nsw i32 %116, 1
  store i32 %117, ptr %3, align 4, !tbaa !5
  br label %13, !llvm.loop !14

118:                                              ; preds = %17
  br label %119

119:                                              ; preds = %118
  %120 = load i32, ptr %1, align 4, !tbaa !5
  %121 = add nsw i32 %120, -1
  store i32 %121, ptr %1, align 4, !tbaa !5
  br label %8, !llvm.loop !15

122:                                              ; preds = %11
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 2 dereferenceable(2) ptr @_ZSt3maxIsERKT_S2_S2_(ptr noundef nonnull align 2 dereferenceable(2), ptr noundef nonnull align 2 dereferenceable(2)) #3

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 = { 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 #3 = { inlinehint 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 #4 = { 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 = !{!"short", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


; 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
@lst = external dso_local global [300 x [300 x [300 x i16]]], align 16
@grid = external dso_local local_unnamed_addr global [300 x [300 x i8]], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3getiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6genlstv() local_unnamed_addr #0 {
  %1 = alloca i16, align 2
  %2 = load i32, ptr @N, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.preheader.preheader, label %._crit_edge

.preheader.preheader:                             ; preds = %0
  %.03237 = add nsw i32 %2, -1
  %4 = zext nneg i32 %.03237 to i64
  %5 = zext nneg i32 %2 to i64
  br label %.preheader

.loopexit33:                                      ; preds = %.loopexit, %.preheader
  %6 = phi i32 [ %9, %.preheader ], [ %15, %.loopexit ]
  %7 = phi i32 [ %10, %.preheader ], [ %15, %.loopexit ]
  %indvars.iv.next48 = add nsw i64 %indvars.iv47, -1
  %8 = icmp sgt i64 %indvars.iv47, 0
  %indvars.iv.next50 = add nsw i64 %indvars.iv49, -1
  br i1 %8, label %.preheader, label %._crit_edge, !llvm.loop !9

.preheader:                                       ; preds = %.preheader.preheader, %.loopexit33
  %9 = phi i32 [ %2, %.preheader.preheader ], [ %6, %.loopexit33 ]
  %10 = phi i32 [ %2, %.preheader.preheader ], [ %7, %.loopexit33 ]
  %indvars.iv49 = phi i64 [ %5, %.preheader.preheader ], [ %indvars.iv.next50, %.loopexit33 ]
  %indvars.iv47 = phi i64 [ %4, %.preheader.preheader ], [ %indvars.iv.next48, %.loopexit33 ]
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.lr.ph36, label %.loopexit33

.lr.ph36:                                         ; preds = %.preheader
  %12 = trunc nuw nsw i64 %indvars.iv47 to i32
  %13 = trunc i64 %indvars.iv47 to i16
  %14 = trunc nuw i64 %indvars.iv49 to i32
  br label %18

._crit_edge:                                      ; preds = %.loopexit33, %0
  ret void

.loopexit:                                        ; preds = %46, %18
  %15 = phi i32 [ %19, %18 ], [ %47, %46 ]
  %16 = sext i32 %15 to i64
  %17 = icmp slt i64 %indvars.iv.next45, %16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br i1 %17, label %18, label %.loopexit33, !llvm.loop !12

18:                                               ; preds = %.lr.ph36, %.loopexit
  %19 = phi i32 [ %9, %.lr.ph36 ], [ %15, %.loopexit ]
  %20 = phi i32 [ %10, %.lr.ph36 ], [ %15, %.loopexit ]
  %indvars.iv44 = phi i64 [ 0, %.lr.ph36 ], [ %indvars.iv.next45, %.loopexit ]
  %indvars.iv = phi i64 [ 1, %.lr.ph36 ], [ %indvars.iv.next, %.loopexit ]
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, 1
  %21 = sext i32 %20 to i64
  %22 = icmp slt i64 %indvars.iv.next45, %21
  br i1 %22, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %18
  %23 = getelementptr inbounds [300 x [300 x i8]], ptr @grid, i64 0, i64 %indvars.iv47, i64 %indvars.iv44
  %24 = trunc nuw nsw i64 %indvars.iv44 to i32
  br label %25

25:                                               ; preds = %.lr.ph, %46
  %indvars.iv41 = phi i64 [ %indvars.iv, %.lr.ph ], [ %indvars.iv.next42, %46 ]
  %26 = phi i32 [ %20, %.lr.ph ], [ %47, %46 ]
  %27 = getelementptr inbounds [300 x [300 x [300 x i16]]], ptr @lst, i64 0, i64 %indvars.iv47, i64 %indvars.iv44, i64 %indvars.iv41
  store i16 -500, ptr %27, align 2, !tbaa !13
  %28 = icmp sgt i32 %26, %14
  br i1 %28, label %29, label %39

29:                                               ; preds = %25
  %30 = load i8, ptr %23, align 1, !tbaa !15
  %31 = icmp eq i8 %30, 46
  br i1 %31, label %32, label %39

32:                                               ; preds = %29
  %33 = getelementptr inbounds [300 x [300 x i8]], ptr @grid, i64 0, i64 %indvars.iv47, i64 %indvars.iv41
  %34 = load i8, ptr %33, align 1, !tbaa !15
  %35 = icmp eq i8 %34, 46
  br i1 %35, label %36, label %39

36:                                               ; preds = %32
  %37 = getelementptr inbounds [300 x [300 x [300 x i16]]], ptr @lst, i64 0, i64 %indvars.iv49, i64 %indvars.iv44, i64 %indvars.iv41
  %38 = load i16, ptr %37, align 2, !tbaa !13
  store i16 %38, ptr %27, align 2, !tbaa !13
  br label %39

39:                                               ; preds = %36, %32, %29, %25
  %40 = trunc nuw nsw i64 %indvars.iv41 to i32
  %41 = call noundef i32 @_Z3getiii(i32 noundef %12, i32 noundef %24, i32 noundef %40)
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %46

43:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %1) #3
  store i16 %13, ptr %1, align 2, !tbaa !13
  %44 = call noundef nonnull align 2 dereferenceable(2) ptr @_ZSt3maxIsERKT_S2_S2_(ptr noundef nonnull align 2 dereferenceable(2) %27, ptr noundef nonnull align 2 dereferenceable(2) %1)
  %45 = load i16, ptr %44, align 2, !tbaa !13
  store i16 %45, ptr %27, align 2, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %1) #3
  br label %46

46:                                               ; preds = %39, %43
  %indvars.iv.next42 = add nuw nsw i64 %indvars.iv41, 1
  %47 = load i32, ptr @N, align 4, !tbaa !5
  %48 = trunc nuw i64 %indvars.iv.next42 to i32
  %49 = icmp sgt i32 %47, %48
  br i1 %49, label %25, label %.loopexit, !llvm.loop !16
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 2 dereferenceable(2) ptr @_ZSt3maxIsERKT_S2_S2_(ptr noundef nonnull align 2 dereferenceable(2), ptr noundef nonnull align 2 dereferenceable(2)) local_unnamed_addr #2

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #3 = { 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 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.unswitch.partial.disable"}
!12 = distinct !{!12, !10}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !10}


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