; LLVM IR from tangjz/acm-icpc :: self_training/2014-12-26 (H)

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

@t = external dso_local global i32, align 4
@top = external dso_local global i32, align 4
@str = external dso_local global [233333 x i8], align 16
@sta = external dso_local global [233333 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 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
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %5

5:                                                ; preds = %80, %0
  %6 = load i32, ptr @t, align 4, !tbaa !5
  %7 = add nsw i32 %6, -1
  store i32 %7, ptr @t, align 4, !tbaa !5
  %8 = icmp ne i32 %6, 0
  br i1 %8, label %9, label %81

9:                                                ; preds = %5
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @str)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  %11 = call i64 @strlen(ptr noundef @str) #5
  %12 = trunc i64 %11 to i32
  store i32 %12, ptr %2, align 4, !tbaa !5
  store i32 -1, ptr @top, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %66, %9
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = load i32, ptr %2, 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 %3) #4
  br label %69

18:                                               ; preds = %13
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [233333 x i8], ptr @str, i64 0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %23 = load i32, ptr @top, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr @top, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [233333 x i8], ptr @sta, i64 0, i64 %25
  store i8 %22, ptr %26, align 1, !tbaa !9
  br label %27

27:                                               ; preds = %62, %18
  %28 = load i32, ptr @top, align 4, !tbaa !5
  %29 = icmp sgt i32 %28, 0
  br i1 %29, label %30, label %60

30:                                               ; preds = %27
  %31 = load i32, ptr @top, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [233333 x i8], ptr @sta, i64 0, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !9
  %35 = sext i8 %34 to i32
  %36 = load i32, ptr @top, align 4, !tbaa !5
  %37 = sub nsw i32 %36, 1
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [233333 x i8], ptr @sta, i64 0, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !9
  %41 = sext i8 %40 to i32
  %42 = icmp ne i32 %35, %41
  br i1 %42, label %43, label %60

43:                                               ; preds = %30
  %44 = load i32, ptr @top, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [233333 x i8], ptr @sta, i64 0, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !9
  %48 = sext i8 %47 to i32
  %49 = sub nsw i32 %48, 97
  %50 = ashr i32 %49, 1
  %51 = load i32, ptr @top, align 4, !tbaa !5
  %52 = sub nsw i32 %51, 1
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [233333 x i8], ptr @sta, i64 0, i64 %53
  %55 = load i8, ptr %54, align 1, !tbaa !9
  %56 = sext i8 %55 to i32
  %57 = sub nsw i32 %56, 97
  %58 = ashr i32 %57, 1
  %59 = icmp eq i32 %50, %58
  br label %60

60:                                               ; preds = %43, %30, %27
  %61 = phi i1 [ false, %30 ], [ false, %27 ], [ %59, %43 ]
  br i1 %61, label %62, label %65

62:                                               ; preds = %60
  %63 = load i32, ptr @top, align 4, !tbaa !5
  %64 = sub nsw i32 %63, 2
  store i32 %64, ptr @top, align 4, !tbaa !5
  br label %27, !llvm.loop !10

65:                                               ; preds = %60
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %3, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %3, align 4, !tbaa !5
  br label %13, !llvm.loop !12

69:                                               ; preds = %17
  %70 = load i32, ptr @top, align 4, !tbaa !5
  %71 = icmp slt i32 %70, 0
  br i1 %71, label %72, label %74

72:                                               ; preds = %69
  %73 = call i32 @puts(ptr noundef @.str.2)
  br label %80

74:                                               ; preds = %69
  %75 = load i32, ptr @top, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr @top, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [233333 x i8], ptr @sta, i64 0, i64 %77
  store i8 0, ptr %78, align 1, !tbaa !9
  %79 = call i32 @puts(ptr noundef @sta)
  br label %80

80:                                               ; preds = %74, %72
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %5, !llvm.loop !13

81:                                               ; preds = %5
  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: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

; 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

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


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

@t = external dso_local global i32, align 4
@top = external dso_local local_unnamed_addr global i32, align 4
@str = external dso_local global [233333 x i8], align 16
@sta = external dso_local global [233333 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 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 @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not21 = icmp eq i32 %2, 0
  br i1 %.not21, label %._crit_edge24, label %.lr.ph23

.lr.ph23:                                         ; preds = %0, %.thread
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @str)
  %5 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @str) #3
  %6 = trunc i64 %5 to i32
  store i32 -1, ptr @top, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph15.preheader, label %.thread

.lr.ph15.preheader:                               ; preds = %.lr.ph23
  %wide.trip.count = and i64 %5, 2147483647
  br label %.lr.ph15

8:                                                ; preds = %.critedge
  store i32 %34, ptr @top, align 4, !tbaa !5
  %9 = icmp slt i32 %34, 0
  br i1 %9, label %.thread, label %35

.lr.ph15:                                         ; preds = %.lr.ph15.preheader, %.critedge
  %indvars.iv = phi i64 [ 0, %.lr.ph15.preheader ], [ %indvars.iv.next, %.critedge ]
  %10 = phi i32 [ -1, %.lr.ph15.preheader ], [ %34, %.critedge ]
  %11 = getelementptr inbounds [233333 x i8], ptr @str, i64 0, i64 %indvars.iv
  %12 = load i8, ptr %11, align 1, !tbaa !9
  %13 = add nsw i32 %10, 1
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [233333 x i8], ptr @sta, i64 0, i64 %14
  store i8 %12, ptr %15, align 1, !tbaa !9
  %16 = icmp sgt i32 %10, -1
  br i1 %16, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %.lr.ph15, %31
  %17 = phi i32 [ %32, %31 ], [ %13, %.lr.ph15 ]
  %18 = zext nneg i32 %17 to i64
  %19 = getelementptr inbounds [233333 x i8], ptr @sta, i64 0, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %21 = add nsw i32 %17, -1
  %22 = zext nneg i32 %21 to i64
  %23 = getelementptr inbounds [233333 x i8], ptr @sta, i64 0, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !9
  %.not8 = icmp eq i8 %20, %24
  br i1 %.not8, label %.critedge, label %25

25:                                               ; preds = %.lr.ph
  %26 = sext i8 %24 to i32
  %27 = sext i8 %20 to i32
  %28 = add nsw i32 %27, -97
  %29 = add nsw i32 %26, -97
  %.unshifted = xor i32 %29, %28
  %30 = icmp ult i32 %.unshifted, 2
  br i1 %30, label %31, label %.critedge

31:                                               ; preds = %25
  %32 = add nsw i32 %17, -2
  %33 = icmp sgt i32 %17, 2
  br i1 %33, label %.lr.ph, label %.critedge, !llvm.loop !10

.critedge:                                        ; preds = %.lr.ph, %31, %25, %.lr.ph15
  %34 = phi i32 [ %13, %.lr.ph15 ], [ %17, %25 ], [ %32, %31 ], [ %17, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %8, label %.lr.ph15, !llvm.loop !12

35:                                               ; preds = %8
  %36 = add nuw nsw i32 %34, 1
  store i32 %36, ptr @top, align 4, !tbaa !5
  %37 = zext nneg i32 %36 to i64
  %38 = getelementptr inbounds [233333 x i8], ptr @sta, i64 0, i64 %37
  store i8 0, ptr %38, align 1, !tbaa !9
  br label %.thread

.thread:                                          ; preds = %8, %.lr.ph23, %35
  %sta.sink = phi ptr [ @sta, %35 ], [ @.str.2, %.lr.ph23 ], [ @.str.2, %8 ]
  %39 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %sta.sink)
  %40 = load i32, ptr @t, align 4, !tbaa !5
  %41 = add nsw i32 %40, -1
  store i32 %41, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %40, 0
  br i1 %.not, label %._crit_edge24, label %.lr.ph23, !llvm.loop !13

._crit_edge24:                                    ; preds = %.thread, %0
  ret i32 0
}

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(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" }
attributes #2 = { 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 #3 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}


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