; LLVM IR from UtkarshPathrabe/Competitive-Coding :: SPOJ Solutions (ACPC10D)

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

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %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
  %6 = alloca i32, align 4
  %7 = alloca [2 x [3 x i32]], align 16
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #3
  br label %10

10:                                               ; preds = %131, %0
  br label %11

11:                                               ; preds = %10
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %11
  br label %142

16:                                               ; preds = %11
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %4, ptr noundef %5, ptr noundef %6)
  %18 = getelementptr inbounds [2 x [3 x i32]], ptr %7, i64 0, i64 0
  %19 = getelementptr inbounds [3 x i32], ptr %18, i64 0, i64 0
  store i32 100000000, ptr %19, align 16, !tbaa !5
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = getelementptr inbounds [2 x [3 x i32]], ptr %7, i64 0, i64 0
  %22 = getelementptr inbounds [3 x i32], ptr %21, i64 0, i64 1
  store i32 %20, ptr %22, align 4, !tbaa !5
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = add nsw i32 %23, %24
  %26 = getelementptr inbounds [2 x [3 x i32]], ptr %7, i64 0, i64 0
  %27 = getelementptr inbounds [3 x i32], ptr %26, i64 0, i64 2
  store i32 %25, ptr %27, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 1, ptr %8, align 4, !tbaa !5
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %124, %16
  %29 = load i32, ptr %8, align 4, !tbaa !5
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %32, label %131

32:                                               ; preds = %28
  %33 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %4, ptr noundef %5, ptr noundef %6)
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = load i32, ptr %9, align 4, !tbaa !5
  %36 = icmp ne i32 %35, 0
  %37 = xor i1 %36, true
  %38 = zext i1 %37 to i32
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [2 x [3 x i32]], ptr %7, i64 0, i64 %39
  %41 = getelementptr inbounds [3 x i32], ptr %40, i64 0, i64 0
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = load i32, ptr %9, align 4, !tbaa !5
  %44 = icmp ne i32 %43, 0
  %45 = xor i1 %44, true
  %46 = zext i1 %45 to i32
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [2 x [3 x i32]], ptr %7, i64 0, i64 %47
  %49 = getelementptr inbounds [3 x i32], ptr %48, i64 0, i64 1
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = call i32 @min(i32 noundef %42, i32 noundef %50)
  %52 = add nsw i32 %34, %51
  %53 = load i32, ptr %9, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [2 x [3 x i32]], ptr %7, i64 0, i64 %54
  %56 = getelementptr inbounds [3 x i32], ptr %55, i64 0, i64 0
  store i32 %52, ptr %56, align 4, !tbaa !5
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = load i32, ptr %9, align 4, !tbaa !5
  %59 = icmp ne i32 %58, 0
  %60 = xor i1 %59, true
  %61 = zext i1 %60 to i32
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [2 x [3 x i32]], ptr %7, i64 0, i64 %62
  %64 = getelementptr inbounds [3 x i32], ptr %63, i64 0, i64 0
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = load i32, ptr %9, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [2 x [3 x i32]], ptr %7, i64 0, i64 %67
  %69 = getelementptr inbounds [3 x i32], ptr %68, i64 0, i64 0
  %70 = load i32, ptr %69, align 4, !tbaa !5
  %71 = call i32 @min(i32 noundef %65, i32 noundef %70)
  %72 = load i32, ptr %9, align 4, !tbaa !5
  %73 = icmp ne i32 %72, 0
  %74 = xor i1 %73, true
  %75 = zext i1 %74 to i32
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [2 x [3 x i32]], ptr %7, i64 0, i64 %76
  %78 = getelementptr inbounds [3 x i32], ptr %77, i64 0, i64 1
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = load i32, ptr %9, align 4, !tbaa !5
  %81 = icmp ne i32 %80, 0
  %82 = xor i1 %81, true
  %83 = zext i1 %82 to i32
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [2 x [3 x i32]], ptr %7, i64 0, i64 %84
  %86 = getelementptr inbounds [3 x i32], ptr %85, i64 0, i64 2
  %87 = load i32, ptr %86, align 4, !tbaa !5
  %88 = call i32 @min(i32 noundef %79, i32 noundef %87)
  %89 = call i32 @min(i32 noundef %71, i32 noundef %88)
  %90 = add nsw i32 %57, %89
  %91 = load i32, ptr %9, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [2 x [3 x i32]], ptr %7, i64 0, i64 %92
  %94 = getelementptr inbounds [3 x i32], ptr %93, i64 0, i64 1
  store i32 %90, ptr %94, align 4, !tbaa !5
  %95 = load i32, ptr %6, align 4, !tbaa !5
  %96 = load i32, ptr %9, align 4, !tbaa !5
  %97 = icmp ne i32 %96, 0
  %98 = xor i1 %97, true
  %99 = zext i1 %98 to i32
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [2 x [3 x i32]], ptr %7, i64 0, i64 %100
  %102 = getelementptr inbounds [3 x i32], ptr %101, i64 0, i64 2
  %103 = load i32, ptr %102, align 4, !tbaa !5
  %104 = load i32, ptr %9, align 4, !tbaa !5
  %105 = icmp ne i32 %104, 0
  %106 = xor i1 %105, true
  %107 = zext i1 %106 to i32
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds [2 x [3 x i32]], ptr %7, i64 0, i64 %108
  %110 = getelementptr inbounds [3 x i32], ptr %109, i64 0, i64 1
  %111 = load i32, ptr %110, align 4, !tbaa !5
  %112 = load i32, ptr %9, align 4, !tbaa !5
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds [2 x [3 x i32]], ptr %7, i64 0, i64 %113
  %115 = getelementptr inbounds [3 x i32], ptr %114, i64 0, i64 1
  %116 = load i32, ptr %115, align 4, !tbaa !5
  %117 = call i32 @min(i32 noundef %111, i32 noundef %116)
  %118 = call i32 @min(i32 noundef %103, i32 noundef %117)
  %119 = add nsw i32 %95, %118
  %120 = load i32, ptr %9, align 4, !tbaa !5
  %121 = sext i32 %120 to i64
  %122 = getelementptr inbounds [2 x [3 x i32]], ptr %7, i64 0, i64 %121
  %123 = getelementptr inbounds [3 x i32], ptr %122, i64 0, i64 2
  store i32 %119, ptr %123, align 4, !tbaa !5
  br label %124

124:                                              ; preds = %32
  %125 = load i32, ptr %8, align 4, !tbaa !5
  %126 = add nsw i32 %125, 1
  store i32 %126, ptr %8, align 4, !tbaa !5
  %127 = load i32, ptr %9, align 4, !tbaa !5
  %128 = icmp ne i32 %127, 0
  %129 = xor i1 %128, true
  %130 = zext i1 %129 to i32
  store i32 %130, ptr %9, align 4, !tbaa !5
  br label %28, !llvm.loop !9

131:                                              ; preds = %28
  %132 = load i32, ptr %2, align 4, !tbaa !5
  %133 = add nsw i32 %132, 1
  store i32 %133, ptr %2, align 4, !tbaa !5
  %134 = load i32, ptr %3, align 4, !tbaa !5
  %135 = sub nsw i32 %134, 1
  %136 = and i32 %135, 1
  %137 = sext i32 %136 to i64
  %138 = getelementptr inbounds [2 x [3 x i32]], ptr %7, i64 0, i64 %137
  %139 = getelementptr inbounds [3 x i32], ptr %138, i64 0, i64 1
  %140 = load i32, ptr %139, align 4, !tbaa !5
  %141 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %132, i32 noundef %140)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %10

142:                                              ; preds = %15
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  ret i32 0
}

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

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

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

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

attributes #0 = { 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 = { "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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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"

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca [2 x [3 x i32]], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #3
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %._crit_edge24, label %.lr.ph23

.lr.ph23:                                         ; preds = %0
  %9 = getelementptr inbounds i8, ptr %5, i64 4
  %10 = getelementptr inbounds i8, ptr %5, i64 8
  br label %11

11:                                               ; preds = %.lr.ph23, %._crit_edge
  %.01721 = phi i32 [ 1, %.lr.ph23 ], [ %46, %._crit_edge ]
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  store i32 100000000, ptr %5, align 16, !tbaa !5
  %13 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %13, ptr %9, align 4, !tbaa !5
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = add nsw i32 %14, %13
  store i32 %15, ptr %10, align 8, !tbaa !5
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = icmp sgt i32 %16, 1
  br i1 %17, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %11, %.lr.ph
  %.020 = phi i32 [ %20, %.lr.ph ], [ 1, %11 ]
  %.01619 = phi i32 [ %43, %.lr.ph ], [ 1, %11 ]
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = xor i32 %.020, 1
  %21 = zext nneg i32 %20 to i64
  %22 = getelementptr inbounds [2 x [3 x i32]], ptr %5, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %22, i64 4
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = call i32 @min(i32 noundef %23, i32 noundef %25)
  %27 = add nsw i32 %26, %19
  %28 = zext nneg i32 %.020 to i64
  %29 = getelementptr inbounds [2 x [3 x i32]], ptr %5, i64 0, i64 %28
  store i32 %27, ptr %29, align 4, !tbaa !5
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = call i32 @min(i32 noundef %23, i32 noundef %27)
  %32 = getelementptr inbounds i8, ptr %22, i64 8
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = call i32 @min(i32 noundef %25, i32 noundef %33)
  %35 = call i32 @min(i32 noundef %31, i32 noundef %34)
  %36 = add nsw i32 %35, %30
  %37 = getelementptr inbounds i8, ptr %29, i64 4
  store i32 %36, ptr %37, align 4, !tbaa !5
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = call i32 @min(i32 noundef %25, i32 noundef %36)
  %40 = call i32 @min(i32 noundef %33, i32 noundef %39)
  %41 = add nsw i32 %40, %38
  %42 = getelementptr inbounds i8, ptr %29, i64 8
  store i32 %41, ptr %42, align 4, !tbaa !5
  %43 = add nuw nsw i32 %.01619, 1
  %44 = load i32, ptr %1, align 4, !tbaa !5
  %45 = icmp slt i32 %43, %44
  br i1 %45, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %11
  %.lcssa = phi i32 [ %16, %11 ], [ %44, %.lr.ph ]
  %46 = add nuw nsw i32 %.01721, 1
  %47 = and i32 %.lcssa, 1
  %48 = xor i32 %47, 1
  %49 = zext nneg i32 %48 to i64
  %50 = getelementptr inbounds [2 x [3 x i32]], ptr %5, i64 0, i64 %49, i64 1
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.01721, i32 noundef %51)
  %53 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %54 = load i32, ptr %1, align 4, !tbaa !5
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %._crit_edge24, label %11

._crit_edge24:                                    ; preds = %._crit_edge, %0
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  ret i32 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: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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

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

attributes #0 = { 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 = { 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" }
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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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