; LLVM IR from tangjz/acm-icpc :: usaco/dec14-bronze (D)

; 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
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@w = external dso_local global [50010 x i32], align 16
@id = external dso_local global [50010 x i32], align 16
@ans = external dso_local global i32, align 4
@s = external dso_local global [50010 x i8], align 16
@.str = external hidden unnamed_addr constant [12 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z3cmpRKiS0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca [5 x i8], align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  call void @llvm.lifetime.start.p0(i64 5, ptr %5) #6
  %9 = load ptr, ptr @stdin, align 8, !tbaa !5
  %10 = call ptr @freopen(ptr noundef @.str, ptr noundef @.str.1, ptr noundef %9)
  %11 = load ptr, ptr @stdout, align 8, !tbaa !5
  %12 = call ptr @freopen(ptr noundef @.str.2, ptr noundef @.str.3, ptr noundef %11)
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.4, ptr noundef @n, ptr noundef @a, ptr noundef @b)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %37, %0
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = load i32, ptr @n, align 4, !tbaa !9
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  br label %40

19:                                               ; preds = %14
  %20 = getelementptr inbounds [5 x i8], ptr %5, i64 0, i64 0
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i32, ptr @w, i64 %22
  %24 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.5, ptr noundef %20, ptr noundef %23)
  %25 = getelementptr inbounds [5 x i8], ptr %5, i64 0, i64 0
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = sext i8 %26 to i32
  %28 = icmp eq i32 %27, 83
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [50010 x i8], ptr @s, i64 0, i64 %30
  %32 = zext i1 %28 to i8
  store i8 %32, ptr %31, align 1, !tbaa !12
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [50010 x i32], ptr @id, i64 0, i64 %35
  store i32 %33, ptr %36, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %19
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %6, align 4, !tbaa !9
  br label %14, !llvm.loop !14

40:                                               ; preds = %18
  %41 = load i32, ptr @n, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i32, ptr @id, i64 %42
  call void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef @id, ptr noundef %43, ptr noundef @_Z3cmpRKiS0_)
  %44 = load i32, ptr @a, align 4, !tbaa !9
  store i32 %44, ptr %2, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %45 = load i32, ptr @id, align 16, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [50010 x i32], ptr @w, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = sub nsw i32 %48, 1
  store i32 %49, ptr %7, align 4, !tbaa !9
  %50 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %7, ptr noundef nonnull align 4 dereferenceable(4) @b)
  %51 = load i32, ptr %50, align 4, !tbaa !9
  store i32 %51, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  %52 = load i32, ptr %2, align 4, !tbaa !9
  %53 = load i32, ptr %3, align 4, !tbaa !9
  %54 = icmp sle i32 %52, %53
  br i1 %54, label %55, label %62

55:                                               ; preds = %40
  %56 = load i32, ptr %3, align 4, !tbaa !9
  %57 = load i32, ptr %2, align 4, !tbaa !9
  %58 = sub nsw i32 %56, %57
  %59 = add nsw i32 %58, 1
  %60 = load i32, ptr @ans, align 4, !tbaa !9
  %61 = add nsw i32 %60, %59
  store i32 %61, ptr @ans, align 4, !tbaa !9
  br label %62

62:                                               ; preds = %55, %40
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  store i32 1, ptr %8, align 4, !tbaa !9
  br label %63

63:                                               ; preds = %178, %62
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = load i32, ptr @n, align 4, !tbaa !9
  %66 = icmp slt i32 %64, %65
  br i1 %66, label %68, label %67

67:                                               ; preds = %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %181

68:                                               ; preds = %63
  %69 = load i32, ptr %8, align 4, !tbaa !9
  %70 = sub nsw i32 %69, 1
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [50010 x i32], ptr @id, i64 0, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !9
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [50010 x i8], ptr @s, i64 0, i64 %74
  %76 = load i8, ptr %75, align 1, !tbaa !12, !range !16, !noundef !17
  %77 = trunc i8 %76 to i1
  br i1 %77, label %78, label %87

78:                                               ; preds = %68
  %79 = load i32, ptr %8, align 4, !tbaa !9
  %80 = sub nsw i32 %79, 1
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [50010 x i32], ptr @id, i64 0, i64 %81
  %83 = load i32, ptr %82, align 4, !tbaa !9
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [50010 x i32], ptr @w, i64 0, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !9
  store i32 %86, ptr %2, align 4, !tbaa !9
  br label %106

87:                                               ; preds = %68
  %88 = load i32, ptr %8, align 4, !tbaa !9
  %89 = sub nsw i32 %88, 1
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [50010 x i32], ptr @id, i64 0, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !9
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [50010 x i32], ptr @w, i64 0, i64 %93
  %95 = load i32, ptr %94, align 4, !tbaa !9
  %96 = load i32, ptr %8, align 4, !tbaa !9
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [50010 x i32], ptr @id, i64 0, i64 %97
  %99 = load i32, ptr %98, align 4, !tbaa !9
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [50010 x i32], ptr @w, i64 0, i64 %100
  %102 = load i32, ptr %101, align 4, !tbaa !9
  %103 = add nsw i32 %95, %102
  %104 = add nsw i32 %103, 1
  %105 = ashr i32 %104, 1
  store i32 %105, ptr %2, align 4, !tbaa !9
  br label %106

106:                                              ; preds = %87, %78
  %107 = load i32, ptr %8, align 4, !tbaa !9
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds [50010 x i32], ptr @id, i64 0, i64 %108
  %110 = load i32, ptr %109, align 4, !tbaa !9
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds [50010 x i8], ptr @s, i64 0, i64 %111
  %113 = load i8, ptr %112, align 1, !tbaa !12, !range !16, !noundef !17
  %114 = trunc i8 %113 to i1
  br i1 %114, label %115, label %124

115:                                              ; preds = %106
  %116 = load i32, ptr %8, align 4, !tbaa !9
  %117 = sext i32 %116 to i64
  %118 = getelementptr inbounds [50010 x i32], ptr @id, i64 0, i64 %117
  %119 = load i32, ptr %118, align 4, !tbaa !9
  %120 = sext i32 %119 to i64
  %121 = getelementptr inbounds [50010 x i32], ptr @w, i64 0, i64 %120
  %122 = load i32, ptr %121, align 4, !tbaa !9
  %123 = sub nsw i32 %122, 1
  store i32 %123, ptr %3, align 4, !tbaa !9
  br label %142

124:                                              ; preds = %106
  %125 = load i32, ptr %8, align 4, !tbaa !9
  %126 = sub nsw i32 %125, 1
  %127 = sext i32 %126 to i64
  %128 = getelementptr inbounds [50010 x i32], ptr @id, i64 0, i64 %127
  %129 = load i32, ptr %128, align 4, !tbaa !9
  %130 = sext i32 %129 to i64
  %131 = getelementptr inbounds [50010 x i32], ptr @w, i64 0, i64 %130
  %132 = load i32, ptr %131, align 4, !tbaa !9
  %133 = load i32, ptr %8, align 4, !tbaa !9
  %134 = sext i32 %133 to i64
  %135 = getelementptr inbounds [50010 x i32], ptr @id, i64 0, i64 %134
  %136 = load i32, ptr %135, align 4, !tbaa !9
  %137 = sext i32 %136 to i64
  %138 = getelementptr inbounds [50010 x i32], ptr @w, i64 0, i64 %137
  %139 = load i32, ptr %138, align 4, !tbaa !9
  %140 = add nsw i32 %132, %139
  %141 = ashr i32 %140, 1
  store i32 %141, ptr %3, align 4, !tbaa !9
  br label %142

142:                                              ; preds = %124, %115
  %143 = load i32, ptr %8, align 4, !tbaa !9
  %144 = sub nsw i32 %143, 1
  %145 = sext i32 %144 to i64
  %146 = getelementptr inbounds [50010 x i32], ptr @id, i64 0, i64 %145
  %147 = load i32, ptr %146, align 4, !tbaa !9
  %148 = sext i32 %147 to i64
  %149 = getelementptr inbounds [50010 x i8], ptr @s, i64 0, i64 %148
  %150 = load i8, ptr %149, align 1, !tbaa !12, !range !16, !noundef !17
  %151 = trunc i8 %150 to i1
  br i1 %151, label %162, label %152

152:                                              ; preds = %142
  %153 = load i32, ptr %8, align 4, !tbaa !9
  %154 = sext i32 %153 to i64
  %155 = getelementptr inbounds [50010 x i32], ptr @id, i64 0, i64 %154
  %156 = load i32, ptr %155, align 4, !tbaa !9
  %157 = sext i32 %156 to i64
  %158 = getelementptr inbounds [50010 x i8], ptr @s, i64 0, i64 %157
  %159 = load i8, ptr %158, align 1, !tbaa !12, !range !16, !noundef !17
  %160 = trunc i8 %159 to i1
  br i1 %160, label %162, label %161

161:                                              ; preds = %152
  br label %178

162:                                              ; preds = %152, %142
  %163 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) @a)
  %164 = load i32, ptr %163, align 4, !tbaa !9
  store i32 %164, ptr %2, align 4, !tbaa !9
  %165 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) @b)
  %166 = load i32, ptr %165, align 4, !tbaa !9
  store i32 %166, ptr %3, align 4, !tbaa !9
  %167 = load i32, ptr %2, align 4, !tbaa !9
  %168 = load i32, ptr %3, align 4, !tbaa !9
  %169 = icmp sle i32 %167, %168
  br i1 %169, label %170, label %177

170:                                              ; preds = %162
  %171 = load i32, ptr %3, align 4, !tbaa !9
  %172 = load i32, ptr %2, align 4, !tbaa !9
  %173 = sub nsw i32 %171, %172
  %174 = add nsw i32 %173, 1
  %175 = load i32, ptr @ans, align 4, !tbaa !9
  %176 = add nsw i32 %175, %174
  store i32 %176, ptr @ans, align 4, !tbaa !9
  br label %177

177:                                              ; preds = %170, %162
  br label %178

178:                                              ; preds = %177, %161
  %179 = load i32, ptr %8, align 4, !tbaa !9
  %180 = add nsw i32 %179, 1
  store i32 %180, ptr %8, align 4, !tbaa !9
  br label %63, !llvm.loop !18

181:                                              ; preds = %67
  %182 = load i32, ptr @n, align 4, !tbaa !9
  %183 = sub nsw i32 %182, 1
  %184 = sext i32 %183 to i64
  %185 = getelementptr inbounds [50010 x i32], ptr @id, i64 0, i64 %184
  %186 = load i32, ptr %185, align 4, !tbaa !9
  %187 = sext i32 %186 to i64
  %188 = getelementptr inbounds [50010 x i32], ptr @w, i64 0, i64 %187
  %189 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @a, ptr noundef nonnull align 4 dereferenceable(4) %188)
  %190 = load i32, ptr %189, align 4, !tbaa !9
  store i32 %190, ptr %2, align 4, !tbaa !9
  %191 = load i32, ptr @b, align 4, !tbaa !9
  store i32 %191, ptr %3, align 4, !tbaa !9
  %192 = load i32, ptr %2, align 4, !tbaa !9
  %193 = load i32, ptr %3, align 4, !tbaa !9
  %194 = icmp sle i32 %192, %193
  br i1 %194, label %195, label %202

195:                                              ; preds = %181
  %196 = load i32, ptr %3, align 4, !tbaa !9
  %197 = load i32, ptr %2, align 4, !tbaa !9
  %198 = sub nsw i32 %196, %197
  %199 = add nsw i32 %198, 1
  %200 = load i32, ptr @ans, align 4, !tbaa !9
  %201 = add nsw i32 %200, %199
  store i32 %201, ptr @ans, align 4, !tbaa !9
  br label %202

202:                                              ; preds = %195, %181
  %203 = load i32, ptr @ans, align 4, !tbaa !9
  %204 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i32 noundef %203)
  %205 = load ptr, ptr @stdin, align 8, !tbaa !5
  %206 = call i32 @fclose(ptr noundef %205)
  %207 = load ptr, ptr @stdout, align 8, !tbaa !5
  %208 = call i32 @fclose(ptr noundef %207)
  call void @llvm.lifetime.end.p0(i64 5, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  ret i32 0
}

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

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) #3

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef, ptr noundef, ptr noundef) #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #5

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #5

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

declare i32 @fclose(ptr noundef) #3

attributes #0 = { mustprogress 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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 #5 = { inlinehint mustprogress 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !15}


; 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
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@w = external dso_local global [50010 x i32], align 16
@id = external dso_local global [50010 x i32], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4
@s = external dso_local local_unnamed_addr global [50010 x i8], align 16
@.str = external hidden unnamed_addr constant [12 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z3cmpRKiS0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca [5 x i8], align 1
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #7
  call void @llvm.lifetime.start.p0(i64 5, ptr nonnull %3) #7
  %5 = load ptr, ptr @stdin, align 8, !tbaa !5
  %6 = tail call ptr @freopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef %5)
  %7 = load ptr, ptr @stdout, align 8, !tbaa !5
  %8 = tail call ptr @freopen(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.3, ptr noundef %7)
  %9 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull @n, ptr noundef nonnull @a, ptr noundef nonnull @b)
  %10 = load i32, ptr @n, align 4, !tbaa !9
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.lr.ph, label %.._crit_edge_crit_edge

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre51 = sext i32 %10 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre51, %.._crit_edge_crit_edge ], [ %30, %.lr.ph ]
  %12 = getelementptr inbounds i32, ptr @id, i64 %.pre-phi
  call void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef nonnull @id, ptr noundef nonnull %12, ptr noundef nonnull @_Z3cmpRKiS0_)
  %13 = load i32, ptr @a, align 4, !tbaa !9
  store i32 %13, ptr %1, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #7
  %14 = load i32, ptr @id, align 16, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [50010 x i32], ptr @w, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = add nsw i32 %17, -1
  store i32 %18, ptr %4, align 4, !tbaa !9
  %19 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) @b)
  %20 = load i32, ptr %19, align 4, !tbaa !9
  store i32 %20, ptr %2, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #7
  %.not = icmp sgt i32 %13, %20
  br i1 %.not, label %37, label %32

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %21 = getelementptr inbounds i32, ptr @w, i64 %indvars.iv
  %22 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.5, ptr noundef nonnull %3, ptr noundef nonnull %21)
  %23 = load i8, ptr %3, align 1, !tbaa !11
  %24 = icmp eq i8 %23, 83
  %25 = getelementptr inbounds [50010 x i8], ptr @s, i64 0, i64 %indvars.iv
  %26 = zext i1 %24 to i8
  store i8 %26, ptr %25, align 1, !tbaa !12
  %27 = getelementptr inbounds [50010 x i32], ptr @id, i64 0, i64 %indvars.iv
  %28 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %28, ptr %27, align 4, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %29 = load i32, ptr @n, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = icmp slt i64 %indvars.iv.next, %30
  br i1 %31, label %.lr.ph, label %._crit_edge, !llvm.loop !14

32:                                               ; preds = %._crit_edge
  %33 = load i32, ptr @ans, align 4, !tbaa !9
  %34 = add i32 %20, 1
  %35 = sub i32 %34, %13
  %36 = add nsw i32 %35, %33
  store i32 %36, ptr @ans, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %32, %._crit_edge
  %38 = load i32, ptr @n, align 4, !tbaa !9
  %39 = icmp sgt i32 %38, 1
  br i1 %39, label %.lr.ph42, label %._crit_edge43

._crit_edge43:                                    ; preds = %.thread31, %37
  %.lcssa = phi i32 [ %38, %37 ], [ %96, %.thread31 ]
  %40 = add nsw i32 %.lcssa, -1
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [50010 x i32], ptr @id, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [50010 x i32], ptr @w, i64 0, i64 %44
  %46 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @a, ptr noundef nonnull align 4 dereferenceable(4) %45)
  %47 = load i32, ptr %46, align 4, !tbaa !9
  store i32 %47, ptr %1, align 4, !tbaa !9
  %48 = load i32, ptr @b, align 4, !tbaa !9
  store i32 %48, ptr %2, align 4, !tbaa !9
  %.not27 = icmp sgt i32 %47, %48
  %.pre = load i32, ptr @ans, align 4, !tbaa !9
  br i1 %.not27, label %102, label %99

.lr.ph42:                                         ; preds = %37, %.thread31
  %indvars.iv48 = phi i64 [ %indvars.iv.next49, %.thread31 ], [ 1, %37 ]
  %49 = add nsw i64 %indvars.iv48, -1
  %50 = getelementptr inbounds [50010 x i32], ptr @id, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [50010 x i8], ptr @s, i64 0, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !12, !range !16, !noundef !17
  %55 = trunc nuw i8 %54 to i1
  %56 = getelementptr inbounds [50010 x i32], ptr @w, i64 0, i64 %52
  %57 = load i32, ptr %56, align 4, !tbaa !9
  br i1 %55, label %58, label %.thread32

58:                                               ; preds = %.lr.ph42
  store i32 %57, ptr %1, align 4, !tbaa !9
  %59 = getelementptr inbounds [50010 x i32], ptr @id, i64 0, i64 %indvars.iv48
  %60 = load i32, ptr %59, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [50010 x i8], ptr @s, i64 0, i64 %61
  %63 = load i8, ptr %62, align 1, !tbaa !12, !range !16, !noundef !17
  %64 = trunc nuw i8 %63 to i1
  %65 = getelementptr inbounds [50010 x i32], ptr @w, i64 0, i64 %61
  %66 = load i32, ptr %65, align 4, !tbaa !9
  br i1 %64, label %81, label %.thread

.thread32:                                        ; preds = %.lr.ph42
  %67 = getelementptr inbounds [50010 x i32], ptr @id, i64 0, i64 %indvars.iv48
  %68 = load i32, ptr %67, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [50010 x i32], ptr @w, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !9
  %72 = add i32 %57, 1
  %73 = add i32 %72, %71
  %74 = ashr i32 %73, 1
  store i32 %74, ptr %1, align 4, !tbaa !9
  %75 = getelementptr inbounds [50010 x i8], ptr @s, i64 0, i64 %69
  %76 = load i8, ptr %75, align 1, !tbaa !12, !range !16, !noundef !17
  %77 = trunc nuw i8 %76 to i1
  br i1 %77, label %.thread34, label %.thread.thread

.thread.thread:                                   ; preds = %.thread32
  %78 = add nsw i32 %71, %57
  %79 = ashr i32 %78, 1
  store i32 %79, ptr %2, align 4, !tbaa !9
  br label %.thread31

.thread34:                                        ; preds = %.thread32
  %80 = add nsw i32 %71, -1
  store i32 %80, ptr %2, align 4, !tbaa !9
  br label %85

81:                                               ; preds = %58
  %82 = add nsw i32 %66, -1
  store i32 %82, ptr %2, align 4, !tbaa !9
  br label %85

.thread:                                          ; preds = %58
  %83 = add nsw i32 %66, %57
  %84 = ashr i32 %83, 1
  store i32 %84, ptr %2, align 4, !tbaa !9
  br label %85

85:                                               ; preds = %.thread, %81, %.thread34
  %86 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) @a)
  %87 = load i32, ptr %86, align 4, !tbaa !9
  store i32 %87, ptr %1, align 4, !tbaa !9
  %88 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) @b)
  %89 = load i32, ptr %88, align 4, !tbaa !9
  store i32 %89, ptr %2, align 4, !tbaa !9
  %90 = load i32, ptr %1, align 4, !tbaa !9
  %.not29 = icmp sgt i32 %90, %89
  br i1 %.not29, label %.thread31, label %91

91:                                               ; preds = %85
  %92 = load i32, ptr @ans, align 4, !tbaa !9
  %93 = add i32 %89, 1
  %94 = sub i32 %93, %90
  %95 = add nsw i32 %94, %92
  store i32 %95, ptr @ans, align 4, !tbaa !9
  br label %.thread31

.thread31:                                        ; preds = %.thread.thread, %85, %91
  %indvars.iv.next49 = add nuw nsw i64 %indvars.iv48, 1
  %96 = load i32, ptr @n, align 4, !tbaa !9
  %97 = sext i32 %96 to i64
  %98 = icmp slt i64 %indvars.iv.next49, %97
  br i1 %98, label %.lr.ph42, label %._crit_edge43, !llvm.loop !18

99:                                               ; preds = %._crit_edge43
  %reass.sub = sub i32 %48, %47
  %100 = add i32 %reass.sub, 1
  %101 = add nsw i32 %100, %.pre
  store i32 %101, ptr @ans, align 4, !tbaa !9
  br label %102

102:                                              ; preds = %99, %._crit_edge43
  %103 = phi i32 [ %101, %99 ], [ %.pre, %._crit_edge43 ]
  %104 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef %103)
  %105 = load ptr, ptr @stdin, align 8, !tbaa !5
  %106 = call i32 @fclose(ptr noundef %105)
  %107 = load ptr, ptr @stdout, align 8, !tbaa !5
  %108 = call i32 @fclose(ptr noundef %107)
  call void @llvm.lifetime.end.p0(i64 5, ptr nonnull %3) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #7
  ret i32 0
}

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

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #5

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #6

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #6

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

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #4

attributes #0 = { mustprogress 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 = { 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #5 = { inlinehint 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 #6 = { inlinehint mustprogress 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 #7 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !15}


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