; LLVM IR from viveakrt/Competitive-programing :: CodeChef (MMAX_MinimumAndMaximum)

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @func() #2 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca [1000000 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 0, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 1000000, ptr %7) #4
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %1)
  %9 = getelementptr inbounds [1000000 x i8], ptr %7, i64 0, i64 0
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %9)
  store i64 0, ptr %6, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %28, %0
  %12 = load i64, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds [1000000 x i8], ptr %7, i64 0, i64 0
  %14 = call i64 @strlen(ptr noundef %13) #5
  %15 = icmp ult i64 %12, %14
  br i1 %15, label %16, label %31

16:                                               ; preds = %11
  %17 = load i64, ptr %3, align 8, !tbaa !5
  %18 = mul nsw i64 %17, 10
  %19 = load i64, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds [1000000 x i8], ptr %7, i64 0, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !9
  %22 = sext i8 %21 to i32
  %23 = sub nsw i32 %22, 48
  %24 = sext i32 %23 to i64
  %25 = add nsw i64 %18, %24
  %26 = load i64, ptr %1, align 8, !tbaa !5
  %27 = srem i64 %25, %26
  store i64 %27, ptr %3, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %16
  %29 = load i64, ptr %6, align 8, !tbaa !5
  %30 = add nsw i64 %29, 1
  store i64 %30, ptr %6, align 8, !tbaa !5
  br label %11, !llvm.loop !10

31:                                               ; preds = %11
  %32 = load i64, ptr %3, align 8, !tbaa !5
  %33 = icmp eq i64 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %31
  store i64 0, ptr %5, align 8, !tbaa !5
  br label %59

35:                                               ; preds = %31
  %36 = load i64, ptr %1, align 8, !tbaa !5
  %37 = load i64, ptr %3, align 8, !tbaa !5
  %38 = sub nsw i64 %36, %37
  store i64 %38, ptr %2, align 8, !tbaa !5
  %39 = load i64, ptr %2, align 8, !tbaa !5
  %40 = load i64, ptr %3, align 8, !tbaa !5
  %41 = icmp sgt i64 %39, %40
  br i1 %41, label %42, label %45

42:                                               ; preds = %35
  %43 = load i64, ptr %3, align 8, !tbaa !5
  %44 = mul nsw i64 %43, 2
  store i64 %44, ptr %5, align 8, !tbaa !5
  br label %58

45:                                               ; preds = %35
  %46 = load i64, ptr %2, align 8, !tbaa !5
  %47 = load i64, ptr %3, align 8, !tbaa !5
  %48 = icmp eq i64 %46, %47
  br i1 %48, label %49, label %54

49:                                               ; preds = %45
  %50 = load i64, ptr %3, align 8, !tbaa !5
  %51 = mul nsw i64 %50, 2
  store i64 %51, ptr %5, align 8, !tbaa !5
  %52 = load i64, ptr %5, align 8, !tbaa !5
  %53 = add nsw i64 %52, -1
  store i64 %53, ptr %5, align 8, !tbaa !5
  br label %57

54:                                               ; preds = %45
  %55 = load i64, ptr %2, align 8, !tbaa !5
  %56 = mul nsw i64 %55, 2
  store i64 %56, ptr %5, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %54, %49
  br label %58

58:                                               ; preds = %57, %42
  br label %59

59:                                               ; preds = %58, %34
  %60 = load i64, ptr %5, align 8, !tbaa !5
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %60)
  call void @llvm.lifetime.end.p0(i64 1000000, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret void
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 willreturn memory(read) "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 }
attributes #5 = { nounwind willreturn memory(read) }

!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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

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

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

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

; Function Attrs: nofree nounwind uwtable
define dso_local void @func() local_unnamed_addr #2 {
  %1 = alloca i64, align 8
  %2 = alloca [1000000 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 1000000, ptr nonnull %2) #4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %2)
  %5 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #5
  %.not = icmp eq i64 %5, 0
  br i1 %.not, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %0
  %6 = load i64, ptr %1, align 8, !tbaa !5
  %xtraiter = and i64 %5, 1
  %7 = icmp eq i64 %5, 1
  br i1 %7, label %._crit_edge.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %5, -2
  br label %8

8:                                                ; preds = %8, %.lr.ph.new
  %.019 = phi i64 [ 0, %.lr.ph.new ], [ %24, %8 ]
  %.01618 = phi i64 [ 0, %.lr.ph.new ], [ %23, %8 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %8 ]
  %9 = mul nsw i64 %.01618, 10
  %10 = getelementptr inbounds [1000000 x i8], ptr %2, i64 0, i64 %.019
  %11 = load i8, ptr %10, align 2, !tbaa !9
  %12 = sext i8 %11 to i64
  %13 = add i64 %9, -48
  %14 = add i64 %13, %12
  %15 = srem i64 %14, %6
  %16 = or disjoint i64 %.019, 1
  %17 = mul nsw i64 %15, 10
  %18 = getelementptr inbounds [1000000 x i8], ptr %2, i64 0, i64 %16
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %20 = sext i8 %19 to i64
  %21 = add i64 %17, -48
  %22 = add i64 %21, %20
  %23 = srem i64 %22, %6
  %24 = add nuw nsw i64 %.019, 2
  %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_edge.unr-lcssa.loopexit, label %8, !llvm.loop !10

._crit_edge.unr-lcssa.loopexit:                   ; preds = %8
  %25 = mul nsw i64 %23, 10
  %26 = add i64 %25, -48
  br label %._crit_edge.unr-lcssa

._crit_edge.unr-lcssa:                            ; preds = %._crit_edge.unr-lcssa.loopexit, %.lr.ph
  %.lcssa.ph = phi i64 [ poison, %.lr.ph ], [ %23, %._crit_edge.unr-lcssa.loopexit ]
  %.019.unr = phi i64 [ 0, %.lr.ph ], [ %24, %._crit_edge.unr-lcssa.loopexit ]
  %.01618.unr = phi i64 [ -48, %.lr.ph ], [ %26, %._crit_edge.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.epilog-lcssa

._crit_edge.epilog-lcssa:                         ; preds = %._crit_edge.unr-lcssa
  %27 = getelementptr inbounds [1000000 x i8], ptr %2, i64 0, i64 %.019.unr
  %28 = load i8, ptr %27, align 1, !tbaa !9
  %29 = sext i8 %28 to i64
  %30 = add i64 %.01618.unr, %29
  %31 = srem i64 %30, %6
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.unr-lcssa, %._crit_edge.epilog-lcssa
  %.lcssa = phi i64 [ %.lcssa.ph, %._crit_edge.unr-lcssa ], [ %31, %._crit_edge.epilog-lcssa ]
  %32 = icmp eq i64 %.lcssa, 0
  br i1 %32, label %._crit_edge.thread, label %33

33:                                               ; preds = %._crit_edge
  %34 = load i64, ptr %1, align 8, !tbaa !5
  %35 = sub nsw i64 %34, %.lcssa
  %36 = icmp sgt i64 %35, %.lcssa
  br i1 %36, label %37, label %39

37:                                               ; preds = %33
  %38 = shl nsw i64 %.lcssa, 1
  br label %._crit_edge.thread

39:                                               ; preds = %33
  %40 = icmp eq i64 %35, %.lcssa
  br i1 %40, label %41, label %44

41:                                               ; preds = %39
  %42 = shl nsw i64 %.lcssa, 1
  %43 = add nsw i64 %42, -1
  br label %._crit_edge.thread

44:                                               ; preds = %39
  %45 = shl nsw i64 %35, 1
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %0, %._crit_edge, %37, %44, %41
  %.015 = phi i64 [ %38, %37 ], [ %43, %41 ], [ %45, %44 ], [ 0, %._crit_edge ], [ 0, %0 ]
  %46 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %.015)
  call void @llvm.lifetime.end.p0(i64 1000000, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #3

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nofree 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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 }
attributes #5 = { nounwind willreturn memory(read) }

!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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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