; LLVM IR from tangjz/acm-icpc :: poj (1738)

; 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
@tmp = external dso_local global i32, align 4
@num = external dso_local global [100001 x i64], align 16
@ans = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 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
  store i32 0, ptr %1, align 4
  br label %4

4:                                                ; preds = %72, %0
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %6 = icmp eq i32 %5, 1
  br i1 %6, label %7, label %10

7:                                                ; preds = %4
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = icmp ne i32 %8, 0
  br label %10

10:                                               ; preds = %7, %4
  %11 = phi i1 [ false, %4 ], [ %9, %7 ]
  br i1 %11, label %12, label %75

12:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %23, %12
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %26

18:                                               ; preds = %13
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds i64, ptr @num, i64 %20
  %22 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %21)
  br label %23

23:                                               ; preds = %18
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %2, align 4, !tbaa !5
  br label %13, !llvm.loop !9

26:                                               ; preds = %17
  store i64 0, ptr @ans, align 8, !tbaa !11
  store i32 1, ptr @tmp, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %62, %26
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = load i32, ptr @n, align 4, !tbaa !5
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %32, label %31

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

32:                                               ; preds = %27
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [100001 x i64], ptr @num, i64 0, i64 %34
  %36 = load i64, ptr %35, align 8, !tbaa !11
  %37 = load i32, ptr @tmp, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr @tmp, align 4, !tbaa !5
  %39 = sext i32 %37 to i64
  %40 = getelementptr inbounds [100001 x i64], ptr @num, i64 0, i64 %39
  store i64 %36, ptr %40, align 8, !tbaa !11
  br label %41

41:                                               ; preds = %58, %32
  %42 = load i32, ptr @tmp, align 4, !tbaa !5
  %43 = icmp sge i32 %42, 3
  br i1 %43, label %44, label %56

44:                                               ; preds = %41
  %45 = load i32, ptr @tmp, align 4, !tbaa !5
  %46 = sub nsw i32 %45, 3
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [100001 x i64], ptr @num, i64 0, i64 %47
  %49 = load i64, ptr %48, align 8, !tbaa !11
  %50 = load i32, ptr @tmp, align 4, !tbaa !5
  %51 = sub nsw i32 %50, 1
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [100001 x i64], ptr @num, i64 0, i64 %52
  %54 = load i64, ptr %53, align 8, !tbaa !11
  %55 = icmp sle i64 %49, %54
  br label %56

56:                                               ; preds = %44, %41
  %57 = phi i1 [ false, %41 ], [ %55, %44 ]
  br i1 %57, label %58, label %61

58:                                               ; preds = %56
  %59 = load i32, ptr @tmp, align 4, !tbaa !5
  %60 = sub nsw i32 %59, 2
  call void @_Z3dfsi(i32 noundef %60)
  br label %41, !llvm.loop !13

61:                                               ; preds = %56
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %3, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %3, align 4, !tbaa !5
  br label %27, !llvm.loop !14

65:                                               ; preds = %31
  br label %66

66:                                               ; preds = %69, %65
  %67 = load i32, ptr @tmp, align 4, !tbaa !5
  %68 = icmp sgt i32 %67, 1
  br i1 %68, label %69, label %72

69:                                               ; preds = %66
  %70 = load i32, ptr @tmp, align 4, !tbaa !5
  %71 = sub nsw i32 %70, 1
  call void @_Z3dfsi(i32 noundef %71)
  br label %66, !llvm.loop !15

72:                                               ; preds = %66
  %73 = load i64, ptr @ans, align 8, !tbaa !11
  %74 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %73)
  br label %4, !llvm.loop !16

75:                                               ; preds = %10
  ret i32 0
}

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

@n = external dso_local global i32, align 4
@tmp = external dso_local local_unnamed_addr global i32, align 4
@num = external dso_local global [100001 x i64], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 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 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %2 = icmp eq i32 %1, 1
  %3 = load i32, ptr @n, align 4
  %4 = icmp ne i32 %3, 0
  %5 = select i1 %2, i1 %4, i1 false
  br i1 %5, label %.preheader9, label %._crit_edge19

.preheader9:                                      ; preds = %0, %._crit_edge18
  %6 = phi i32 [ %48, %._crit_edge18 ], [ %3, %0 ]
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %.preheader9
  store i64 0, ptr @ans, align 8, !tbaa !5
  store i32 1, ptr @tmp, align 4, !tbaa !9
  br label %._crit_edge18

._crit_edge:                                      ; preds = %.lr.ph
  store i64 0, ptr @ans, align 8, !tbaa !5
  store i32 1, ptr @tmp, align 4, !tbaa !9
  %8 = icmp sgt i32 %11, 1
  br i1 %8, label %.lr.ph16, label %._crit_edge18

.lr.ph:                                           ; preds = %.preheader9, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader9 ]
  %9 = getelementptr inbounds i64, ptr @num, i64 %indvars.iv
  %10 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, 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
  %13 = icmp slt i64 %indvars.iv.next, %12
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !11

.preheader:                                       ; preds = %.critedge
  %14 = icmp sgt i32 %37, 1
  br i1 %14, label %.lr.ph17, label %._crit_edge18

.lr.ph16:                                         ; preds = %._crit_edge, %.critedge
  %15 = phi i32 [ %36, %.critedge ], [ %11, %._crit_edge ]
  %16 = phi i32 [ %37, %.critedge ], [ 1, %._crit_edge ]
  %indvars.iv21 = phi i64 [ %indvars.iv.next22, %.critedge ], [ 1, %._crit_edge ]
  %17 = getelementptr inbounds [100001 x i64], ptr @num, i64 0, i64 %indvars.iv21
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %19 = add nsw i32 %16, 1
  store i32 %19, ptr @tmp, align 4, !tbaa !9
  %20 = sext i32 %16 to i64
  %21 = getelementptr inbounds [100001 x i64], ptr @num, i64 0, i64 %20
  store i64 %18, ptr %21, align 8, !tbaa !5
  %22 = icmp sgt i32 %16, 1
  br i1 %22, label %.lr.ph12, label %.critedge

.lr.ph12:                                         ; preds = %.lr.ph16, %32
  %23 = phi i32 [ %.pr, %32 ], [ %19, %.lr.ph16 ]
  %24 = add nsw i32 %23, -3
  %25 = zext nneg i32 %24 to i64
  %26 = getelementptr inbounds [100001 x i64], ptr @num, i64 0, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = add nsw i32 %23, -1
  %29 = zext nneg i32 %28 to i64
  %30 = getelementptr inbounds [100001 x i64], ptr @num, i64 0, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !5
  %.not = icmp sgt i64 %27, %31
  br i1 %.not, label %.critedge.loopexit, label %32

32:                                               ; preds = %.lr.ph12
  %33 = add nsw i32 %23, -2
  tail call void @_Z3dfsi(i32 noundef %33)
  %.pr = load i32, ptr @tmp, align 4, !tbaa !9
  %34 = icmp sgt i32 %.pr, 2
  br i1 %34, label %.lr.ph12, label %.critedge.loopexit, !llvm.loop !13

.critedge.loopexit:                               ; preds = %.lr.ph12, %32
  %35 = phi i32 [ %23, %.lr.ph12 ], [ %.pr, %32 ]
  %.pre = load i32, ptr @n, align 4, !tbaa !9
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %.lr.ph16
  %36 = phi i32 [ %.pre, %.critedge.loopexit ], [ %15, %.lr.ph16 ]
  %37 = phi i32 [ %35, %.critedge.loopexit ], [ %19, %.lr.ph16 ]
  %indvars.iv.next22 = add nuw nsw i64 %indvars.iv21, 1
  %38 = sext i32 %36 to i64
  %39 = icmp slt i64 %indvars.iv.next22, %38
  br i1 %39, label %.lr.ph16, label %.preheader, !llvm.loop !14

.lr.ph17:                                         ; preds = %.preheader, %.lr.ph17
  %40 = phi i32 [ %42, %.lr.ph17 ], [ %37, %.preheader ]
  %41 = add nsw i32 %40, -1
  tail call void @_Z3dfsi(i32 noundef %41)
  %42 = load i32, ptr @tmp, align 4, !tbaa !9
  %43 = icmp sgt i32 %42, 1
  br i1 %43, label %.lr.ph17, label %._crit_edge18, !llvm.loop !15

._crit_edge18:                                    ; preds = %.lr.ph17, %._crit_edge.thread, %._crit_edge, %.preheader
  %44 = load i64, ptr @ans, align 8, !tbaa !5
  %45 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %44)
  %46 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %47 = icmp eq i32 %46, 1
  %48 = load i32, ptr @n, align 4
  %49 = icmp ne i32 %48, 0
  %50 = select i1 %47, i1 %49, i1 false
  br i1 %50, label %.preheader9, label %._crit_edge19, !llvm.loop !16

._crit_edge19:                                    ; preds = %._crit_edge18, %0
  ret i32 0
}

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

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

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 = { 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 = !{!"long long", !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}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}


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