; LLVM IR from tangjz/acm-icpc :: codeforces/complete (4B)

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

@d = external dso_local global i32, align 4
@sum = external dso_local global i32, align 4
@min = external dso_local global [40 x i32], align 16
@max = external dso_local global [40 x i32], align 16
@.str = external hidden unnamed_addr constant [5 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 [4 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
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @d, ptr noundef @sum)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %32, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = load i32, ptr @d, align 4, !tbaa !5
  %10 = icmp sle i32 %8, %9
  br i1 %10, label %12, label %11

11:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %35

12:                                               ; preds = %7
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i32, ptr @min, i64 %14
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i32, ptr @max, i64 %17
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %15, ptr noundef %18)
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [40 x i32], ptr @min, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = load i32, ptr @min, align 16, !tbaa !5
  %25 = add nsw i32 %24, %23
  store i32 %25, ptr @min, align 16, !tbaa !5
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [40 x i32], ptr @max, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = load i32, ptr @max, align 16, !tbaa !5
  %31 = add nsw i32 %30, %29
  store i32 %31, ptr @max, align 16, !tbaa !5
  br label %32

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

35:                                               ; preds = %11
  %36 = load i32, ptr @sum, align 4, !tbaa !5
  %37 = load i32, ptr @min, align 16, !tbaa !5
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %43, label %39

39:                                               ; preds = %35
  %40 = load i32, ptr @max, align 16, !tbaa !5
  %41 = load i32, ptr @sum, align 4, !tbaa !5
  %42 = icmp slt i32 %40, %41
  br i1 %42, label %43, label %45

43:                                               ; preds = %39, %35
  %44 = call i32 @puts(ptr noundef @.str.1)
  br label %114

45:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %93, %45
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = load i32, ptr @d, align 4, !tbaa !5
  %49 = icmp sle i32 %47, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %46
  store i32 5, ptr %4, align 4
  br label %96

51:                                               ; preds = %46
  %52 = load i32, ptr @min, align 16, !tbaa !5
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [40 x i32], ptr @max, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = add nsw i32 %52, %56
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [40 x i32], ptr @min, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = sub nsw i32 %57, %61
  %63 = load i32, ptr @sum, align 4, !tbaa !5
  %64 = icmp sge i32 %62, %63
  br i1 %64, label %65, label %74

65:                                               ; preds = %51
  %66 = load i32, ptr @sum, align 4, !tbaa !5
  %67 = load i32, ptr @min, align 16, !tbaa !5
  %68 = sub nsw i32 %66, %67
  %69 = load i32, ptr %3, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [40 x i32], ptr @min, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = add nsw i32 %72, %68
  store i32 %73, ptr %71, align 4, !tbaa !5
  store i32 5, ptr %4, align 4
  br label %96

74:                                               ; preds = %51
  %75 = load i32, ptr %3, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [40 x i32], ptr @max, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !5
  %79 = load i32, ptr %3, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [40 x i32], ptr @min, i64 0, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = sub nsw i32 %78, %82
  %84 = load i32, ptr @min, align 16, !tbaa !5
  %85 = add nsw i32 %84, %83
  store i32 %85, ptr @min, align 16, !tbaa !5
  %86 = load i32, ptr %3, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [40 x i32], ptr @max, i64 0, i64 %87
  %89 = load i32, ptr %88, align 4, !tbaa !5
  %90 = load i32, ptr %3, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [40 x i32], ptr @min, i64 0, i64 %91
  store i32 %89, ptr %92, align 4, !tbaa !5
  br label %93

93:                                               ; preds = %74
  %94 = load i32, ptr %3, align 4, !tbaa !5
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %3, align 4, !tbaa !5
  br label %46, !llvm.loop !11

96:                                               ; preds = %65, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %97

97:                                               ; preds = %96
  %98 = call i32 @puts(ptr noundef @.str.2)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %99

99:                                               ; preds = %110, %97
  %100 = load i32, ptr %5, align 4, !tbaa !5
  %101 = load i32, ptr @d, align 4, !tbaa !5
  %102 = icmp sle i32 %100, %101
  br i1 %102, label %104, label %103

103:                                              ; preds = %99
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %113

104:                                              ; preds = %99
  %105 = load i32, ptr %5, align 4, !tbaa !5
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [40 x i32], ptr @min, i64 0, i64 %106
  %108 = load i32, ptr %107, align 4, !tbaa !5
  %109 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %108)
  br label %110

110:                                              ; preds = %104
  %111 = load i32, ptr %5, align 4, !tbaa !5
  %112 = add nsw i32 %111, 1
  store i32 %112, ptr %5, align 4, !tbaa !5
  br label %99, !llvm.loop !12

113:                                              ; preds = %103
  br label %114

114:                                              ; preds = %113, %43
  ret i32 0
}

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

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

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

declare i32 @puts(ptr noundef) #1

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

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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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++ 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"

@d = external dso_local global i32, align 4
@sum = external dso_local global i32, align 4
@min = external dso_local global [40 x i32], align 16
@max = external dso_local global [40 x i32], align 16
@.str = external hidden unnamed_addr constant [5 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 [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @d, ptr noundef nonnull @sum)
  %2 = load i32, ptr @d, align 4, !tbaa !5
  %.not31 = icmp slt i32 %2, 1
  br i1 %.not31, label %.._crit_edge_crit_edge, label %.lr.ph

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre = load i32, ptr @min, align 16, !tbaa !5
  %.pre53 = load i32, ptr @max, align 16
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %3 = phi i32 [ %.pre53, %.._crit_edge_crit_edge ], [ %16, %.lr.ph ]
  %min.promoted = phi i32 [ %.pre, %.._crit_edge_crit_edge ], [ %13, %.lr.ph ]
  %.lcssa30 = phi i32 [ %2, %.._crit_edge_crit_edge ], [ %17, %.lr.ph ]
  %4 = load i32, ptr @sum, align 4, !tbaa !5
  %5 = icmp slt i32 %4, %min.promoted
  %6 = icmp slt i32 %3, %4
  %or.cond = select i1 %5, i1 true, i1 %6
  br i1 %or.cond, label %19, label %.preheader

.preheader:                                       ; preds = %._crit_edge
  %.not2233 = icmp slt i32 %.lcssa30, 1
  br i1 %.not2233, label %.loopexit27, label %.lr.ph35.preheader

.lr.ph35.preheader:                               ; preds = %.preheader
  %7 = add nuw i32 %.lcssa30, 1
  %wide.trip.count = zext i32 %7 to i64
  br label %.lr.ph35

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %8 = getelementptr inbounds i32, ptr @min, i64 %indvars.iv
  %9 = getelementptr inbounds i32, ptr @max, i64 %indvars.iv
  %10 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %8, ptr noundef nonnull %9)
  %11 = load i32, ptr %8, align 4, !tbaa !5
  %12 = load i32, ptr @min, align 16, !tbaa !5
  %13 = add nsw i32 %12, %11
  store i32 %13, ptr @min, align 16, !tbaa !5
  %14 = load i32, ptr %9, align 4, !tbaa !5
  %15 = load i32, ptr @max, align 16, !tbaa !5
  %16 = add nsw i32 %15, %14
  store i32 %16, ptr @max, align 16, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = load i32, ptr @d, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %.not.not = icmp slt i64 %indvars.iv, %18
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9

19:                                               ; preds = %._crit_edge
  %20 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %.loopexit

.lr.ph35:                                         ; preds = %.lr.ph35.preheader, %31
  %indvars.iv47 = phi i64 [ 1, %.lr.ph35.preheader ], [ %indvars.iv.next48, %31 ]
  %21 = phi i32 [ %min.promoted, %.lr.ph35.preheader ], [ %27, %31 ]
  %22 = getelementptr inbounds [40 x i32], ptr @max, i64 0, i64 %indvars.iv47
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = add nsw i32 %23, %21
  %25 = getelementptr inbounds [40 x i32], ptr @min, i64 0, i64 %indvars.iv47
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = sub i32 %24, %26
  %.not23 = icmp slt i32 %27, %4
  br i1 %.not23, label %31, label %28

28:                                               ; preds = %.lr.ph35
  %29 = sub i32 %4, %21
  %30 = add nsw i32 %29, %26
  store i32 %30, ptr %25, align 4, !tbaa !5
  br label %.loopexit27

31:                                               ; preds = %.lr.ph35
  store i32 %27, ptr @min, align 16, !tbaa !5
  store i32 %23, ptr %25, align 4, !tbaa !5
  %indvars.iv.next48 = add nuw nsw i64 %indvars.iv47, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next48, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit27, label %.lr.ph35, !llvm.loop !11

.loopexit27:                                      ; preds = %31, %.preheader, %28
  %32 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.2)
  %33 = load i32, ptr @d, align 4, !tbaa !5
  %.not2436 = icmp slt i32 %33, 1
  br i1 %.not2436, label %.loopexit, label %.lr.ph39

.lr.ph39:                                         ; preds = %.loopexit27, %.lr.ph39
  %indvars.iv50 = phi i64 [ %indvars.iv.next51, %.lr.ph39 ], [ 1, %.loopexit27 ]
  %34 = getelementptr inbounds [40 x i32], ptr @min, i64 0, i64 %indvars.iv50
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %35)
  %indvars.iv.next51 = add nuw nsw i64 %indvars.iv50, 1
  %37 = load i32, ptr @d, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %.not24.not = icmp slt i64 %indvars.iv50, %38
  br i1 %.not24.not, label %.lr.ph39, label %.loopexit, !llvm.loop !12

.loopexit:                                        ; preds = %.lr.ph39, %.loopexit27, %19
  ret i32 0
}

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

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

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

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


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