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

; 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 [10 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef 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 ptr, align 8
  %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
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = zext i32 %15 to i64
  %17 = call ptr @llvm.stacksave.p0()
  store ptr %17, ptr %6, align 8
  %18 = alloca i32, i64 %16, align 16
  store i64 %16, ptr %7, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %29, %0
  %20 = load i32, ptr %8, align 4, !tbaa !5
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %32

24:                                               ; preds = %19
  %25 = load i32, ptr %8, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i32, ptr %18, i64 %26
  %28 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %27)
  br label %29

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

32:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 -1, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %78, %32
  %34 = load i32, ptr %11, align 4, !tbaa !5
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %81

38:                                               ; preds = %33
  %39 = load i32, ptr %11, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds i32, ptr %18, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  store i32 %42, ptr %10, align 4, !tbaa !5
  %43 = load i32, ptr %11, align 4, !tbaa !5
  store i32 %43, ptr %5, align 4, !tbaa !5
  %44 = load i32, ptr %9, align 4, !tbaa !5
  %45 = load i32, ptr %10, align 4, !tbaa !5
  %46 = icmp slt i32 %44, %45
  br i1 %46, label %47, label %51

47:                                               ; preds = %38
  %48 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %48, ptr %9, align 4, !tbaa !5
  %49 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %49, ptr %3, align 4, !tbaa !5
  %50 = load i32, ptr %11, align 4, !tbaa !5
  store i32 %50, ptr %4, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %47, %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %52 = load i32, ptr %11, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %13, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %74, %51
  %55 = load i32, ptr %13, align 4, !tbaa !5
  %56 = load i32, ptr %2, align 4, !tbaa !5
  %57 = icmp slt i32 %55, %56
  br i1 %57, label %59, label %58

58:                                               ; preds = %54
  store i32 8, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %77

59:                                               ; preds = %54
  %60 = load i32, ptr %10, align 4, !tbaa !5
  %61 = load i32, ptr %13, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds i32, ptr %18, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = xor i32 %60, %64
  store i32 %65, ptr %10, align 4, !tbaa !5
  %66 = load i32, ptr %9, align 4, !tbaa !5
  %67 = load i32, ptr %10, align 4, !tbaa !5
  %68 = icmp slt i32 %66, %67
  br i1 %68, label %69, label %73

69:                                               ; preds = %59
  %70 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %70, ptr %9, align 4, !tbaa !5
  %71 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %71, ptr %3, align 4, !tbaa !5
  %72 = load i32, ptr %13, align 4, !tbaa !5
  store i32 %72, ptr %4, align 4, !tbaa !5
  br label %73

73:                                               ; preds = %69, %59
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %13, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %13, align 4, !tbaa !5
  br label %54, !llvm.loop !11

77:                                               ; preds = %58
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %11, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %11, align 4, !tbaa !5
  br label %33, !llvm.loop !12

81:                                               ; preds = %37
  %82 = load i32, ptr %9, align 4, !tbaa !5
  %83 = load i32, ptr %3, align 4, !tbaa !5
  %84 = add nsw i32 %83, 1
  %85 = load i32, ptr %4, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  %87 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %82, i32 noundef %84, i32 noundef %86)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %88 = load ptr, ptr %6, align 8
  call void @llvm.stackrestore.p0(ptr %88)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %89 = load i32, ptr %1, align 4
  ret i32 %89
}

; 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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

attributes #0 = { 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 #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 = { nocallback nofree nosync nounwind willreturn }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !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"

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

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = zext i32 %3 to i64
  %5 = call ptr @llvm.stacksave.p0()
  %6 = alloca i32, i64 %4, align 16
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = icmp sgt i32 %7, 0
  call void @llvm.assume(i1 %8)
  br label %.lr.ph

.preheader:                                       ; preds = %.lr.ph
  %9 = icmp sgt i32 %13, 0
  call void @llvm.assume(i1 %9)
  %10 = zext nneg i32 %13 to i64
  %wide.trip.count68 = zext nneg i32 %13 to i64
  br label %.lr.ph54

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %11 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %11)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = icmp slt i64 %indvars.iv.next, %14
  br i1 %15, label %.lr.ph, label %.preheader, !llvm.loop !9

.loopexit:                                        ; preds = %.lr.ph46, %.lr.ph54
  %.236.lcssa = phi i32 [ %.135, %.lr.ph54 ], [ %.337, %.lr.ph46 ]
  %.232.lcssa = phi i32 [ %.131, %.lr.ph54 ], [ %.333, %.lr.ph46 ]
  %.2.lcssa = phi i32 [ %.1, %.lr.ph54 ], [ %.3, %.lr.ph46 ]
  %indvars.iv.next61 = add nuw nsw i64 %indvars.iv60, 1
  %exitcond69.not = icmp eq i64 %indvars.iv.next66, %wide.trip.count68
  br i1 %exitcond69.not, label %._crit_edge.loopexit, label %.lr.ph54, !llvm.loop !11

._crit_edge.loopexit:                             ; preds = %.loopexit
  %16 = add nsw i32 %.232.lcssa, 1
  %17 = add nsw i32 %.236.lcssa, 1
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.2.lcssa, i32 noundef %16, i32 noundef %17)
  call void @llvm.stackrestore.p0(ptr %5)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  ret i32 0

.lr.ph54:                                         ; preds = %.preheader, %.loopexit
  %indvars.iv65 = phi i64 [ 0, %.preheader ], [ %indvars.iv.next66, %.loopexit ]
  %indvars.iv60 = phi i64 [ 1, %.preheader ], [ %indvars.iv.next61, %.loopexit ]
  %.02852 = phi i32 [ -1, %.preheader ], [ %.2.lcssa, %.loopexit ]
  %.03051 = phi i32 [ undef, %.preheader ], [ %.232.lcssa, %.loopexit ]
  %.03450 = phi i32 [ undef, %.preheader ], [ %.236.lcssa, %.loopexit ]
  %19 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv65
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = icmp slt i32 %.02852, %20
  %22 = trunc nuw nsw i64 %indvars.iv65 to i32
  %.135 = select i1 %21, i32 %22, i32 %.03450
  %.131 = select i1 %21, i32 %22, i32 %.03051
  %.1 = call i32 @llvm.smax.i32(i32 %.02852, i32 %20)
  %indvars.iv.next66 = add nuw nsw i64 %indvars.iv65, 1
  %23 = icmp ult i64 %indvars.iv.next66, %10
  br i1 %23, label %.lr.ph46, label %.loopexit

.lr.ph46:                                         ; preds = %.lr.ph54, %.lr.ph46
  %indvars.iv62 = phi i64 [ %indvars.iv.next63, %.lr.ph46 ], [ %indvars.iv60, %.lr.ph54 ]
  %.02744 = phi i32 [ %26, %.lr.ph46 ], [ %20, %.lr.ph54 ]
  %.243 = phi i32 [ %.3, %.lr.ph46 ], [ %.1, %.lr.ph54 ]
  %.23242 = phi i32 [ %.333, %.lr.ph46 ], [ %.131, %.lr.ph54 ]
  %.23641 = phi i32 [ %.337, %.lr.ph46 ], [ %.135, %.lr.ph54 ]
  %24 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv62
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = xor i32 %25, %.02744
  %27 = icmp slt i32 %.243, %26
  %28 = trunc nuw nsw i64 %indvars.iv62 to i32
  %.337 = select i1 %27, i32 %28, i32 %.23641
  %.333 = select i1 %27, i32 %22, i32 %.23242
  %.3 = call i32 @llvm.smax.i32(i32 %.243, i32 %26)
  %indvars.iv.next63 = add nuw nsw i64 %indvars.iv62, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next63, %wide.trip.count68
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph46, !llvm.loop !12
}

; 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: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)
declare void @llvm.assume(i1 noundef) #5

attributes #0 = { mustprogress nofree norecurse 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 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }
attributes #6 = { 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}


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