; LLVM IR from tangjz/acm-icpc :: Summer_Training/2016-07-17 (I - Query - tjz)

; 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
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@s = external dso_local global [1000001 x i8], align 16
@t = external dso_local global [1000001 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5buildii(i32 noundef, 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 uwtable
declare dso_local void @_Z6updateiii(i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z3sumiii(i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z5queryiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #0

; 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
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @tt)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %89, %0
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = load i32, ptr @tt, align 4, !tbaa !5
  %12 = icmp sle i32 %10, %11
  br i1 %12, label %14, label %13

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

14:                                               ; preds = %9
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @s, ptr noundef @t, ptr noundef @m)
  %16 = call i64 @strlen(ptr noundef @s) #6
  %17 = trunc i64 %16 to i32
  store i32 %17, ptr @n, align 4, !tbaa !5
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = sub nsw i32 %18, 1
  call void @_Z5buildii(i32 noundef 0, i32 noundef %19)
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %20)
  br label %22

22:                                               ; preds = %87, %14
  %23 = load i32, ptr @m, align 4, !tbaa !5
  %24 = add nsw i32 %23, -1
  store i32 %24, ptr @m, align 4, !tbaa !5
  %25 = icmp ne i32 %23, 0
  br i1 %25, label %26, label %88

26:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #5
  %27 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = icmp eq i32 %28, 1
  br i1 %29, label %30, label %48

30:                                               ; preds = %26
  %31 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.3, ptr noundef %4, ptr noundef %5, ptr noundef %6)
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = icmp eq i32 %32, 1
  br i1 %33, label %34, label %39

34:                                               ; preds = %30
  %35 = load i8, ptr %6, align 1, !tbaa !9
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [1000001 x i8], ptr @s, i64 0, i64 %37
  store i8 %35, ptr %38, align 1, !tbaa !9
  br label %44

39:                                               ; preds = %30
  %40 = load i8, ptr %6, align 1, !tbaa !9
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [1000001 x i8], ptr @t, i64 0, i64 %42
  store i8 %40, ptr %43, align 1, !tbaa !9
  br label %44

44:                                               ; preds = %39, %34
  %45 = load i32, ptr @n, align 4, !tbaa !5
  %46 = sub nsw i32 %45, 1
  %47 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z6updateiii(i32 noundef 0, i32 noundef %46, i32 noundef %47)
  br label %87

48:                                               ; preds = %26
  %49 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %4)
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [1000001 x i8], ptr @s, i64 0, i64 %51
  %53 = load i8, ptr %52, align 1, !tbaa !9
  %54 = sext i8 %53 to i32
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [1000001 x i8], ptr @t, i64 0, i64 %56
  %58 = load i8, ptr %57, align 1, !tbaa !9
  %59 = sext i8 %58 to i32
  %60 = icmp eq i32 %54, %59
  br i1 %60, label %61, label %84

61:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %64, label %70

64:                                               ; preds = %61
  %65 = load i32, ptr @n, align 4, !tbaa !5
  %66 = sub nsw i32 %65, 1
  %67 = load i32, ptr %4, align 4, !tbaa !5
  %68 = sub nsw i32 %67, 1
  %69 = call noundef i32 @_Z3sumiii(i32 noundef 0, i32 noundef %66, i32 noundef %68)
  br label %71

70:                                               ; preds = %61
  br label %71

71:                                               ; preds = %70, %64
  %72 = phi i32 [ %69, %64 ], [ 0, %70 ]
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = sub nsw i32 %73, 1
  %75 = sub nsw i32 %72, %74
  store i32 %75, ptr %7, align 4, !tbaa !5
  %76 = load i32, ptr @n, align 4, !tbaa !5
  %77 = sub nsw i32 %76, 1
  %78 = load i32, ptr %7, align 4, !tbaa !5
  %79 = call noundef i32 @_Z5queryiiii(i32 noundef 0, i32 noundef %77, i32 noundef %78, i32 noundef 0)
  %80 = load i32, ptr %4, align 4, !tbaa !5
  %81 = sub nsw i32 %79, %80
  %82 = add nsw i32 %81, 1
  %83 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %82)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %86

84:                                               ; preds = %48
  %85 = call i32 @puts(ptr noundef @.str.5)
  br label %86

86:                                               ; preds = %84, %71
  br label %87

87:                                               ; preds = %86, %44
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %22, !llvm.loop !10

88:                                               ; preds = %22
  br label %89

89:                                               ; preds = %88
  %90 = load i32, ptr %2, align 4, !tbaa !5
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %2, align 4, !tbaa !5
  br label %9, !llvm.loop !12

92:                                               ; preds = %13
  ret i32 0
}

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #4

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

declare i32 @puts(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 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 #5 = { nounwind }
attributes #6 = { 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}


; 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
@n = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local global i32, align 4
@s = external dso_local global [1000001 x i8], align 16
@t = external dso_local global [1000001 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1

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

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

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

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

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i8, align 1
  %5 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @tt)
  %6 = load i32, ptr @tt, align 4, !tbaa !5
  %.not10 = icmp slt i32 %6, 1
  br i1 %.not10, label %._crit_edge14, label %.lr.ph13

._crit_edge14:                                    ; preds = %._crit_edge, %0
  ret i32 0

.lr.ph13:                                         ; preds = %0, %._crit_edge
  %.011 = phi i32 [ %58, %._crit_edge ], [ 1, %0 ]
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @s, ptr noundef nonnull @t, ptr noundef nonnull @m)
  %8 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) @s) #5
  %9 = trunc i64 %8 to i32
  store i32 %9, ptr @n, align 4, !tbaa !5
  %10 = add nsw i32 %9, -1
  call void @_Z5buildii(i32 noundef 0, i32 noundef %10)
  %11 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.011)
  %12 = load i32, ptr @m, align 4, !tbaa !5
  %13 = add nsw i32 %12, -1
  store i32 %13, ptr @m, align 4, !tbaa !5
  %.not59 = icmp eq i32 %12, 0
  br i1 %.not59, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph13, %55
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #6
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #6
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = icmp eq i32 %15, 1
  br i1 %16, label %17, label %27

17:                                               ; preds = %.lr.ph
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.3, ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = icmp eq i32 %19, 1
  %21 = load i8, ptr %4, align 1, !tbaa !9
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %s.t = select i1 %20, ptr @s, ptr @t
  %24 = getelementptr inbounds [1000001 x i8], ptr %s.t, i64 0, i64 %23
  store i8 %21, ptr %24, align 1, !tbaa !9
  %25 = load i32, ptr @n, align 4, !tbaa !5
  %26 = add nsw i32 %25, -1
  call void @_Z6updateiii(i32 noundef 0, i32 noundef %26, i32 noundef %22)
  br label %55

27:                                               ; preds = %.lr.ph
  %28 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [1000001 x i8], ptr @s, i64 0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !9
  %33 = getelementptr inbounds [1000001 x i8], ptr @t, i64 0, i64 %30
  %34 = load i8, ptr %33, align 1, !tbaa !9
  %35 = icmp eq i8 %32, %34
  br i1 %35, label %36, label %53

36:                                               ; preds = %27
  %.not6 = icmp eq i32 %29, 0
  br i1 %.not6, label %42, label %37

37:                                               ; preds = %36
  %38 = load i32, ptr @n, align 4, !tbaa !5
  %39 = add nsw i32 %38, -1
  %40 = add nsw i32 %29, -1
  %41 = call noundef i32 @_Z3sumiii(i32 noundef 0, i32 noundef %39, i32 noundef %40)
  %.pre = load i32, ptr %2, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %36, %37
  %43 = phi i32 [ %.pre, %37 ], [ 0, %36 ]
  %44 = phi i32 [ %41, %37 ], [ 0, %36 ]
  %.neg7 = add i32 %44, 1
  %45 = sub i32 %.neg7, %43
  %46 = load i32, ptr @n, align 4, !tbaa !5
  %47 = add nsw i32 %46, -1
  %48 = call noundef i32 @_Z5queryiiii(i32 noundef 0, i32 noundef %47, i32 noundef %45, i32 noundef 0)
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = add i32 %48, 1
  %51 = sub i32 %50, %49
  %52 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %51)
  br label %55

53:                                               ; preds = %27
  %54 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.5)
  br label %55

55:                                               ; preds = %42, %53, %17
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  %56 = load i32, ptr @m, align 4, !tbaa !5
  %57 = add nsw i32 %56, -1
  store i32 %57, ptr @m, align 4, !tbaa !5
  %.not5 = icmp eq i32 %56, 0
  br i1 %.not5, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %55, %.lr.ph13
  %58 = add nuw nsw i32 %.011, 1
  %59 = load i32, ptr @tt, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.011, %59
  br i1 %.not.not, label %.lr.ph13, label %._crit_edge14, !llvm.loop !12
}

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

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(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 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 = { 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 #4 = { 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 #5 = { nounwind willreturn memory(read) }
attributes #6 = { 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}


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