; LLVM IR from brpapa/algorithms :: solutions/uva (116)

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

@m = external dso_local global [10 x [100 x i32]], align 16
@tab = external dso_local global [10 x [100 x i32]], align 16
@ans = external dso_local global [100 x i32], align 16
@qteLIN = external dso_local global i32, align 4
@qteCOL = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4dpBUii(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
declare dso_local void @_Z7recoverv() #2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %6

6:                                                ; preds = %55, %0
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @qteLIN, ptr noundef @qteCOL)
  %8 = icmp ne i32 %7, -1
  br i1 %8, label %9, label %68

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

10:                                               ; preds = %33, %9
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = load i32, ptr @qteLIN, align 4, !tbaa !5
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %15, label %14

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

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

16:                                               ; preds = %29, %15
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = load i32, ptr @qteCOL, align 4, !tbaa !5
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 7, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %32

21:                                               ; preds = %16
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [10 x [100 x i32]], ptr @m, i64 0, i64 %23
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [100 x i32], ptr %24, i64 0, i64 %26
  %28 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %27)
  br label %29

29:                                               ; preds = %21
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %4, align 4, !tbaa !5
  br label %16, !llvm.loop !9

32:                                               ; preds = %20
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %2, align 4, !tbaa !5
  br label %10, !llvm.loop !11

36:                                               ; preds = %14
  %37 = load i32, ptr @qteLIN, align 4, !tbaa !5
  %38 = load i32, ptr @qteCOL, align 4, !tbaa !5
  call void @_Z4dpBUii(i32 noundef %37, i32 noundef %38)
  call void @_Z7recoverv()
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %52, %36
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = load i32, ptr @qteCOL, align 4, !tbaa !5
  %42 = sub nsw i32 %41, 1
  %43 = icmp slt i32 %40, %42
  br i1 %43, label %45, label %44

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

45:                                               ; preds = %39
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [100 x i32], ptr @ans, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  %51 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %50)
  br label %52

52:                                               ; preds = %45
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %5, align 4, !tbaa !5
  br label %39, !llvm.loop !12

55:                                               ; preds = %44
  %56 = load i32, ptr @qteCOL, align 4, !tbaa !5
  %57 = sub nsw i32 %56, 1
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [100 x i32], ptr @ans, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  %62 = load i32, ptr @ans, align 16, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [10 x [100 x i32]], ptr @tab, i64 0, i64 %63
  %65 = getelementptr inbounds [100 x i32], ptr %64, i64 0, i64 0
  %66 = load i32, ptr %65, align 16, !tbaa !5
  %67 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %61, i32 noundef %66)
  br label %6, !llvm.loop !13

68:                                               ; preds = %6
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #4

declare i32 @printf(ptr noundef, ...) #4

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 = { mustprogress norecurse 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 = { "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 #5 = { 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}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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

@m = external dso_local global [10 x [100 x i32]], align 16
@tab = external dso_local local_unnamed_addr global [10 x [100 x i32]], align 16
@ans = external dso_local local_unnamed_addr global [100 x i32], align 16
@qteLIN = external dso_local global i32, align 4
@qteCOL = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7recoverv() local_unnamed_addr #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @qteLIN, ptr noundef nonnull @qteCOL)
  %.not23 = icmp eq i32 %1, -1
  br i1 %.not23, label %._crit_edge24, label %.preheader13

.preheader13:                                     ; preds = %0, %._crit_edge21
  %2 = load i32, ptr @qteLIN, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  %.pre35 = load i32, ptr @qteCOL, align 4, !tbaa !5
  %4 = icmp sgt i32 %.pre35, 0
  %or.cond = select i1 %3, i1 %4, i1 false
  br i1 %or.cond, label %.preheader, label %._crit_edge17

.preheader:                                       ; preds = %.preheader13, %._crit_edge
  %5 = phi i32 [ %12, %._crit_edge ], [ %2, %.preheader13 ]
  %6 = phi i32 [ %13, %._crit_edge ], [ %.pre35, %.preheader13 ]
  %indvars.iv29 = phi i64 [ %indvars.iv.next30, %._crit_edge ], [ 0, %.preheader13 ]
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

._crit_edge17:                                    ; preds = %._crit_edge, %.preheader13
  %8 = phi i32 [ %.pre35, %.preheader13 ], [ %13, %._crit_edge ]
  %.lcssa = phi i32 [ %2, %.preheader13 ], [ %12, %._crit_edge ]
  tail call void @_Z4dpBUii(i32 noundef %.lcssa, i32 noundef %8)
  tail call void @_Z7recoverv()
  %9 = load i32, ptr @qteCOL, align 4, !tbaa !5
  %10 = icmp sgt i32 %9, 1
  br i1 %10, label %.lr.ph20, label %._crit_edge17.._crit_edge21_crit_edge

._crit_edge17.._crit_edge21_crit_edge:            ; preds = %._crit_edge17
  %11 = add nsw i32 %9, -1
  %.pre36 = sext i32 %11 to i64
  br label %._crit_edge21

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr @qteLIN, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %12 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %5, %.preheader ]
  %13 = phi i32 [ %18, %._crit_edge.loopexit ], [ %6, %.preheader ]
  %indvars.iv.next30 = add nuw nsw i64 %indvars.iv29, 1
  %14 = sext i32 %12 to i64
  %15 = icmp slt i64 %indvars.iv.next30, %14
  br i1 %15, label %.preheader, label %._crit_edge17, !llvm.loop !9

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader ]
  %16 = getelementptr inbounds [10 x [100 x i32]], ptr @m, i64 0, i64 %indvars.iv29, i64 %indvars.iv
  %17 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %16)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %18 = load i32, ptr @qteCOL, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = icmp slt i64 %indvars.iv.next, %19
  br i1 %20, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !12

._crit_edge21:                                    ; preds = %.lr.ph20, %._crit_edge17.._crit_edge21_crit_edge
  %.pre-phi = phi i64 [ %.pre36, %._crit_edge17.._crit_edge21_crit_edge ], [ %36, %.lr.ph20 ]
  %21 = getelementptr inbounds [100 x i32], ptr @ans, i64 0, i64 %.pre-phi
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  %24 = load i32, ptr @ans, align 16, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [10 x [100 x i32]], ptr @tab, i64 0, i64 %25
  %27 = load i32, ptr %26, align 16, !tbaa !5
  %28 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %23, i32 noundef %27)
  %29 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @qteLIN, ptr noundef nonnull @qteCOL)
  %.not = icmp eq i32 %29, -1
  br i1 %.not, label %._crit_edge24, label %.preheader13, !llvm.loop !13

.lr.ph20:                                         ; preds = %._crit_edge17, %.lr.ph20
  %indvars.iv32 = phi i64 [ %indvars.iv.next33, %.lr.ph20 ], [ 0, %._crit_edge17 ]
  %30 = getelementptr inbounds [100 x i32], ptr @ans, i64 0, i64 %indvars.iv32
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  %33 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %32)
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
  %34 = load i32, ptr @qteCOL, align 4, !tbaa !5
  %35 = add nsw i32 %34, -1
  %36 = sext i32 %35 to i64
  %37 = icmp slt i64 %indvars.iv.next33, %36
  br i1 %37, label %.lr.ph20, label %._crit_edge21, !llvm.loop !14

._crit_edge24:                                    ; preds = %._crit_edge21, %0
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { 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 = { mustprogress norecurse 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 = { nofree nounwind "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 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.unswitch.partial.disable"}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


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