; LLVM IR from tangjz/acm-icpc :: usaco/Training/Chapter 1 Getting started (wormhole)

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

@n = external dso_local global i32, align 4
@x = external dso_local global [13 x i32], align 16
@y = external dso_local global [13 x i32], align 16
@nxt = external dso_local global [13 x i32], align 16
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [12 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsi(i32 noundef) #0

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %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 = load ptr, ptr @stdin, align 8, !tbaa !5
  %7 = call ptr @freopen(ptr noundef @.str, ptr noundef @.str.1, ptr noundef %6)
  %8 = load ptr, ptr @stdout, align 8, !tbaa !5
  %9 = call ptr @freopen(ptr noundef @.str.2, ptr noundef @.str.3, ptr noundef %8)
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.4, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %24, %0
  %12 = load i32, ptr %2, align 4, !tbaa !9
  %13 = load i32, ptr @n, align 4, !tbaa !9
  %14 = icmp sle i32 %12, %13
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %11
  %17 = load i32, ptr %2, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds i32, ptr @x, i64 %18
  %20 = load i32, ptr %2, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i32, ptr @y, i64 %21
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.5, ptr noundef %19, ptr noundef %22)
  br label %24

24:                                               ; preds = %16
  %25 = load i32, ptr %2, align 4, !tbaa !9
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %2, align 4, !tbaa !9
  br label %11, !llvm.loop !11

27:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 1, ptr %3, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %88, %27
  %29 = load i32, ptr %3, align 4, !tbaa !9
  %30 = load i32, ptr @n, align 4, !tbaa !9
  %31 = icmp sle i32 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %91

33:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %84, %33
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = load i32, ptr @n, align 4, !tbaa !9
  %37 = icmp sle i32 %35, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %34
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %87

39:                                               ; preds = %34
  %40 = load i32, ptr %3, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [13 x i32], ptr @x, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [13 x i32], ptr @x, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !9
  %48 = icmp slt i32 %43, %47
  br i1 %48, label %49, label %83

49:                                               ; preds = %39
  %50 = load i32, ptr %3, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [13 x i32], ptr @y, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = load i32, ptr %5, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [13 x i32], ptr @y, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = icmp eq i32 %53, %57
  br i1 %58, label %59, label %83

59:                                               ; preds = %49
  %60 = load i32, ptr %3, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [13 x i32], ptr @nxt, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !9
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %78

65:                                               ; preds = %59
  %66 = load i32, ptr %5, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [13 x i32], ptr @x, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !9
  %70 = load i32, ptr %3, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [13 x i32], ptr @nxt, i64 0, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !9
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [13 x i32], ptr @x, i64 0, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !9
  %77 = icmp slt i32 %69, %76
  br i1 %77, label %78, label %83

78:                                               ; preds = %65, %59
  %79 = load i32, ptr %5, align 4, !tbaa !9
  %80 = load i32, ptr %3, align 4, !tbaa !9
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [13 x i32], ptr @nxt, i64 0, i64 %81
  store i32 %79, ptr %82, align 4, !tbaa !9
  br label %83

83:                                               ; preds = %78, %65, %49, %39
  br label %84

84:                                               ; preds = %83
  %85 = load i32, ptr %5, align 4, !tbaa !9
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %5, align 4, !tbaa !9
  br label %34, !llvm.loop !13

87:                                               ; preds = %38
  br label %88

88:                                               ; preds = %87
  %89 = load i32, ptr %3, align 4, !tbaa !9
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %3, align 4, !tbaa !9
  br label %28, !llvm.loop !14

91:                                               ; preds = %32
  call void @_Z3dfsi(i32 noundef 0)
  %92 = load i32, ptr @ans, align 4, !tbaa !9
  %93 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i32 noundef %92)
  ret i32 0
}

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) #3

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

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

attributes #0 = { mustprogress 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 = { 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 #3 = { "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 }

!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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !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"

@n = external dso_local global i32, align 4
@x = external dso_local global [13 x i32], align 16
@y = external dso_local global [13 x i32], align 16
@nxt = external dso_local local_unnamed_addr global [13 x i32], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [12 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = load ptr, ptr @stdin, align 8, !tbaa !5
  %2 = tail call ptr @freopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef %1)
  %3 = load ptr, ptr @stdout, align 8, !tbaa !5
  %4 = tail call ptr @freopen(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.3, ptr noundef %3)
  %5 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull @n)
  %6 = load i32, ptr @n, align 4, !tbaa !9
  %.not25 = icmp slt i32 %6, 1
  br i1 %.not25, label %._crit_edge32, label %.lr.ph

.preheader24:                                     ; preds = %.lr.ph
  %.not2130 = icmp slt i32 %11, 1
  br i1 %.not2130, label %._crit_edge32, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.preheader24
  %7 = add nuw i32 %11, 1
  %wide.trip.count41 = zext i32 %7 to i64
  br label %.preheader

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %8 = getelementptr inbounds i32, ptr @x, i64 %indvars.iv
  %9 = getelementptr inbounds i32, ptr @y, i64 %indvars.iv
  %10 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.5, ptr noundef nonnull %8, ptr noundef nonnull %9)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %11 = load i32, ptr @n, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %.not.not = icmp slt i64 %indvars.iv, %12
  br i1 %.not.not, label %.lr.ph, label %.preheader24, !llvm.loop !11

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge
  %indvars.iv38 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next39, %._crit_edge ]
  %13 = getelementptr inbounds [13 x i32], ptr @x, i64 0, i64 %indvars.iv38
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = getelementptr inbounds [13 x i32], ptr @y, i64 0, i64 %indvars.iv38
  %16 = getelementptr inbounds [13 x i32], ptr @nxt, i64 0, i64 %indvars.iv38
  br label %19

._crit_edge32:                                    ; preds = %._crit_edge, %0, %.preheader24
  tail call void @_Z3dfsi(i32 noundef 0)
  %17 = load i32, ptr @ans, align 4, !tbaa !9
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef %17)
  ret i32 0

._crit_edge:                                      ; preds = %37
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 1
  %exitcond42.not = icmp eq i64 %indvars.iv.next39, %wide.trip.count41
  br i1 %exitcond42.not, label %._crit_edge32, label %.preheader, !llvm.loop !13

19:                                               ; preds = %.preheader, %37
  %indvars.iv35 = phi i64 [ 1, %.preheader ], [ %indvars.iv.next36, %37 ]
  %20 = getelementptr inbounds [13 x i32], ptr @x, i64 0, i64 %indvars.iv35
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = icmp slt i32 %14, %21
  br i1 %22, label %23, label %37

23:                                               ; preds = %19
  %24 = load i32, ptr %15, align 4, !tbaa !9
  %25 = getelementptr inbounds [13 x i32], ptr @y, i64 0, i64 %indvars.iv35
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = icmp eq i32 %24, %26
  br i1 %27, label %28, label %37

28:                                               ; preds = %23
  %29 = load i32, ptr %16, align 4, !tbaa !9
  %.not23 = icmp eq i32 %29, 0
  br i1 %.not23, label %35, label %30

30:                                               ; preds = %28
  %31 = sext i32 %29 to i64
  %32 = getelementptr inbounds [13 x i32], ptr @x, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !9
  %34 = icmp slt i32 %21, %33
  br i1 %34, label %35, label %37

35:                                               ; preds = %30, %28
  %36 = trunc nuw nsw i64 %indvars.iv35 to i32
  store i32 %36, ptr %16, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %19, %23, %30, %35
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next36, %wide.trip.count41
  br i1 %exitcond.not, label %._crit_edge, label %19, !llvm.loop !14
}

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

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

attributes #0 = { mustprogress 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 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 #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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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