; LLVM IR from tangjz/acm-icpc :: self_training/2015-01-31 (B)

; 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
@t = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@lpos = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [7 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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %3

3:                                                ; preds = %70, %0
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @t, ptr noundef @c)
  %5 = icmp eq i32 %4, 3
  br i1 %5, label %6, label %73

6:                                                ; preds = %3
  store i32 0, ptr @ans, align 4, !tbaa !5
  store i32 0, ptr @lpos, align 4, !tbaa !5
  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 = %47, %6
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = load i32, ptr @n, 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 %50

12:                                               ; preds = %7
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @x)
  %14 = load i32, ptr @x, align 4, !tbaa !5
  %15 = load i32, ptr @t, align 4, !tbaa !5
  %16 = icmp sle i32 %14, %15
  br i1 %16, label %17, label %22

17:                                               ; preds = %12
  %18 = load i32, ptr @lpos, align 4, !tbaa !5
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %22, label %20

20:                                               ; preds = %17
  %21 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %21, ptr @lpos, align 4, !tbaa !5
  br label %46

22:                                               ; preds = %17, %12
  %23 = load i32, ptr @x, align 4, !tbaa !5
  %24 = load i32, ptr @t, align 4, !tbaa !5
  %25 = icmp sgt i32 %23, %24
  br i1 %25, label %26, label %45

26:                                               ; preds = %22
  %27 = load i32, ptr @lpos, align 4, !tbaa !5
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %45

29:                                               ; preds = %26
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = load i32, ptr @lpos, align 4, !tbaa !5
  %32 = sub nsw i32 %30, %31
  %33 = load i32, ptr @c, align 4, !tbaa !5
  %34 = icmp sge i32 %32, %33
  br i1 %34, label %35, label %44

35:                                               ; preds = %29
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = load i32, ptr @lpos, align 4, !tbaa !5
  %38 = sub nsw i32 %36, %37
  %39 = load i32, ptr @c, align 4, !tbaa !5
  %40 = sub nsw i32 %38, %39
  %41 = add nsw i32 %40, 1
  %42 = load i32, ptr @ans, align 4, !tbaa !5
  %43 = add nsw i32 %42, %41
  store i32 %43, ptr @ans, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %35, %29
  store i32 0, ptr @lpos, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %44, %26, %22
  br label %46

46:                                               ; preds = %45, %20
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !9

50:                                               ; preds = %11
  %51 = load i32, ptr @lpos, align 4, !tbaa !5
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %70

53:                                               ; preds = %50
  %54 = load i32, ptr @n, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  %56 = load i32, ptr @lpos, align 4, !tbaa !5
  %57 = sub nsw i32 %55, %56
  %58 = load i32, ptr @c, align 4, !tbaa !5
  %59 = icmp sge i32 %57, %58
  br i1 %59, label %60, label %70

60:                                               ; preds = %53
  %61 = load i32, ptr @n, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  %63 = load i32, ptr @lpos, align 4, !tbaa !5
  %64 = sub nsw i32 %62, %63
  %65 = load i32, ptr @c, align 4, !tbaa !5
  %66 = sub nsw i32 %64, %65
  %67 = add nsw i32 %66, 1
  %68 = load i32, ptr @ans, align 4, !tbaa !5
  %69 = add nsw i32 %68, %67
  store i32 %69, ptr @ans, align 4, !tbaa !5
  br label %70

70:                                               ; preds = %60, %53, %50
  %71 = load i32, ptr @ans, align 4, !tbaa !5
  %72 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %71)
  br label %3, !llvm.loop !11

73:                                               ; preds = %3
  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 @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}


; 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
@t = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@lpos = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [7 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

; 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 @n, ptr noundef nonnull @t, ptr noundef nonnull @c)
  %2 = icmp eq i32 %1, 3
  br i1 %2, label %.lr.ph23, label %._crit_edge24

.lr.ph23:                                         ; preds = %0, %31
  store i32 0, ptr @ans, align 4, !tbaa !5
  store i32 0, ptr @lpos, align 4, !tbaa !5
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %.not20 = icmp slt i32 %3, 1
  br i1 %.not20, label %._crit_edge._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %19
  %.not15 = icmp eq i32 %20, 0
  br i1 %.not15, label %._crit_edge._crit_edge, label %23

._crit_edge._crit_edge:                           ; preds = %.lr.ph23, %._crit_edge
  %.pre = load i32, ptr @ans, align 4, !tbaa !5
  br label %31

.lr.ph:                                           ; preds = %.lr.ph23, %19
  %.021 = phi i32 [ %21, %19 ], [ 1, %.lr.ph23 ]
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @x)
  %5 = load i32, ptr @x, align 4, !tbaa !5
  %6 = load i32, ptr @t, align 4, !tbaa !5
  %7 = icmp sgt i32 %5, %6
  %8 = load i32, ptr @lpos, align 4
  %9 = icmp ne i32 %8, 0
  %or.cond = select i1 %7, i1 true, i1 %9
  br i1 %or.cond, label %10, label %.sink.split

10:                                               ; preds = %.lr.ph
  %or.cond3 = select i1 %7, i1 %9, i1 false
  br i1 %or.cond3, label %11, label %19

11:                                               ; preds = %10
  %12 = sub nsw i32 %.021, %8
  %13 = load i32, ptr @c, align 4, !tbaa !5
  %.not17 = icmp slt i32 %12, %13
  br i1 %.not17, label %.sink.split, label %14

14:                                               ; preds = %11
  %15 = load i32, ptr @ans, align 4, !tbaa !5
  %16 = add i32 %12, 1
  %17 = sub i32 %16, %13
  %18 = add nsw i32 %17, %15
  store i32 %18, ptr @ans, align 4, !tbaa !5
  br label %.sink.split

.sink.split:                                      ; preds = %11, %14, %.lr.ph
  %.021.sink = phi i32 [ %.021, %.lr.ph ], [ 0, %14 ], [ 0, %11 ]
  store i32 %.021.sink, ptr @lpos, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %.sink.split, %10
  %20 = phi i32 [ %8, %10 ], [ %.021.sink, %.sink.split ]
  %21 = add nuw nsw i32 %.021, 1
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.021, %22
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9

23:                                               ; preds = %._crit_edge
  %24 = add nsw i32 %22, 1
  %25 = sub i32 %24, %20
  %26 = load i32, ptr @c, align 4, !tbaa !5
  %.not16 = icmp slt i32 %25, %26
  %.pre26 = load i32, ptr @ans, align 4, !tbaa !5
  br i1 %.not16, label %31, label %27

27:                                               ; preds = %23
  %28 = add i32 %25, 1
  %29 = sub i32 %28, %26
  %30 = add nsw i32 %29, %.pre26
  store i32 %30, ptr @ans, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %._crit_edge._crit_edge, %27, %23
  %32 = phi i32 [ %.pre, %._crit_edge._crit_edge ], [ %30, %27 ], [ %.pre26, %23 ]
  %33 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %32)
  %34 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @t, ptr noundef nonnull @c)
  %35 = icmp eq i32 %34, 3
  br i1 %35, label %.lr.ph23, label %._crit_edge24, !llvm.loop !11

._crit_edge24:                                    ; preds = %31, %0
  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 @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}


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