; LLVM IR from DionysiosB/CodeForces :: 0001-0099 (34A-Reconnaissance2)

; 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 [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 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 ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %10, i64 4)
  %12 = extractvalue { i64, i1 } %11, 1
  %13 = extractvalue { i64, i1 } %11, 0
  %14 = select i1 %12, i64 -1, i64 %13
  %15 = call noalias noundef nonnull ptr @_Znam(i64 noundef %14) #6
  store ptr %15, ptr %3, align 8, !tbaa !9
  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 = %27, %0
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %30

21:                                               ; preds = %16
  %22 = load ptr, ptr %3, align 8, !tbaa !9
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i32, ptr %22, i64 %24
  %26 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %25)
  br label %27

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

30:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %31 = load ptr, ptr %3, align 8, !tbaa !9
  %32 = getelementptr inbounds i32, ptr %31, i64 0
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = load ptr, ptr %3, align 8, !tbaa !9
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sub nsw i32 %35, 1
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i32, ptr %34, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = sub nsw i32 %33, %39
  %41 = call i32 @llvm.abs.i32(i32 %40, i1 true)
  store i32 %41, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = sub nsw i32 %42, 1
  store i32 %43, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %82, %30
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = sub nsw i32 %46, 1
  %48 = icmp slt i32 %45, %47
  br i1 %48, label %50, label %49

49:                                               ; preds = %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %85

50:                                               ; preds = %44
  %51 = load ptr, ptr %3, align 8, !tbaa !9
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i32, ptr %51, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = load ptr, ptr %3, align 8, !tbaa !9
  %57 = load i32, ptr %7, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i32, ptr %56, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = sub nsw i32 %55, %61
  %63 = call i32 @llvm.abs.i32(i32 %62, i1 true)
  %64 = load i32, ptr %5, align 4, !tbaa !5
  %65 = icmp slt i32 %63, %64
  br i1 %65, label %66, label %81

66:                                               ; preds = %50
  %67 = load ptr, ptr %3, align 8, !tbaa !9
  %68 = load i32, ptr %7, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds i32, ptr %67, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = load ptr, ptr %3, align 8, !tbaa !9
  %73 = load i32, ptr %7, align 4, !tbaa !5
  %74 = add nsw i32 %73, 1
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds i32, ptr %72, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !5
  %78 = sub nsw i32 %71, %77
  %79 = call i32 @llvm.abs.i32(i32 %78, i1 true)
  store i32 %79, ptr %5, align 4, !tbaa !5
  %80 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %80, ptr %6, align 4, !tbaa !5
  br label %81

81:                                               ; preds = %66, %50
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %7, align 4, !tbaa !5
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %7, align 4, !tbaa !5
  br label %44, !llvm.loop !13

85:                                               ; preds = %49
  %86 = load i32, ptr %6, align 4, !tbaa !5
  %87 = add nsw i32 1, %86
  %88 = load i32, ptr %6, align 4, !tbaa !5
  %89 = add nsw i32 %88, 1
  %90 = load i32, ptr %2, align 4, !tbaa !5
  %91 = srem i32 %89, %90
  %92 = add nsw i32 1, %91
  %93 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %87, i32 noundef %92)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #3

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #4

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #3

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

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 speculatable willreturn memory(none) }
attributes #4 = { nobuiltin allocsize(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 #5 = { nounwind }
attributes #6 = { builtin allocsize(0) }

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


; 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 [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress norecurse 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 = sext i32 %3 to i64
  %5 = icmp slt i32 %3, 0
  %6 = shl nsw i64 %4, 2
  %7 = select i1 %5, i64 -1, i64 %6
  %8 = call noalias noundef nonnull ptr @_Znam(i64 noundef %7) #7
  %9 = icmp sgt i32 %3, 0
  br i1 %9, label %.lr.ph, label %._crit_edge32

._crit_edge:                                      ; preds = %.lr.ph
  %10 = icmp sgt i32 %20, 1
  br i1 %10, label %.lr.ph31.preheader, label %._crit_edge32

.lr.ph31.preheader:                               ; preds = %._crit_edge
  %.pre = load i32, ptr %8, align 4, !tbaa !5
  %11 = add nsw i32 %20, -1
  %12 = zext nneg i32 %11 to i64
  %13 = getelementptr inbounds i32, ptr %8, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = sub nsw i32 %.pre, %14
  %16 = call i32 @llvm.abs.i32(i32 %15, i1 true)
  %xtraiter = and i64 %12, 1
  %17 = icmp eq i32 %11, 1
  br i1 %17, label %._crit_edge32.loopexit.unr-lcssa, label %.lr.ph31.preheader.new

.lr.ph31.preheader.new:                           ; preds = %.lr.ph31.preheader
  %unroll_iter = and i64 %12, 2147483646
  br label %.lr.ph31

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %18 = getelementptr inbounds i32, ptr %8, i64 %indvars.iv
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %18)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %20 = load i32, ptr %1, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = icmp slt i64 %indvars.iv.next, %21
  br i1 %22, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge32.loopexit.unr-lcssa:                 ; preds = %.lr.ph31, %.lr.ph31.preheader
  %spec.select25.lcssa.ph = phi i32 [ poison, %.lr.ph31.preheader ], [ %spec.select25.1, %.lr.ph31 ]
  %.unr = phi i32 [ %.pre, %.lr.ph31.preheader ], [ %42, %.lr.ph31 ]
  %indvars.iv36.unr = phi i64 [ 0, %.lr.ph31.preheader ], [ %indvars.iv.next37.1, %.lr.ph31 ]
  %.01928.unr = phi i32 [ %11, %.lr.ph31.preheader ], [ %spec.select25.1, %.lr.ph31 ]
  %.02027.unr = phi i32 [ %16, %.lr.ph31.preheader ], [ %spec.select.1, %.lr.ph31 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge32.loopexit, label %.lr.ph31.epil

.lr.ph31.epil:                                    ; preds = %._crit_edge32.loopexit.unr-lcssa
  %23 = getelementptr i32, ptr %8, i64 %indvars.iv36.unr
  %24 = getelementptr i8, ptr %23, i64 4
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = sub nsw i32 %.unr, %25
  %27 = call i32 @llvm.abs.i32(i32 %26, i1 true)
  %28 = icmp slt i32 %27, %.02027.unr
  %29 = trunc nuw nsw i64 %indvars.iv36.unr to i32
  %spec.select25.epil = select i1 %28, i32 %29, i32 %.01928.unr
  br label %._crit_edge32.loopexit

._crit_edge32.loopexit:                           ; preds = %._crit_edge32.loopexit.unr-lcssa, %.lr.ph31.epil
  %spec.select25.lcssa = phi i32 [ %spec.select25.lcssa.ph, %._crit_edge32.loopexit.unr-lcssa ], [ %spec.select25.epil, %.lr.ph31.epil ]
  %30 = add nsw i32 %spec.select25.lcssa, 1
  br label %._crit_edge32

._crit_edge32:                                    ; preds = %0, %._crit_edge32.loopexit, %._crit_edge
  %.lcssa40 = phi i32 [ %20, %._crit_edge ], [ %20, %._crit_edge32.loopexit ], [ %3, %0 ]
  %.019.lcssa = phi i32 [ %20, %._crit_edge ], [ %30, %._crit_edge32.loopexit ], [ %3, %0 ]
  %31 = srem i32 %.019.lcssa, %.lcssa40
  %32 = add nsw i32 %31, 1
  %33 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.019.lcssa, i32 noundef %32)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  ret i32 0

.lr.ph31:                                         ; preds = %.lr.ph31, %.lr.ph31.preheader.new
  %34 = phi i32 [ %.pre, %.lr.ph31.preheader.new ], [ %42, %.lr.ph31 ]
  %indvars.iv36 = phi i64 [ 0, %.lr.ph31.preheader.new ], [ %indvars.iv.next37.1, %.lr.ph31 ]
  %.01928 = phi i32 [ %11, %.lr.ph31.preheader.new ], [ %spec.select25.1, %.lr.ph31 ]
  %.02027 = phi i32 [ %16, %.lr.ph31.preheader.new ], [ %spec.select.1, %.lr.ph31 ]
  %niter = phi i64 [ 0, %.lr.ph31.preheader.new ], [ %niter.next.1, %.lr.ph31 ]
  %indvars.iv.next37 = or disjoint i64 %indvars.iv36, 1
  %35 = getelementptr inbounds i32, ptr %8, i64 %indvars.iv.next37
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sub nsw i32 %34, %36
  %38 = call i32 @llvm.abs.i32(i32 %37, i1 true)
  %39 = icmp slt i32 %38, %.02027
  %spec.select = call i32 @llvm.smin.i32(i32 %38, i32 %.02027)
  %40 = trunc nuw nsw i64 %indvars.iv36 to i32
  %spec.select25 = select i1 %39, i32 %40, i32 %.01928
  %indvars.iv.next37.1 = add nuw nsw i64 %indvars.iv36, 2
  %41 = getelementptr inbounds i32, ptr %8, i64 %indvars.iv.next37.1
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = sub nsw i32 %36, %42
  %44 = call i32 @llvm.abs.i32(i32 %43, i1 true)
  %45 = icmp slt i32 %44, %spec.select
  %spec.select.1 = call i32 @llvm.smin.i32(i32 %44, i32 %spec.select)
  %46 = trunc nuw nsw i64 %indvars.iv.next37 to i32
  %spec.select25.1 = select i1 %45, i32 %46, i32 %spec.select25
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge32.loopexit.unr-lcssa, label %.lr.ph31, !llvm.loop !11
}

; 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #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: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #4

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

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

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 = { 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 = { nobuiltin allocsize(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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { nounwind }
attributes #7 = { builtin allocsize(0) }

!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}


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