; LLVM IR from tangjz/acm-icpc :: codeforces/complete (4D)

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

%struct.gift = type { i32, i32, i32 }
%"class.std::stack" = type { %"class.std::deque" }
%"class.std::deque" = type { %"class.std::_Deque_base" }
%"class.std::_Deque_base" = type { %"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl" }
%"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl" = type { %"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl_data" }
%"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl_data" = type { ptr, i64, %"struct.std::_Deque_iterator", %"struct.std::_Deque_iterator" }
%"struct.std::_Deque_iterator" = type { ptr, ptr, ptr, ptr }

@n = external dso_local global i32, align 4
@w = external dso_local global i32, align 4
@h = external dso_local global i32, align 4
@f = external dso_local global [5010 x i32], align 16
@p = external dso_local global [5010 x i32], align 16
@pos = external dso_local global i32, align 4
@a = external dso_local global [5010 x %struct.gift], align 16
@.str = external hidden unnamed_addr constant [7 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 [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 personality ptr @__gxx_personality_v0 {
  %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 %struct.gift, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %"class.std::stack", align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @w, ptr noundef @h)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #8
  %14 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %14, ptr %2, align 4, !tbaa !5
  store i32 0, ptr @n, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #8
  store i32 1, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #8
  br label %15

15:                                               ; preds = %41, %0
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = icmp sle i32 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #8
  br label %44

20:                                               ; preds = %15
  %21 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %4, ptr noundef %5)
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = load i32, ptr @w, align 4, !tbaa !5
  %24 = icmp sle i32 %22, %23
  br i1 %24, label %29, label %25

25:                                               ; preds = %20
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = load i32, ptr @h, align 4, !tbaa !5
  %28 = icmp sle i32 %26, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %25, %20
  br label %41

30:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 12, ptr %6) #8
  %31 = getelementptr inbounds %struct.gift, ptr %6, i32 0, i32 0
  %32 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %32, ptr %31, align 4, !tbaa !9
  %33 = getelementptr inbounds %struct.gift, ptr %6, i32 0, i32 1
  %34 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %34, ptr %33, align 4, !tbaa !11
  %35 = getelementptr inbounds %struct.gift, ptr %6, i32 0, i32 2
  %36 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %36, ptr %35, align 4, !tbaa !12
  %37 = load i32, ptr @n, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr @n, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [5010 x %struct.gift], ptr @a, i64 0, i64 %39
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %40, ptr align 4 %6, i64 12, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 12, ptr %6) #8
  br label %41

41:                                               ; preds = %30, %29
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %3, align 4, !tbaa !5
  br label %15, !llvm.loop !14

44:                                               ; preds = %19
  %45 = load i32, ptr @n, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds %struct.gift, ptr @a, i64 %46
  %48 = getelementptr inbounds %struct.gift, ptr %47, i64 1
  call void @_ZSt4sortIP4giftEvT_S2_(ptr noundef getelementptr inbounds (%struct.gift, ptr @a, i64 1), ptr noundef %48)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #8
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %128, %44
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = load i32, ptr @n, align 4, !tbaa !5
  %52 = icmp sle i32 %50, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %49
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #8
  br label %131

54:                                               ; preds = %49
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [5010 x i32], ptr @f, i64 0, i64 %56
  store i32 1, ptr %57, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #8
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %112, %54
  %59 = load i32, ptr %9, align 4, !tbaa !5
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = icmp slt i32 %59, %60
  br i1 %61, label %63, label %62

62:                                               ; preds = %58
  store i32 8, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #8
  br label %115

63:                                               ; preds = %58
  %64 = load i32, ptr %9, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [5010 x %struct.gift], ptr @a, i64 0, i64 %65
  %67 = getelementptr inbounds %struct.gift, ptr %66, i32 0, i32 0
  %68 = load i32, ptr %67, align 4, !tbaa !9
  %69 = load i32, ptr %7, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [5010 x %struct.gift], ptr @a, i64 0, i64 %70
  %72 = getelementptr inbounds %struct.gift, ptr %71, i32 0, i32 0
  %73 = load i32, ptr %72, align 4, !tbaa !9
  %74 = icmp slt i32 %68, %73
  br i1 %74, label %75, label %111

75:                                               ; preds = %63
  %76 = load i32, ptr %9, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [5010 x %struct.gift], ptr @a, i64 0, i64 %77
  %79 = getelementptr inbounds %struct.gift, ptr %78, i32 0, i32 1
  %80 = load i32, ptr %79, align 4, !tbaa !11
  %81 = load i32, ptr %7, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [5010 x %struct.gift], ptr @a, i64 0, i64 %82
  %84 = getelementptr inbounds %struct.gift, ptr %83, i32 0, i32 1
  %85 = load i32, ptr %84, align 4, !tbaa !11
  %86 = icmp slt i32 %80, %85
  br i1 %86, label %87, label %111

87:                                               ; preds = %75
  %88 = load i32, ptr %7, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [5010 x i32], ptr @f, i64 0, i64 %89
  %91 = load i32, ptr %90, align 4, !tbaa !5
  %92 = load i32, ptr %9, align 4, !tbaa !5
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [5010 x i32], ptr @f, i64 0, i64 %93
  %95 = load i32, ptr %94, align 4, !tbaa !5
  %96 = add nsw i32 %95, 1
  %97 = icmp slt i32 %91, %96
  br i1 %97, label %98, label %111

98:                                               ; preds = %87
  %99 = load i32, ptr %9, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [5010 x i32], ptr @f, i64 0, i64 %100
  %102 = load i32, ptr %101, align 4, !tbaa !5
  %103 = add nsw i32 %102, 1
  %104 = load i32, ptr %7, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [5010 x i32], ptr @f, i64 0, i64 %105
  store i32 %103, ptr %106, align 4, !tbaa !5
  %107 = load i32, ptr %9, align 4, !tbaa !5
  %108 = load i32, ptr %7, align 4, !tbaa !5
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [5010 x i32], ptr @p, i64 0, i64 %109
  store i32 %107, ptr %110, align 4, !tbaa !5
  br label %111

111:                                              ; preds = %98, %87, %75, %63
  br label %112

112:                                              ; preds = %111
  %113 = load i32, ptr %9, align 4, !tbaa !5
  %114 = add nsw i32 %113, 1
  store i32 %114, ptr %9, align 4, !tbaa !5
  br label %58, !llvm.loop !16

115:                                              ; preds = %62
  %116 = load i32, ptr @pos, align 4, !tbaa !5
  %117 = sext i32 %116 to i64
  %118 = getelementptr inbounds [5010 x i32], ptr @f, i64 0, i64 %117
  %119 = load i32, ptr %118, align 4, !tbaa !5
  %120 = load i32, ptr %7, align 4, !tbaa !5
  %121 = sext i32 %120 to i64
  %122 = getelementptr inbounds [5010 x i32], ptr @f, i64 0, i64 %121
  %123 = load i32, ptr %122, align 4, !tbaa !5
  %124 = icmp slt i32 %119, %123
  br i1 %124, label %125, label %127

125:                                              ; preds = %115
  %126 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %126, ptr @pos, align 4, !tbaa !5
  br label %127

127:                                              ; preds = %125, %115
  br label %128

128:                                              ; preds = %127
  %129 = load i32, ptr %7, align 4, !tbaa !5
  %130 = add nsw i32 %129, 1
  store i32 %130, ptr %7, align 4, !tbaa !5
  br label %49, !llvm.loop !17

131:                                              ; preds = %53
  %132 = load i32, ptr @pos, align 4, !tbaa !5
  %133 = sext i32 %132 to i64
  %134 = getelementptr inbounds [5010 x i32], ptr @f, i64 0, i64 %133
  %135 = load i32, ptr %134, align 4, !tbaa !5
  %136 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %135)
  call void @llvm.lifetime.start.p0(i64 80, ptr %10) #8
  call void @_ZNSt5stackIiSt5dequeIiSaIiEEEC2IS2_vEEv(ptr noundef nonnull align 8 dereferenceable(80) %10)
  br label %137

137:                                              ; preds = %145, %131
  %138 = load i32, ptr @pos, align 4, !tbaa !5
  %139 = icmp ne i32 %138, 0
  br i1 %139, label %140, label %154

140:                                              ; preds = %137
  %141 = load i32, ptr @pos, align 4, !tbaa !5
  %142 = sext i32 %141 to i64
  %143 = getelementptr inbounds [5010 x %struct.gift], ptr @a, i64 0, i64 %142
  %144 = getelementptr inbounds %struct.gift, ptr %143, i32 0, i32 2
  invoke void @_ZNSt5stackIiSt5dequeIiSaIiEEE4pushERKi(ptr noundef nonnull align 8 dereferenceable(80) %10, ptr noundef nonnull align 4 dereferenceable(4) %144)
          to label %145 unwind label %150

145:                                              ; preds = %140
  %146 = load i32, ptr @pos, align 4, !tbaa !5
  %147 = sext i32 %146 to i64
  %148 = getelementptr inbounds [5010 x i32], ptr @p, i64 0, i64 %147
  %149 = load i32, ptr %148, align 4, !tbaa !5
  store i32 %149, ptr @pos, align 4, !tbaa !5
  br label %137, !llvm.loop !18

150:                                              ; preds = %164, %161, %159, %155, %140
  %151 = landingpad { ptr, i32 }
          cleanup
  %152 = extractvalue { ptr, i32 } %151, 0
  store ptr %152, ptr %11, align 8
  %153 = extractvalue { ptr, i32 } %151, 1
  store i32 %153, ptr %12, align 4
  call void @_ZNSt5stackIiSt5dequeIiSaIiEEED2Ev(ptr noundef nonnull align 8 dereferenceable(80) %10) #8
  call void @llvm.lifetime.end.p0(i64 80, ptr %10) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #8
  br label %168

154:                                              ; preds = %137
  br label %155

155:                                              ; preds = %165, %154
  %156 = invoke noundef zeroext i1 @_ZNKSt5stackIiSt5dequeIiSaIiEEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(80) %10)
          to label %157 unwind label %150

157:                                              ; preds = %155
  %158 = xor i1 %156, true
  br i1 %158, label %159, label %166

159:                                              ; preds = %157
  %160 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5stackIiSt5dequeIiSaIiEEE3topEv(ptr noundef nonnull align 8 dereferenceable(80) %10)
          to label %161 unwind label %150

161:                                              ; preds = %159
  %162 = load i32, ptr %160, align 4, !tbaa !5
  %163 = invoke i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %162)
          to label %164 unwind label %150

164:                                              ; preds = %161
  invoke void @_ZNSt5stackIiSt5dequeIiSaIiEEE3popEv(ptr noundef nonnull align 8 dereferenceable(80) %10)
          to label %165 unwind label %150

165:                                              ; preds = %164
  br label %155, !llvm.loop !19

166:                                              ; preds = %157
  store i32 0, ptr %1, align 4
  store i32 1, ptr %8, align 4
  call void @_ZNSt5stackIiSt5dequeIiSaIiEEED2Ev(ptr noundef nonnull align 8 dereferenceable(80) %10) #8
  call void @llvm.lifetime.end.p0(i64 80, ptr %10) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #8
  %167 = load i32, ptr %1, align 4
  ret i32 %167

168:                                              ; preds = %150
  %169 = load ptr, ptr %11, align 8
  %170 = load i32, ptr %12, align 4
  %171 = insertvalue { ptr, i32 } poison, ptr %169, 0
  %172 = insertvalue { ptr, i32 } %171, i32 %170, 1
  resume { ptr, i32 } %172
}

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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 @_ZSt4sortIP4giftEvT_S2_(ptr noundef, ptr noundef) #4

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt5stackIiSt5dequeIiSaIiEEEC2IS2_vEEv(ptr noundef nonnull align 8 dereferenceable(80)) unnamed_addr #5 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt5stackIiSt5dequeIiSaIiEEE4pushERKi(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef nonnull align 4 dereferenceable(4)) #5 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt5stackIiSt5dequeIiSaIiEEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(80)) #6 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5stackIiSt5dequeIiSaIiEEE3topEv(ptr noundef nonnull align 8 dereferenceable(80)) #6 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt5stackIiSt5dequeIiSaIiEEE3popEv(ptr noundef nonnull align 8 dereferenceable(80)) #6 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZNSt5stackIiSt5dequeIiSaIiEEED2Ev(ptr noundef nonnull align 8 dereferenceable(80)) unnamed_addr #7 align 2

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 = { 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 #8 = { 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 = !{!10, !6, i64 0}
!10 = !{!"_ZTS4gift", !6, i64 0, !6, i64 4, !6, i64 8}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 8}
!13 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}
!18 = distinct !{!18, !15}
!19 = distinct !{!19, !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"

%struct.gift = type { i32, i32, i32 }
%"class.std::stack" = type { %"class.std::deque" }
%"class.std::deque" = type { %"class.std::_Deque_base" }
%"class.std::_Deque_base" = type { %"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl" }
%"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl" = type { %"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl_data" }
%"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl_data" = type { ptr, i64, %"struct.std::_Deque_iterator", %"struct.std::_Deque_iterator" }
%"struct.std::_Deque_iterator" = type { ptr, ptr, ptr, ptr }

@n = external dso_local global i32, align 4
@w = external dso_local global i32, align 4
@h = external dso_local global i32, align 4
@f = external dso_local local_unnamed_addr global [5010 x i32], align 16
@p = external dso_local local_unnamed_addr global [5010 x i32], align 16
@pos = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local global [5010 x %struct.gift], align 16
@.str = external hidden unnamed_addr constant [7 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 [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca %"class.std::stack", align 8
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @w, ptr noundef nonnull @h)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  store i32 0, ptr @n, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #7
  %.not35 = icmp slt i32 %5, 1
  br i1 %.not35, label %._crit_edge, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %23
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  %6 = sext i32 %.pre to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %0
  %7 = phi i64 [ %6, %._crit_edge.loopexit ], [ 0, %0 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #7
  %8 = getelementptr inbounds %struct.gift, ptr @a, i64 %7
  %9 = getelementptr inbounds i8, ptr %8, i64 12
  call void @_ZSt4sortIP4giftEvT_S2_(ptr noundef nonnull getelementptr inbounds (i8, ptr @a, i64 12), ptr noundef nonnull %9)
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %pos.promoted = load i32, ptr @pos, align 4, !tbaa !5
  %.not3043 = icmp slt i32 %10, 1
  br i1 %.not3043, label %._crit_edge48, label %.lr.ph47.preheader

.lr.ph47.preheader:                               ; preds = %._crit_edge
  %11 = add nuw i32 %10, 1
  %wide.trip.count59 = zext i32 %11 to i64
  br label %.lr.ph47

.lr.ph:                                           ; preds = %0, %23
  %.036 = phi i32 [ %24, %23 ], [ 1, %0 ]
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = load i32, ptr @w, align 4, !tbaa !5
  %.not33 = icmp sgt i32 %13, %14
  br i1 %.not33, label %15, label %23

15:                                               ; preds = %.lr.ph
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = load i32, ptr @h, align 4, !tbaa !5
  %.not34 = icmp sgt i32 %16, %17
  br i1 %.not34, label %18, label %23

18:                                               ; preds = %15
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr @n, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [5010 x %struct.gift], ptr @a, i64 0, i64 %21
  store i32 %13, ptr %22, align 4, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %22, i64 4
  store i32 %16, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %22, i64 8
  store i32 %.036, ptr %.sroa.5.0..sroa_idx, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %.lr.ph, %15, %18
  %24 = add nuw i32 %.036, 1
  %exitcond.not = icmp eq i32 %.036, %5
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !9

._crit_edge48:                                    ; preds = %61, %._crit_edge
  %25 = phi i32 [ %pos.promoted, %._crit_edge ], [ %.02541, %61 ]
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [5010 x i32], ptr @f, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %28)
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %3) #7
  call void @_ZNSt5stackIiSt5dequeIiSaIiEEEC2IS2_vEEv(ptr noundef nonnull align 8 dereferenceable(80) %3)
  %.pr = load i32, ptr @pos, align 4, !tbaa !5
  %.not3149 = icmp eq i32 %.pr, 0
  br i1 %.not3149, label %.preheader, label %.lr.ph51

.lr.ph47:                                         ; preds = %.lr.ph47.preheader, %61
  %indvars.iv56 = phi i64 [ 1, %.lr.ph47.preheader ], [ %indvars.iv.next57, %61 ]
  %.0254244 = phi i32 [ %pos.promoted, %.lr.ph47.preheader ], [ %.02541, %61 ]
  %30 = getelementptr inbounds [5010 x i32], ptr @f, i64 0, i64 %indvars.iv56
  store i32 1, ptr %30, align 4, !tbaa !5
  %31 = icmp ugt i64 %indvars.iv56, 1
  br i1 %31, label %.lr.ph39, label %._crit_edge40

.lr.ph39:                                         ; preds = %.lr.ph47
  %32 = getelementptr inbounds [5010 x %struct.gift], ptr @a, i64 0, i64 %indvars.iv56
  %33 = load i32, ptr %32, align 4, !tbaa !11
  %34 = getelementptr inbounds i8, ptr %32, i64 4
  %35 = getelementptr inbounds [5010 x i32], ptr @p, i64 0, i64 %indvars.iv56
  br label %41

._crit_edge40:                                    ; preds = %57, %.lr.ph47
  %36 = phi i32 [ 1, %.lr.ph47 ], [ %58, %57 ]
  %37 = sext i32 %.0254244 to i64
  %38 = getelementptr inbounds [5010 x i32], ptr @f, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = icmp slt i32 %39, %36
  br i1 %40, label %59, label %61

41:                                               ; preds = %.lr.ph39, %57
  %42 = phi i32 [ 1, %.lr.ph39 ], [ %58, %57 ]
  %indvars.iv = phi i64 [ 1, %.lr.ph39 ], [ %indvars.iv.next, %57 ]
  %43 = getelementptr inbounds [5010 x %struct.gift], ptr @a, i64 0, i64 %indvars.iv
  %44 = load i32, ptr %43, align 4, !tbaa !11
  %45 = icmp slt i32 %44, %33
  br i1 %45, label %46, label %57

46:                                               ; preds = %41
  %47 = getelementptr inbounds i8, ptr %43, i64 4
  %48 = load i32, ptr %47, align 4, !tbaa !13
  %49 = load i32, ptr %34, align 4, !tbaa !13
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %51, label %57

51:                                               ; preds = %46
  %52 = getelementptr inbounds [5010 x i32], ptr @f, i64 0, i64 %indvars.iv
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %.not32 = icmp sgt i32 %42, %53
  br i1 %.not32, label %57, label %54

54:                                               ; preds = %51
  %55 = add nsw i32 %53, 1
  store i32 %55, ptr %30, align 4, !tbaa !5
  %56 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %56, ptr %35, align 4, !tbaa !5
  br label %57

57:                                               ; preds = %41, %46, %51, %54
  %58 = phi i32 [ %42, %41 ], [ %42, %46 ], [ %42, %51 ], [ %55, %54 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond55.not = icmp eq i64 %indvars.iv.next, %indvars.iv56
  br i1 %exitcond55.not, label %._crit_edge40, label %41, !llvm.loop !14

59:                                               ; preds = %._crit_edge40
  %60 = trunc nuw nsw i64 %indvars.iv56 to i32
  store i32 %60, ptr @pos, align 4, !tbaa !5
  br label %61

61:                                               ; preds = %._crit_edge40, %59
  %.02541 = phi i32 [ %.0254244, %._crit_edge40 ], [ %60, %59 ]
  %indvars.iv.next57 = add nuw nsw i64 %indvars.iv56, 1
  %exitcond60.not = icmp eq i64 %indvars.iv.next57, %wide.trip.count59
  br i1 %exitcond60.not, label %._crit_edge48, label %.lr.ph47, !llvm.loop !15

.preheader:                                       ; preds = %66, %._crit_edge48
  %62 = call noundef zeroext i1 @_ZNKSt5stackIiSt5dequeIiSaIiEEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(80) %3)
  br i1 %62, label %._crit_edge53, label %.lr.ph52

.lr.ph51:                                         ; preds = %._crit_edge48, %66
  %63 = phi i32 [ %70, %66 ], [ %.pr, %._crit_edge48 ]
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [5010 x %struct.gift], ptr @a, i64 0, i64 %64, i32 2
  invoke void @_ZNSt5stackIiSt5dequeIiSaIiEEE4pushERKi(ptr noundef nonnull align 8 dereferenceable(80) %3, ptr noundef nonnull align 4 dereferenceable(4) %65)
          to label %66 unwind label %71

66:                                               ; preds = %.lr.ph51
  %67 = load i32, ptr @pos, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [5010 x i32], ptr @p, i64 0, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !5
  store i32 %70, ptr @pos, align 4, !tbaa !5
  %.not31 = icmp eq i32 %70, 0
  br i1 %.not31, label %.preheader, label %.lr.ph51, !llvm.loop !16

71:                                               ; preds = %.lr.ph51
  %72 = landingpad { ptr, i32 }
          cleanup
  call void @_ZNSt5stackIiSt5dequeIiSaIiEEED2Ev(ptr noundef nonnull align 8 dereferenceable(80) %3) #7
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %3) #7
  resume { ptr, i32 } %72

.lr.ph52:                                         ; preds = %.preheader, %.lr.ph52
  %73 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5stackIiSt5dequeIiSaIiEEE3topEv(ptr noundef nonnull align 8 dereferenceable(80) %3)
  %74 = load i32, ptr %73, align 4, !tbaa !5
  %75 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %74)
  call void @_ZNSt5stackIiSt5dequeIiSaIiEEE3popEv(ptr noundef nonnull align 8 dereferenceable(80) %3)
  %76 = call noundef zeroext i1 @_ZNKSt5stackIiSt5dequeIiSaIiEEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(80) %3)
  br i1 %76, label %._crit_edge53, label %.lr.ph52, !llvm.loop !17

._crit_edge53:                                    ; preds = %.lr.ph52, %.preheader
  call void @_ZNSt5stackIiSt5dequeIiSaIiEEED2Ev(ptr noundef nonnull align 8 dereferenceable(80) %3) #7
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %3) #7
  ret i32 0
}

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

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

; 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 @_ZSt4sortIP4giftEvT_S2_(ptr noundef, ptr noundef) local_unnamed_addr #3

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt5stackIiSt5dequeIiSaIiEEEC2IS2_vEEv(ptr noundef nonnull align 8 dereferenceable(80)) unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt5stackIiSt5dequeIiSaIiEEE4pushERKi(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #4 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt5stackIiSt5dequeIiSaIiEEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #5 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5stackIiSt5dequeIiSaIiEEE3topEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #5 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt5stackIiSt5dequeIiSaIiEEE3popEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #5 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZNSt5stackIiSt5dequeIiSaIiEEED2Ev(ptr noundef nonnull align 8 dereferenceable(80)) unnamed_addr #6 align 2

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


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