; LLVM IR from tangjz/acm-icpc :: self_training/2016-06-18 (S)

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

@tt = external dso_local global i32, align 4
@pos = external dso_local global i32, align 4
@s = external dso_local global [100001 x i8], align 16
@t = external dso_local global [100001 x i8], align 16
@.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 [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 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
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @tt)
  br label %4

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

8:                                                ; preds = %4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @s, ptr noundef @t)
  store i32 0, ptr @pos, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %33, %8
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [100001 x i8], ptr @s, i64 0, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !9
  %15 = icmp ne i8 %14, 0
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %10
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [100001 x i8], ptr @s, i64 0, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !9
  %22 = sext i8 %21 to i32
  %23 = load i32, ptr @pos, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100001 x i8], ptr @t, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = sext i8 %26 to i32
  %28 = icmp eq i32 %22, %27
  br i1 %28, label %29, label %32

29:                                               ; preds = %17
  %30 = load i32, ptr @pos, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr @pos, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %29, %17
  br label %33

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

36:                                               ; preds = %16
  %37 = load i32, ptr @pos, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [100001 x i8], ptr @t, i64 0, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !9
  %41 = icmp ne i8 %40, 0
  %42 = xor i1 %41, true
  %43 = zext i1 %42 to i64
  %44 = select i1 %42, ptr @.str.2, ptr @.str.3
  %45 = call i32 @puts(ptr noundef %44)
  br label %4, !llvm.loop !12

46:                                               ; preds = %4
  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

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

@tt = external dso_local global i32, align 4
@pos = external dso_local local_unnamed_addr global i32, align 4
@s = external dso_local global [100001 x i8], align 16
@t = external dso_local global [100001 x i8], align 16
@.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 [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 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 @tt)
  %2 = load i32, ptr @tt, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @tt, align 4, !tbaa !5
  %.not8 = icmp eq i32 %2, 0
  br i1 %.not8, label %._crit_edge11, label %.lr.ph10

.lr.ph10:                                         ; preds = %0, %._crit_edge
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @s, ptr noundef nonnull @t)
  store i32 0, ptr @pos, align 4, !tbaa !5
  %5 = load i8, ptr @s, align 16, !tbaa !9
  %.not46 = icmp eq i8 %5, 0
  br i1 %.not46, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %22, %.lr.ph10
  %6 = phi i32 [ 0, %.lr.ph10 ], [ %23, %22 ]
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [100001 x i8], ptr @t, i64 0, i64 %7
  %9 = load i8, ptr %8, align 1, !tbaa !9
  %.not5 = icmp eq i8 %9, 0
  %10 = select i1 %.not5, ptr @.str.2, ptr @.str.3
  %11 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %10)
  %12 = load i32, ptr @tt, align 4, !tbaa !5
  %13 = add nsw i32 %12, -1
  store i32 %13, ptr @tt, align 4, !tbaa !5
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %._crit_edge11, label %.lr.ph10, !llvm.loop !10

.lr.ph:                                           ; preds = %.lr.ph10, %22
  %indvars.iv = phi i64 [ %indvars.iv.next, %22 ], [ 0, %.lr.ph10 ]
  %14 = phi i8 [ %25, %22 ], [ %5, %.lr.ph10 ]
  %15 = phi i32 [ %23, %22 ], [ 0, %.lr.ph10 ]
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [100001 x i8], ptr @t, i64 0, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !9
  %19 = icmp eq i8 %14, %18
  br i1 %19, label %20, label %22

20:                                               ; preds = %.lr.ph
  %21 = add nsw i32 %15, 1
  store i32 %21, ptr @pos, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %.lr.ph, %20
  %23 = phi i32 [ %15, %.lr.ph ], [ %21, %20 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %24 = getelementptr inbounds [100001 x i8], ptr @s, i64 0, i64 %indvars.iv.next
  %25 = load i8, ptr %24, align 1, !tbaa !9
  %.not4 = icmp eq i8 %25, 0
  br i1 %.not4, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge11:                                    ; preds = %._crit_edge, %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 @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" }

!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}


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