; LLVM IR from seppo0010/rlite :: src (page_btree)

; 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.rl_btree_iterator = type { ptr, ptr, i64, i64, [0 x %struct.rl_btree_iterator_nodes] }
%struct.rl_btree_iterator_nodes = type { i64, ptr }
%struct.rl_btree = type { ptr, i64, i64, ptr, i64, i64 }
%struct.rl_btree_type = type { ptr, ptr, i32, i32, ptr }
%struct.rl_btree_node = type { ptr, ptr, ptr, i64 }

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

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_btree_node_destroy(ptr noundef, ptr noundef) #2

declare i32 @rl_read(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef) #3

; 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) #4

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_btree_iterator_destroy(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_btree_iterator_next(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store ptr null, ptr %8, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %19, label %14

14:                                               ; preds = %3
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.rl_btree_iterator, ptr %15, i32 0, i32 3
  %17 = load i64, ptr %16, align 8, !tbaa !9
  %18 = icmp eq i64 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %14, %3
  store i32 9, ptr %7, align 4, !tbaa !11
  br label %269

20:                                               ; preds = %14
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.rl_btree_iterator, ptr %21, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  store ptr %23, ptr %11, align 8, !tbaa !5
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.rl_btree_iterator, ptr %24, i32 0, i32 4
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.rl_btree_iterator, ptr %26, i32 0, i32 3
  %28 = load i64, ptr %27, align 8, !tbaa !9
  %29 = sub nsw i64 %28, 1
  %30 = getelementptr inbounds [0 x %struct.rl_btree_iterator_nodes], ptr %25, i64 0, i64 %29
  %31 = getelementptr inbounds %struct.rl_btree_iterator_nodes, ptr %30, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  store ptr %32, ptr %8, align 8, !tbaa !5
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.rl_btree_iterator, ptr %33, i32 0, i32 4
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.rl_btree_iterator, ptr %35, i32 0, i32 3
  %37 = load i64, ptr %36, align 8, !tbaa !9
  %38 = sub nsw i64 %37, 1
  %39 = getelementptr inbounds [0 x %struct.rl_btree_iterator_nodes], ptr %34, i64 0, i64 %38
  %40 = getelementptr inbounds %struct.rl_btree_iterator_nodes, ptr %39, i32 0, i32 0
  %41 = load i64, ptr %40, align 8, !tbaa !15
  store i64 %41, ptr %9, align 8, !tbaa !9
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %76

44:                                               ; preds = %20
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.rl_btree_iterator, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.rl_btree, ptr %47, i32 0, i32 3
  %49 = load ptr, ptr %48, align 8, !tbaa !16
  %50 = getelementptr inbounds %struct.rl_btree_type, ptr %49, i32 0, i32 2
  %51 = load i32, ptr %50, align 8, !tbaa !18
  %52 = sext i32 %51 to i64
  %53 = call noalias ptr @malloc(i64 noundef %52) #6
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %53, ptr %54, align 8, !tbaa !5
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  %57 = icmp ne ptr %56, null
  br i1 %57, label %59, label %58

58:                                               ; preds = %44
  store i32 4, ptr %7, align 4, !tbaa !11
  br label %269

59:                                               ; preds = %44
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = load ptr, ptr %60, align 8, !tbaa !5
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.rl_btree_node, ptr %62, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !20
  %65 = load i64, ptr %9, align 8, !tbaa !9
  %66 = getelementptr inbounds ptr, ptr %64, i64 %65
  %67 = load ptr, ptr %66, align 8, !tbaa !5
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.rl_btree_iterator, ptr %68, i32 0, i32 1
  %70 = load ptr, ptr %69, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.rl_btree, ptr %70, i32 0, i32 3
  %72 = load ptr, ptr %71, align 8, !tbaa !16
  %73 = getelementptr inbounds %struct.rl_btree_type, ptr %72, i32 0, i32 2
  %74 = load i32, ptr %73, align 8, !tbaa !18
  %75 = sext i32 %74 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %61, ptr align 1 %67, i64 %75, i1 false)
  br label %76

76:                                               ; preds = %59, %20
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = icmp ne ptr %77, null
  br i1 %78, label %79, label %111

79:                                               ; preds = %76
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.rl_btree_iterator, ptr %80, i32 0, i32 1
  %82 = load ptr, ptr %81, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.rl_btree, ptr %82, i32 0, i32 3
  %84 = load ptr, ptr %83, align 8, !tbaa !16
  %85 = getelementptr inbounds %struct.rl_btree_type, ptr %84, i32 0, i32 3
  %86 = load i32, ptr %85, align 4, !tbaa !22
  %87 = sext i32 %86 to i64
  %88 = call noalias ptr @malloc(i64 noundef %87) #6
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %88, ptr %89, align 8, !tbaa !5
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = load ptr, ptr %90, align 8, !tbaa !5
  %92 = icmp ne ptr %91, null
  br i1 %92, label %94, label %93

93:                                               ; preds = %79
  store i32 4, ptr %7, align 4, !tbaa !11
  br label %269

94:                                               ; preds = %79
  %95 = load ptr, ptr %6, align 8, !tbaa !5
  %96 = load ptr, ptr %95, align 8, !tbaa !5
  %97 = load ptr, ptr %8, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.rl_btree_node, ptr %97, i32 0, i32 2
  %99 = load ptr, ptr %98, align 8, !tbaa !23
  %100 = load i64, ptr %9, align 8, !tbaa !9
  %101 = getelementptr inbounds ptr, ptr %99, i64 %100
  %102 = load ptr, ptr %101, align 8, !tbaa !5
  %103 = load ptr, ptr %4, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.rl_btree_iterator, ptr %103, i32 0, i32 1
  %105 = load ptr, ptr %104, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.rl_btree, ptr %105, i32 0, i32 3
  %107 = load ptr, ptr %106, align 8, !tbaa !16
  %108 = getelementptr inbounds %struct.rl_btree_type, ptr %107, i32 0, i32 3
  %109 = load i32, ptr %108, align 4, !tbaa !22
  %110 = sext i32 %109 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %96, ptr align 1 %102, i64 %110, i1 false)
  br label %111

111:                                              ; preds = %94, %76
  %112 = load ptr, ptr %8, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.rl_btree_node, ptr %112, i32 0, i32 1
  %114 = load ptr, ptr %113, align 8, !tbaa !24
  %115 = icmp ne ptr %114, null
  br i1 %115, label %116, label %184

116:                                              ; preds = %111
  %117 = load ptr, ptr %4, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.rl_btree_iterator, ptr %117, i32 0, i32 4
  %119 = load ptr, ptr %4, align 8, !tbaa !5
  %120 = getelementptr inbounds %struct.rl_btree_iterator, ptr %119, i32 0, i32 3
  %121 = load i64, ptr %120, align 8, !tbaa !9
  %122 = sub nsw i64 %121, 1
  %123 = getelementptr inbounds [0 x %struct.rl_btree_iterator_nodes], ptr %118, i64 0, i64 %122
  %124 = getelementptr inbounds %struct.rl_btree_iterator_nodes, ptr %123, i32 0, i32 0
  %125 = load i64, ptr %124, align 8, !tbaa !15
  %126 = add nsw i64 %125, 1
  store i64 %126, ptr %124, align 8, !tbaa !15
  br label %127

127:                                              ; preds = %166, %116
  %128 = load ptr, ptr %4, align 8, !tbaa !5
  %129 = getelementptr inbounds %struct.rl_btree_iterator, ptr %128, i32 0, i32 3
  %130 = load i64, ptr %129, align 8, !tbaa !9
  %131 = load ptr, ptr %4, align 8, !tbaa !5
  %132 = getelementptr inbounds %struct.rl_btree_iterator, ptr %131, i32 0, i32 1
  %133 = load ptr, ptr %132, align 8, !tbaa !5
  %134 = getelementptr inbounds %struct.rl_btree, ptr %133, i32 0, i32 2
  %135 = load i64, ptr %134, align 8, !tbaa !25
  %136 = icmp slt i64 %130, %135
  br i1 %136, label %137, label %183

137:                                              ; preds = %127
  %138 = load ptr, ptr %8, align 8, !tbaa !5
  %139 = getelementptr inbounds %struct.rl_btree_node, ptr %138, i32 0, i32 1
  %140 = load ptr, ptr %139, align 8, !tbaa !24
  %141 = load ptr, ptr %4, align 8, !tbaa !5
  %142 = getelementptr inbounds %struct.rl_btree_iterator, ptr %141, i32 0, i32 4
  %143 = load ptr, ptr %4, align 8, !tbaa !5
  %144 = getelementptr inbounds %struct.rl_btree_iterator, ptr %143, i32 0, i32 3
  %145 = load i64, ptr %144, align 8, !tbaa !9
  %146 = sub nsw i64 %145, 1
  %147 = getelementptr inbounds [0 x %struct.rl_btree_iterator_nodes], ptr %142, i64 0, i64 %146
  %148 = getelementptr inbounds %struct.rl_btree_iterator_nodes, ptr %147, i32 0, i32 0
  %149 = load i64, ptr %148, align 8, !tbaa !15
  %150 = getelementptr inbounds i64, ptr %140, i64 %149
  %151 = load i64, ptr %150, align 8, !tbaa !9
  store i64 %151, ptr %9, align 8, !tbaa !9
  %152 = load ptr, ptr %4, align 8, !tbaa !5
  %153 = getelementptr inbounds %struct.rl_btree_iterator, ptr %152, i32 0, i32 0
  %154 = load ptr, ptr %153, align 8, !tbaa !5
  %155 = load ptr, ptr %11, align 8, !tbaa !5
  %156 = getelementptr inbounds %struct.rl_btree, ptr %155, i32 0, i32 3
  %157 = load ptr, ptr %156, align 8, !tbaa !16
  %158 = getelementptr inbounds %struct.rl_btree_type, ptr %157, i32 0, i32 1
  %159 = load ptr, ptr %158, align 8, !tbaa !26
  %160 = load i64, ptr %9, align 8, !tbaa !9
  %161 = load ptr, ptr %11, align 8, !tbaa !5
  %162 = call i32 @rl_read(ptr noundef %154, ptr noundef %159, i64 noundef %160, ptr noundef %161, ptr noundef %10, i32 noundef 0)
  store i32 %162, ptr %7, align 4, !tbaa !11
  %163 = load i32, ptr %7, align 4, !tbaa !11
  %164 = icmp ne i32 2, %163
  br i1 %164, label %165, label %166

165:                                              ; preds = %137
  br label %269

166:                                              ; preds = %137
  %167 = load ptr, ptr %4, align 8, !tbaa !5
  %168 = getelementptr inbounds %struct.rl_btree_iterator, ptr %167, i32 0, i32 4
  %169 = load ptr, ptr %4, align 8, !tbaa !5
  %170 = getelementptr inbounds %struct.rl_btree_iterator, ptr %169, i32 0, i32 3
  %171 = load i64, ptr %170, align 8, !tbaa !9
  %172 = getelementptr inbounds [0 x %struct.rl_btree_iterator_nodes], ptr %168, i64 0, i64 %171
  %173 = getelementptr inbounds %struct.rl_btree_iterator_nodes, ptr %172, i32 0, i32 0
  store i64 0, ptr %173, align 8, !tbaa !15
  %174 = load ptr, ptr %10, align 8, !tbaa !5
  %175 = load ptr, ptr %4, align 8, !tbaa !5
  %176 = getelementptr inbounds %struct.rl_btree_iterator, ptr %175, i32 0, i32 4
  %177 = load ptr, ptr %4, align 8, !tbaa !5
  %178 = getelementptr inbounds %struct.rl_btree_iterator, ptr %177, i32 0, i32 3
  %179 = load i64, ptr %178, align 8, !tbaa !9
  %180 = add nsw i64 %179, 1
  store i64 %180, ptr %178, align 8, !tbaa !9
  %181 = getelementptr inbounds [0 x %struct.rl_btree_iterator_nodes], ptr %176, i64 0, i64 %179
  %182 = getelementptr inbounds %struct.rl_btree_iterator_nodes, ptr %181, i32 0, i32 1
  store ptr %174, ptr %182, align 8, !tbaa !13
  store ptr %174, ptr %8, align 8, !tbaa !5
  br label %127, !llvm.loop !27

183:                                              ; preds = %127
  br label %268

184:                                              ; preds = %111
  %185 = load ptr, ptr %8, align 8, !tbaa !5
  %186 = getelementptr inbounds %struct.rl_btree_node, ptr %185, i32 0, i32 3
  %187 = load i64, ptr %186, align 8, !tbaa !29
  %188 = load ptr, ptr %4, align 8, !tbaa !5
  %189 = getelementptr inbounds %struct.rl_btree_iterator, ptr %188, i32 0, i32 4
  %190 = load ptr, ptr %4, align 8, !tbaa !5
  %191 = getelementptr inbounds %struct.rl_btree_iterator, ptr %190, i32 0, i32 3
  %192 = load i64, ptr %191, align 8, !tbaa !9
  %193 = sub nsw i64 %192, 1
  %194 = getelementptr inbounds [0 x %struct.rl_btree_iterator_nodes], ptr %189, i64 0, i64 %193
  %195 = getelementptr inbounds %struct.rl_btree_iterator_nodes, ptr %194, i32 0, i32 0
  %196 = load i64, ptr %195, align 8, !tbaa !15
  %197 = add nsw i64 %196, 1
  %198 = icmp eq i64 %187, %197
  br i1 %198, label %199, label %256

199:                                              ; preds = %184
  br label %200

200:                                              ; preds = %239, %199
  %201 = load ptr, ptr %4, align 8, !tbaa !5
  %202 = getelementptr inbounds %struct.rl_btree_iterator, ptr %201, i32 0, i32 3
  %203 = load i64, ptr %202, align 8, !tbaa !9
  %204 = add nsw i64 %203, -1
  store i64 %204, ptr %202, align 8, !tbaa !9
  %205 = icmp sgt i64 %204, 0
  br i1 %205, label %206, label %240

206:                                              ; preds = %200
  %207 = load ptr, ptr %4, align 8, !tbaa !5
  %208 = getelementptr inbounds %struct.rl_btree_iterator, ptr %207, i32 0, i32 0
  %209 = load ptr, ptr %208, align 8, !tbaa !5
  %210 = load ptr, ptr %8, align 8, !tbaa !5
  %211 = call i32 @rl_btree_node_destroy(ptr noundef %209, ptr noundef %210)
  store i32 %211, ptr %7, align 4, !tbaa !11
  %212 = load i32, ptr %7, align 4, !tbaa !11
  %213 = icmp ne i32 0, %212
  br i1 %213, label %214, label %215

214:                                              ; preds = %206
  br label %269

215:                                              ; preds = %206
  %216 = load ptr, ptr %4, align 8, !tbaa !5
  %217 = getelementptr inbounds %struct.rl_btree_iterator, ptr %216, i32 0, i32 4
  %218 = load ptr, ptr %4, align 8, !tbaa !5
  %219 = getelementptr inbounds %struct.rl_btree_iterator, ptr %218, i32 0, i32 3
  %220 = load i64, ptr %219, align 8, !tbaa !9
  %221 = sub nsw i64 %220, 1
  %222 = getelementptr inbounds [0 x %struct.rl_btree_iterator_nodes], ptr %217, i64 0, i64 %221
  %223 = getelementptr inbounds %struct.rl_btree_iterator_nodes, ptr %222, i32 0, i32 1
  %224 = load ptr, ptr %223, align 8, !tbaa !13
  store ptr %224, ptr %8, align 8, !tbaa !5
  %225 = load ptr, ptr %4, align 8, !tbaa !5
  %226 = getelementptr inbounds %struct.rl_btree_iterator, ptr %225, i32 0, i32 4
  %227 = load ptr, ptr %4, align 8, !tbaa !5
  %228 = getelementptr inbounds %struct.rl_btree_iterator, ptr %227, i32 0, i32 3
  %229 = load i64, ptr %228, align 8, !tbaa !9
  %230 = sub nsw i64 %229, 1
  %231 = getelementptr inbounds [0 x %struct.rl_btree_iterator_nodes], ptr %226, i64 0, i64 %230
  %232 = getelementptr inbounds %struct.rl_btree_iterator_nodes, ptr %231, i32 0, i32 0
  %233 = load i64, ptr %232, align 8, !tbaa !15
  %234 = load ptr, ptr %8, align 8, !tbaa !5
  %235 = getelementptr inbounds %struct.rl_btree_node, ptr %234, i32 0, i32 3
  %236 = load i64, ptr %235, align 8, !tbaa !29
  %237 = icmp slt i64 %233, %236
  br i1 %237, label %238, label %239

238:                                              ; preds = %215
  br label %240

239:                                              ; preds = %215
  br label %200, !llvm.loop !30

240:                                              ; preds = %238, %200
  %241 = load ptr, ptr %4, align 8, !tbaa !5
  %242 = getelementptr inbounds %struct.rl_btree_iterator, ptr %241, i32 0, i32 3
  %243 = load i64, ptr %242, align 8, !tbaa !9
  %244 = icmp eq i64 %243, 0
  br i1 %244, label %245, label %255

245:                                              ; preds = %240
  %246 = load ptr, ptr %4, align 8, !tbaa !5
  %247 = getelementptr inbounds %struct.rl_btree_iterator, ptr %246, i32 0, i32 0
  %248 = load ptr, ptr %247, align 8, !tbaa !5
  %249 = load ptr, ptr %8, align 8, !tbaa !5
  %250 = call i32 @rl_btree_node_destroy(ptr noundef %248, ptr noundef %249)
  store i32 %250, ptr %7, align 4, !tbaa !11
  %251 = load i32, ptr %7, align 4, !tbaa !11
  %252 = icmp ne i32 0, %251
  br i1 %252, label %253, label %254

253:                                              ; preds = %245
  br label %269

254:                                              ; preds = %245
  br label %255

255:                                              ; preds = %254, %240
  br label %267

256:                                              ; preds = %184
  %257 = load ptr, ptr %4, align 8, !tbaa !5
  %258 = getelementptr inbounds %struct.rl_btree_iterator, ptr %257, i32 0, i32 4
  %259 = load ptr, ptr %4, align 8, !tbaa !5
  %260 = getelementptr inbounds %struct.rl_btree_iterator, ptr %259, i32 0, i32 3
  %261 = load i64, ptr %260, align 8, !tbaa !9
  %262 = sub nsw i64 %261, 1
  %263 = getelementptr inbounds [0 x %struct.rl_btree_iterator_nodes], ptr %258, i64 0, i64 %262
  %264 = getelementptr inbounds %struct.rl_btree_iterator_nodes, ptr %263, i32 0, i32 0
  %265 = load i64, ptr %264, align 8, !tbaa !15
  %266 = add nsw i64 %265, 1
  store i64 %266, ptr %264, align 8, !tbaa !15
  br label %267

267:                                              ; preds = %256, %255
  br label %268

268:                                              ; preds = %267, %183
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %269

269:                                              ; preds = %268, %253, %214, %165, %93, %58, %19
  %270 = load i32, ptr %7, align 4, !tbaa !11
  %271 = icmp ne i32 %270, 0
  br i1 %271, label %272, label %275

272:                                              ; preds = %269
  %273 = load ptr, ptr %4, align 8, !tbaa !5
  %274 = call i32 @rl_btree_iterator_destroy(ptr noundef %273)
  br label %275

275:                                              ; preds = %272, %269
  %276 = load i32, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  ret i32 %276
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"rl_btree_iterator_nodes", !10, i64 0, !6, i64 8}
!15 = !{!14, !10, i64 0}
!16 = !{!17, !6, i64 24}
!17 = !{!"rl_btree", !6, i64 0, !10, i64 8, !10, i64 16, !6, i64 24, !10, i64 32, !10, i64 40}
!18 = !{!19, !12, i64 16}
!19 = !{!"", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 20, !6, i64 24}
!20 = !{!21, !6, i64 0}
!21 = !{!"rl_btree_node", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24}
!22 = !{!19, !12, i64 20}
!23 = !{!21, !6, i64 16}
!24 = !{!21, !6, i64 8}
!25 = !{!17, !10, i64 16}
!26 = !{!19, !6, i64 8}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}
!29 = !{!21, !10, i64 24}
!30 = distinct !{!30, !28}


; 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.rl_btree_iterator_nodes = type { i64, ptr }

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_btree_node_destroy(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @rl_read(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress 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: nounwind uwtable
declare dso_local i32 @rl_btree_iterator_destroy(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_btree_iterator_next(ptr noundef %0, ptr noundef writeonly %1, ptr noundef writeonly %2) local_unnamed_addr #1 {
  %4 = alloca ptr, align 8
  %5 = icmp eq ptr %0, null
  br i1 %5, label %.thread, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = icmp eq i64 %8, 0
  br i1 %9, label %.thread, label %10

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = getelementptr inbounds i8, ptr %0, i64 32
  %14 = add nsw i64 %8, -1
  %15 = getelementptr inbounds [0 x %struct.rl_btree_iterator_nodes], ptr %13, i64 0, i64 %14
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = load i64, ptr %15, align 8, !tbaa !13
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %36, label %19

19:                                               ; preds = %10
  %20 = getelementptr inbounds i8, ptr %12, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  %23 = load i32, ptr %22, align 8, !tbaa !16
  %24 = sext i32 %23 to i64
  %25 = tail call noalias ptr @malloc(i64 noundef %24) #4
  store ptr %25, ptr %1, align 8, !tbaa !9
  %.not72 = icmp eq ptr %25, null
  br i1 %.not72, label %.thread, label %26

26:                                               ; preds = %19
  %27 = load ptr, ptr %17, align 8, !tbaa !19
  %28 = getelementptr inbounds ptr, ptr %27, i64 %18
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = load ptr, ptr %11, align 8, !tbaa !9
  %31 = getelementptr inbounds i8, ptr %30, i64 24
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = getelementptr inbounds i8, ptr %32, i64 16
  %34 = load i32, ptr %33, align 8, !tbaa !16
  %35 = sext i32 %34 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %25, ptr align 1 %29, i64 %35, i1 false)
  br label %36

36:                                               ; preds = %26, %10
  %37 = phi ptr [ %30, %26 ], [ %12, %10 ]
  %.not73 = icmp eq ptr %2, null
  br i1 %.not73, label %56, label %38

38:                                               ; preds = %36
  %39 = getelementptr inbounds i8, ptr %37, i64 24
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  %41 = getelementptr inbounds i8, ptr %40, i64 20
  %42 = load i32, ptr %41, align 4, !tbaa !21
  %43 = sext i32 %42 to i64
  %44 = tail call noalias ptr @malloc(i64 noundef %43) #4
  store ptr %44, ptr %2, align 8, !tbaa !9
  %.not74 = icmp eq ptr %44, null
  br i1 %.not74, label %.thread, label %45

45:                                               ; preds = %38
  %46 = getelementptr inbounds i8, ptr %17, i64 16
  %47 = load ptr, ptr %46, align 8, !tbaa !22
  %48 = getelementptr inbounds ptr, ptr %47, i64 %18
  %49 = load ptr, ptr %48, align 8, !tbaa !9
  %50 = load ptr, ptr %11, align 8, !tbaa !9
  %51 = getelementptr inbounds i8, ptr %50, i64 24
  %52 = load ptr, ptr %51, align 8, !tbaa !14
  %53 = getelementptr inbounds i8, ptr %52, i64 20
  %54 = load i32, ptr %53, align 4, !tbaa !21
  %55 = sext i32 %54 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %44, ptr align 1 %49, i64 %55, i1 false)
  br label %56

56:                                               ; preds = %45, %36
  %57 = phi ptr [ %50, %45 ], [ %37, %36 ]
  %58 = getelementptr inbounds i8, ptr %17, i64 8
  %59 = load ptr, ptr %58, align 8, !tbaa !23
  %.not75 = icmp eq ptr %59, null
  br i1 %.not75, label %103, label %60

60:                                               ; preds = %56
  %61 = add nsw i64 %18, 1
  store i64 %61, ptr %15, align 8, !tbaa !13
  %62 = getelementptr inbounds i8, ptr %57, i64 16
  %63 = load i64, ptr %62, align 8, !tbaa !24
  %64 = icmp slt i64 %8, %63
  br i1 %64, label %.lr.ph, label %.thread84

.lr.ph:                                           ; preds = %60
  %65 = getelementptr inbounds i8, ptr %12, i64 24
  %66 = getelementptr inbounds i8, ptr %17, i64 8
  %67 = load ptr, ptr %66, align 8, !tbaa !23
  %68 = getelementptr inbounds i64, ptr %67, i64 %61
  %69 = load i64, ptr %68, align 8, !tbaa !5
  %70 = load ptr, ptr %0, align 8, !tbaa !9
  %71 = load ptr, ptr %65, align 8, !tbaa !14
  %72 = getelementptr inbounds i8, ptr %71, i64 8
  %73 = load ptr, ptr %72, align 8, !tbaa !25
  %74 = call i32 @rl_read(ptr noundef %70, ptr noundef %73, i64 noundef %69, ptr noundef %12, ptr noundef nonnull %4, i32 noundef 0) #5
  switch i32 %74, label %.thread [
    i32 2, label %75
    i32 0, label %.thread84
  ]

75:                                               ; preds = %.lr.ph
  %76 = load i64, ptr %7, align 8, !tbaa !5
  %77 = getelementptr inbounds [0 x %struct.rl_btree_iterator_nodes], ptr %13, i64 0, i64 %76
  store i64 0, ptr %77, align 8, !tbaa !13
  %78 = load ptr, ptr %4, align 8, !tbaa !9
  %79 = add nsw i64 %76, 1
  store i64 %79, ptr %7, align 8, !tbaa !5
  %80 = getelementptr inbounds [0 x %struct.rl_btree_iterator_nodes], ptr %13, i64 0, i64 %76, i32 1
  store ptr %78, ptr %80, align 8, !tbaa !11
  %81 = load ptr, ptr %11, align 8, !tbaa !9
  %82 = getelementptr inbounds i8, ptr %81, i64 16
  %83 = load i64, ptr %82, align 8, !tbaa !24
  %84 = icmp slt i64 %79, %83
  br i1 %84, label %.lr.ph.peel.newph, label %.thread84

.lr.ph.peel.newph:                                ; preds = %75, %93
  %.06096 = phi ptr [ %96, %93 ], [ %78, %75 ]
  %85 = getelementptr inbounds i8, ptr %.06096, i64 8
  %86 = load ptr, ptr %85, align 8, !tbaa !23
  %87 = load i64, ptr %86, align 8, !tbaa !5
  %88 = load ptr, ptr %0, align 8, !tbaa !9
  %89 = load ptr, ptr %65, align 8, !tbaa !14
  %90 = getelementptr inbounds i8, ptr %89, i64 8
  %91 = load ptr, ptr %90, align 8, !tbaa !25
  %92 = call i32 @rl_read(ptr noundef %88, ptr noundef %91, i64 noundef %87, ptr noundef %12, ptr noundef nonnull %4, i32 noundef 0) #5
  switch i32 %92, label %.thread [
    i32 2, label %93
    i32 0, label %.thread84
  ]

93:                                               ; preds = %.lr.ph.peel.newph
  %94 = load i64, ptr %7, align 8, !tbaa !5
  %95 = getelementptr inbounds [0 x %struct.rl_btree_iterator_nodes], ptr %13, i64 0, i64 %94
  store i64 0, ptr %95, align 8, !tbaa !13
  %96 = load ptr, ptr %4, align 8, !tbaa !9
  %97 = add nsw i64 %94, 1
  store i64 %97, ptr %7, align 8, !tbaa !5
  %98 = getelementptr inbounds [0 x %struct.rl_btree_iterator_nodes], ptr %13, i64 0, i64 %94, i32 1
  store ptr %96, ptr %98, align 8, !tbaa !11
  %99 = load ptr, ptr %11, align 8, !tbaa !9
  %100 = getelementptr inbounds i8, ptr %99, i64 16
  %101 = load i64, ptr %100, align 8, !tbaa !24
  %102 = icmp slt i64 %97, %101
  br i1 %102, label %.lr.ph.peel.newph, label %.thread84, !llvm.loop !26

103:                                              ; preds = %56
  %104 = getelementptr inbounds i8, ptr %17, i64 24
  %105 = load i64, ptr %104, align 8, !tbaa !29
  %106 = add nsw i64 %18, 1
  %107 = icmp eq i64 %105, %106
  br i1 %107, label %.preheader, label %129

.preheader:                                       ; preds = %103, %114
  %108 = phi i64 [ %115, %114 ], [ %8, %103 ]
  %.1 = phi ptr [ %119, %114 ], [ %17, %103 ]
  %109 = add nsw i64 %108, -1
  store i64 %109, ptr %7, align 8, !tbaa !5
  %110 = icmp sgt i64 %108, 1
  br i1 %110, label %111, label %.loopexit

111:                                              ; preds = %.preheader
  %112 = load ptr, ptr %0, align 8, !tbaa !9
  %113 = tail call i32 @rl_btree_node_destroy(ptr noundef %112, ptr noundef nonnull %.1)
  %.not76 = icmp eq i32 %113, 0
  br i1 %.not76, label %114, label %.thread

114:                                              ; preds = %111
  %115 = load i64, ptr %7, align 8, !tbaa !5
  %116 = add nsw i64 %115, -1
  %117 = getelementptr inbounds [0 x %struct.rl_btree_iterator_nodes], ptr %13, i64 0, i64 %116
  %118 = getelementptr inbounds i8, ptr %117, i64 8
  %119 = load ptr, ptr %118, align 8, !tbaa !11
  %120 = load i64, ptr %117, align 8, !tbaa !13
  %121 = getelementptr inbounds i8, ptr %119, i64 24
  %122 = load i64, ptr %121, align 8, !tbaa !29
  %123 = icmp slt i64 %120, %122
  br i1 %123, label %.loopexit, label %.preheader, !llvm.loop !30

.loopexit:                                        ; preds = %.preheader, %114
  %124 = phi i64 [ %115, %114 ], [ %109, %.preheader ]
  %.2 = phi ptr [ %119, %114 ], [ %.1, %.preheader ]
  %125 = icmp eq i64 %124, 0
  br i1 %125, label %126, label %.thread84

126:                                              ; preds = %.loopexit
  %127 = load ptr, ptr %0, align 8, !tbaa !9
  %128 = tail call i32 @rl_btree_node_destroy(ptr noundef %127, ptr noundef nonnull %.2)
  %.not77 = icmp eq i32 %128, 0
  br i1 %.not77, label %.thread84, label %.thread

129:                                              ; preds = %103
  store i64 %106, ptr %15, align 8, !tbaa !13
  br label %.thread84

.thread:                                          ; preds = %.lr.ph, %.lr.ph.peel.newph, %111, %38, %19, %3, %6, %126
  %.082 = phi i32 [ 4, %38 ], [ 4, %19 ], [ 9, %3 ], [ 9, %6 ], [ %128, %126 ], [ %113, %111 ], [ %74, %.lr.ph ], [ %92, %.lr.ph.peel.newph ]
  %130 = call i32 @rl_btree_iterator_destroy(ptr noundef %0)
  br label %.thread84

.thread84:                                        ; preds = %.lr.ph, %75, %93, %.lr.ph.peel.newph, %60, %129, %126, %.loopexit, %.thread
  %.083 = phi i32 [ %.082, %.thread ], [ 0, %.loopexit ], [ 0, %126 ], [ 0, %129 ], [ 0, %60 ], [ %74, %.lr.ph ], [ 0, %75 ], [ %92, %.lr.ph.peel.newph ], [ 0, %93 ]
  ret i32 %.083
}

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 #2 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind allocsize(0) }
attributes #5 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"rl_btree_iterator_nodes", !6, i64 0, !10, i64 8}
!13 = !{!12, !6, i64 0}
!14 = !{!15, !10, i64 24}
!15 = !{!"rl_btree", !10, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !6, i64 32, !6, i64 40}
!16 = !{!17, !18, i64 16}
!17 = !{!"", !10, i64 0, !10, i64 8, !18, i64 16, !18, i64 20, !10, i64 24}
!18 = !{!"int", !7, i64 0}
!19 = !{!20, !10, i64 0}
!20 = !{!"rl_btree_node", !10, i64 0, !10, i64 8, !10, i64 16, !6, i64 24}
!21 = !{!17, !18, i64 20}
!22 = !{!20, !10, i64 16}
!23 = !{!20, !10, i64 8}
!24 = !{!15, !6, i64 16}
!25 = !{!17, !10, i64 8}
!26 = distinct !{!26, !27, !28}
!27 = !{!"llvm.loop.mustprogress"}
!28 = !{!"llvm.loop.peeled.count", i32 1}
!29 = !{!20, !6, i64 24}
!30 = distinct !{!30, !27}


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