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

; 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.rlite = type { i64, i64, i32, ptr, i64, i64, i64, ptr, i32, i32, i32, i32, ptr, i64, i64, ptr, i64, i64, ptr, ptr, ptr, ptr }
%struct.rl_file_driver = type { ptr, ptr, i32 }
%struct.rl_page = type { i64, ptr, ptr }
%struct.rl_memory_driver = type { ptr, i64 }
%struct.rl_data_type = type { ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [3 x i8], align 1

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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #1

declare i32 @rl_flock(ptr noundef, i32 noundef) #1

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

declare i32 @fclose(ptr noundef) #1

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

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

20:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.rlite, ptr %21, i32 0, i32 7
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  store ptr %23, ptr %12, align 8, !tbaa !5
  %24 = load ptr, ptr %12, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.rl_file_driver, ptr %24, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  %27 = call ptr @get_wal_filename(ptr noundef %26)
  store ptr %27, ptr %9, align 8, !tbaa !5
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = icmp eq ptr %28, null
  br i1 %29, label %30, label %31

30:                                               ; preds = %20
  store i32 4, ptr %5, align 4, !tbaa !9
  store i32 2, ptr %13, align 4
  br label %81

31:                                               ; preds = %20
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = call noalias ptr @fopen(ptr noundef %32, ptr noundef @.str)
  store ptr %33, ptr %4, align 8, !tbaa !5
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = icmp eq ptr %34, null
  br i1 %35, label %36, label %37

36:                                               ; preds = %31
  store i32 6, ptr %5, align 4, !tbaa !9
  store i32 2, ptr %13, align 4
  br label %81

37:                                               ; preds = %31
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = call i32 @rl_flock(ptr noundef %38, i32 noundef 2)
  store i32 %39, ptr %5, align 4, !tbaa !9
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = icmp ne i32 0, %40
  br i1 %41, label %42, label %43

42:                                               ; preds = %37
  store i32 2, ptr %13, align 4
  br label %81

43:                                               ; preds = %37
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = call i32 @rl_write_wal_file(ptr noundef %44, ptr noundef %45, ptr noundef %10, ptr noundef %11)
  store i32 %46, ptr %5, align 4, !tbaa !9
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = icmp ne i32 0, %47
  br i1 %48, label %49, label %50

49:                                               ; preds = %43
  store i32 2, ptr %13, align 4
  br label %81

50:                                               ; preds = %43
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = load i64, ptr %11, align 8, !tbaa !17
  %54 = call i32 @rl_apply_wal_data(ptr noundef %51, ptr noundef %52, i64 noundef %53, i32 noundef 1)
  store i32 %54, ptr %5, align 4, !tbaa !9
  %55 = load i32, ptr %5, align 4, !tbaa !9
  %56 = icmp ne i32 0, %55
  br i1 %56, label %57, label %58

57:                                               ; preds = %50
  store i32 2, ptr %13, align 4
  br label %81

58:                                               ; preds = %50
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = call i32 @fileno(ptr noundef %59) #6
  %61 = call i32 @ftruncate(i32 noundef %60, i64 noundef 0) #6
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = call i32 @fclose(ptr noundef %62)
  store ptr null, ptr %4, align 8, !tbaa !5
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = call i32 @rl_delete_wal(ptr noundef %64)
  store i32 %65, ptr %5, align 4, !tbaa !9
  %66 = load i32, ptr %5, align 4, !tbaa !9
  %67 = icmp ne i32 0, %66
  br i1 %67, label %68, label %69

68:                                               ; preds = %58
  store i32 2, ptr %13, align 4
  br label %81

69:                                               ; preds = %58
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.rlite, ptr %70, i32 0, i32 17
  %72 = load i64, ptr %71, align 8, !tbaa !18
  %73 = icmp sgt i64 %72, 0
  br i1 %73, label %74, label %79

74:                                               ; preds = %69
  %75 = load ptr, ptr %12, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.rl_file_driver, ptr %75, i32 0, i32 0
  %77 = load ptr, ptr %76, align 8, !tbaa !19
  %78 = call i32 @fflush(ptr noundef %77)
  br label %79

79:                                               ; preds = %74, %69
  %80 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %80) #6
  store ptr null, ptr %10, align 8, !tbaa !5
  store i32 0, ptr %13, align 4
  br label %81

81:                                               ; preds = %79, %68, %57, %49, %42, %36, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  %82 = load i32, ptr %13, align 4
  switch i32 %82, label %227 [
    i32 0, label %83
    i32 2, label %217
  ]

83:                                               ; preds = %81
  br label %216

84:                                               ; preds = %1
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.rlite, ptr %85, i32 0, i32 8
  %87 = load i32, ptr %86, align 8, !tbaa !11
  %88 = icmp eq i32 %87, 0
  br i1 %88, label %89, label %215

89:                                               ; preds = %84
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  %90 = load ptr, ptr %3, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.rlite, ptr %90, i32 0, i32 7
  %92 = load ptr, ptr %91, align 8, !tbaa !14
  store ptr %92, ptr %14, align 8, !tbaa !5
  %93 = load ptr, ptr %3, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.rlite, ptr %93, i32 0, i32 17
  %95 = load i64, ptr %94, align 8, !tbaa !18
  %96 = icmp sgt i64 %95, 0
  br i1 %96, label %97, label %154

97:                                               ; preds = %89
  %98 = load ptr, ptr %3, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.rlite, ptr %98, i32 0, i32 18
  %100 = load ptr, ptr %99, align 8, !tbaa !20
  %101 = load ptr, ptr %3, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.rlite, ptr %101, i32 0, i32 17
  %103 = load i64, ptr %102, align 8, !tbaa !18
  %104 = sub nsw i64 %103, 1
  %105 = getelementptr inbounds ptr, ptr %100, i64 %104
  %106 = load ptr, ptr %105, align 8, !tbaa !5
  store ptr %106, ptr %8, align 8, !tbaa !5
  %107 = load ptr, ptr %8, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.rl_page, ptr %107, i32 0, i32 0
  %109 = load i64, ptr %108, align 8, !tbaa !21
  %110 = add nsw i64 %109, 1
  %111 = load ptr, ptr %3, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.rlite, ptr %111, i32 0, i32 6
  %113 = load i64, ptr %112, align 8, !tbaa !23
  %114 = mul nsw i64 %110, %113
  %115 = load ptr, ptr %14, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.rl_memory_driver, ptr %115, i32 0, i32 1
  %117 = load i64, ptr %116, align 8, !tbaa !24
  %118 = icmp sgt i64 %114, %117
  br i1 %118, label %119, label %153

119:                                              ; preds = %97
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #6
  %120 = load ptr, ptr %14, align 8, !tbaa !5
  %121 = getelementptr inbounds %struct.rl_memory_driver, ptr %120, i32 0, i32 0
  %122 = load ptr, ptr %121, align 8, !tbaa !26
  %123 = load ptr, ptr %8, align 8, !tbaa !5
  %124 = getelementptr inbounds %struct.rl_page, ptr %123, i32 0, i32 0
  %125 = load i64, ptr %124, align 8, !tbaa !21
  %126 = add nsw i64 %125, 1
  %127 = load ptr, ptr %3, align 8, !tbaa !5
  %128 = getelementptr inbounds %struct.rlite, ptr %127, i32 0, i32 6
  %129 = load i64, ptr %128, align 8, !tbaa !23
  %130 = mul nsw i64 %126, %129
  %131 = mul i64 %130, 1
  %132 = call ptr @realloc(ptr noundef %122, i64 noundef %131) #7
  store ptr %132, ptr %15, align 8, !tbaa !5
  %133 = load ptr, ptr %15, align 8, !tbaa !5
  %134 = icmp ne ptr %133, null
  br i1 %134, label %136, label %135

135:                                              ; preds = %119
  store i32 4, ptr %5, align 4, !tbaa !9
  store i32 2, ptr %13, align 4
  br label %150

136:                                              ; preds = %119
  %137 = load ptr, ptr %15, align 8, !tbaa !5
  %138 = load ptr, ptr %14, align 8, !tbaa !5
  %139 = getelementptr inbounds %struct.rl_memory_driver, ptr %138, i32 0, i32 0
  store ptr %137, ptr %139, align 8, !tbaa !26
  %140 = load ptr, ptr %8, align 8, !tbaa !5
  %141 = getelementptr inbounds %struct.rl_page, ptr %140, i32 0, i32 0
  %142 = load i64, ptr %141, align 8, !tbaa !21
  %143 = add nsw i64 %142, 1
  %144 = load ptr, ptr %3, align 8, !tbaa !5
  %145 = getelementptr inbounds %struct.rlite, ptr %144, i32 0, i32 6
  %146 = load i64, ptr %145, align 8, !tbaa !23
  %147 = mul nsw i64 %143, %146
  %148 = load ptr, ptr %14, align 8, !tbaa !5
  %149 = getelementptr inbounds %struct.rl_memory_driver, ptr %148, i32 0, i32 1
  store i64 %147, ptr %149, align 8, !tbaa !24
  store i32 0, ptr %13, align 4
  br label %150

150:                                              ; preds = %136, %135
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  %151 = load i32, ptr %13, align 4
  switch i32 %151, label %212 [
    i32 0, label %152
  ]

152:                                              ; preds = %150
  br label %153

153:                                              ; preds = %152, %97
  br label %154

154:                                              ; preds = %153, %89
  store i64 0, ptr %6, align 8, !tbaa !17
  br label %155

155:                                              ; preds = %208, %154
  %156 = load i64, ptr %6, align 8, !tbaa !17
  %157 = load ptr, ptr %3, align 8, !tbaa !5
  %158 = getelementptr inbounds %struct.rlite, ptr %157, i32 0, i32 17
  %159 = load i64, ptr %158, align 8, !tbaa !18
  %160 = icmp slt i64 %156, %159
  br i1 %160, label %161, label %211

161:                                              ; preds = %155
  %162 = load ptr, ptr %3, align 8, !tbaa !5
  %163 = getelementptr inbounds %struct.rlite, ptr %162, i32 0, i32 18
  %164 = load ptr, ptr %163, align 8, !tbaa !20
  %165 = load i64, ptr %6, align 8, !tbaa !17
  %166 = getelementptr inbounds ptr, ptr %164, i64 %165
  %167 = load ptr, ptr %166, align 8, !tbaa !5
  store ptr %167, ptr %8, align 8, !tbaa !5
  %168 = load ptr, ptr %8, align 8, !tbaa !5
  %169 = getelementptr inbounds %struct.rl_page, ptr %168, i32 0, i32 0
  %170 = load i64, ptr %169, align 8, !tbaa !21
  store i64 %170, ptr %7, align 8, !tbaa !17
  %171 = load ptr, ptr %14, align 8, !tbaa !5
  %172 = getelementptr inbounds %struct.rl_memory_driver, ptr %171, i32 0, i32 0
  %173 = load ptr, ptr %172, align 8, !tbaa !26
  %174 = load i64, ptr %7, align 8, !tbaa !17
  %175 = load ptr, ptr %3, align 8, !tbaa !5
  %176 = getelementptr inbounds %struct.rlite, ptr %175, i32 0, i32 6
  %177 = load i64, ptr %176, align 8, !tbaa !23
  %178 = mul nsw i64 %174, %177
  %179 = getelementptr inbounds i8, ptr %173, i64 %178
  %180 = load ptr, ptr %3, align 8, !tbaa !5
  %181 = getelementptr inbounds %struct.rlite, ptr %180, i32 0, i32 6
  %182 = load i64, ptr %181, align 8, !tbaa !23
  call void @llvm.memset.p0.i64(ptr align 1 %179, i8 0, i64 %182, i1 false)
  %183 = load ptr, ptr %8, align 8, !tbaa !5
  %184 = getelementptr inbounds %struct.rl_page, ptr %183, i32 0, i32 1
  %185 = load ptr, ptr %184, align 8, !tbaa !27
  %186 = icmp ne ptr %185, null
  br i1 %186, label %187, label %207

187:                                              ; preds = %161
  %188 = load ptr, ptr %8, align 8, !tbaa !5
  %189 = getelementptr inbounds %struct.rl_page, ptr %188, i32 0, i32 1
  %190 = load ptr, ptr %189, align 8, !tbaa !27
  %191 = getelementptr inbounds %struct.rl_data_type, ptr %190, i32 0, i32 1
  %192 = load ptr, ptr %191, align 8, !tbaa !28
  %193 = load ptr, ptr %3, align 8, !tbaa !5
  %194 = load ptr, ptr %8, align 8, !tbaa !5
  %195 = getelementptr inbounds %struct.rl_page, ptr %194, i32 0, i32 2
  %196 = load ptr, ptr %195, align 8, !tbaa !30
  %197 = load ptr, ptr %14, align 8, !tbaa !5
  %198 = getelementptr inbounds %struct.rl_memory_driver, ptr %197, i32 0, i32 0
  %199 = load ptr, ptr %198, align 8, !tbaa !26
  %200 = load i64, ptr %7, align 8, !tbaa !17
  %201 = load ptr, ptr %3, align 8, !tbaa !5
  %202 = getelementptr inbounds %struct.rlite, ptr %201, i32 0, i32 6
  %203 = load i64, ptr %202, align 8, !tbaa !23
  %204 = mul nsw i64 %200, %203
  %205 = getelementptr inbounds i8, ptr %199, i64 %204
  %206 = call i32 %192(ptr noundef %193, ptr noundef %196, ptr noundef %205)
  store i32 %206, ptr %5, align 4, !tbaa !9
  br label %207

207:                                              ; preds = %187, %161
  br label %208

208:                                              ; preds = %207
  %209 = load i64, ptr %6, align 8, !tbaa !17
  %210 = add nsw i64 %209, 1
  store i64 %210, ptr %6, align 8, !tbaa !17
  br label %155, !llvm.loop !31

211:                                              ; preds = %155
  store i32 0, ptr %13, align 4
  br label %212

212:                                              ; preds = %211, %150
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  %213 = load i32, ptr %13, align 4
  switch i32 %213, label %227 [
    i32 0, label %214
    i32 2, label %217
  ]

214:                                              ; preds = %212
  br label %215

215:                                              ; preds = %214, %84
  br label %216

216:                                              ; preds = %215, %83
  br label %217

217:                                              ; preds = %216, %212, %81
  %218 = load ptr, ptr %4, align 8, !tbaa !5
  %219 = icmp ne ptr %218, null
  br i1 %219, label %220, label %223

220:                                              ; preds = %217
  %221 = load ptr, ptr %4, align 8, !tbaa !5
  %222 = call i32 @fclose(ptr noundef %221)
  br label %223

223:                                              ; preds = %220, %217
  %224 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %224) #6
  %225 = load ptr, ptr %9, align 8, !tbaa !5
  call void @free(ptr noundef %225) #6
  %226 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %226, ptr %2, align 4
  store i32 1, ptr %13, align 4
  br label %227

227:                                              ; preds = %223, %212, %81
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  %228 = load i32, ptr %2, align 4
  ret i32 %228
}

; Function Attrs: nounwind uwtable
declare hidden ptr @get_wal_filename(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @rl_apply_wal_data(ptr noundef, ptr noundef, i64 noundef, i32 noundef) #2

; Function Attrs: nounwind
declare i32 @ftruncate(i32 noundef, i64 noundef) #3

; Function Attrs: nounwind
declare i32 @fileno(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden i32 @rl_delete_wal(ptr noundef) #2

declare i32 @fflush(ptr noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind allocsize(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 #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nounwind }
attributes #7 = { nounwind allocsize(1) }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 64}
!12 = !{!"rlite", !13, i64 0, !13, i64 8, !10, i64 16, !6, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !6, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !6, i64 80, !13, i64 88, !13, i64 96, !6, i64 104, !13, i64 112, !13, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 56}
!15 = !{!16, !6, i64 8}
!16 = !{!"", !6, i64 0, !6, i64 8, !10, i64 16}
!17 = !{!13, !13, i64 0}
!18 = !{!12, !13, i64 120}
!19 = !{!16, !6, i64 0}
!20 = !{!12, !6, i64 128}
!21 = !{!22, !13, i64 0}
!22 = !{!"", !13, i64 0, !6, i64 8, !6, i64 16}
!23 = !{!12, !13, i64 48}
!24 = !{!25, !13, i64 8}
!25 = !{!"", !6, i64 0, !13, i64 8}
!26 = !{!25, !6, i64 0}
!27 = !{!22, !6, i64 8}
!28 = !{!29, !6, i64 8}
!29 = !{!"rl_data_type", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!30 = !{!22, !6, i64 16}
!31 = distinct !{!31, !32}
!32 = !{!"llvm.loop.mustprogress"}


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

@.str = external hidden unnamed_addr constant [3 x i8], align 1

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

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

declare i32 @rl_flock(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @rl_write_wal_file(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_write_apply_wal(ptr noundef %0) local_unnamed_addr #3 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #8
  store ptr null, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #8
  %4 = getelementptr inbounds i8, ptr %0, i64 64
  %5 = load i32, ptr %4, align 8, !tbaa !9
  switch i32 %5, label %.thread88 [
    i32 1, label %6
    i32 0, label %38
  ]

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 56
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  %11 = tail call ptr @get_wal_filename(ptr noundef %10)
  %12 = icmp eq ptr %11, null
  br i1 %12, label %.thread88, label %13

13:                                               ; preds = %6
  %14 = tail call noalias ptr @fopen(ptr noundef nonnull %11, ptr noundef nonnull @.str)
  %15 = icmp eq ptr %14, null
  br i1 %15, label %.thread88, label %16

16:                                               ; preds = %13
  %17 = tail call i32 @rl_flock(ptr noundef nonnull %14, i32 noundef 2) #8
  %.not81 = icmp eq i32 %17, 0
  br i1 %.not81, label %18, label %94

18:                                               ; preds = %16
  %19 = call i32 @rl_write_wal_file(ptr noundef nonnull %14, ptr noundef nonnull %0, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %.not82 = icmp eq i32 %19, 0
  br i1 %.not82, label %20, label %94

20:                                               ; preds = %18
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = load i64, ptr %3, align 8, !tbaa !16
  %23 = call i32 @rl_apply_wal_data(ptr noundef nonnull %0, ptr noundef %21, i64 noundef %22, i32 noundef 1)
  %.not83 = icmp eq i32 %23, 0
  br i1 %.not83, label %24, label %94

24:                                               ; preds = %20
  %25 = call i32 @fileno(ptr noundef nonnull %14) #8
  %26 = call i32 @ftruncate(i32 noundef %25, i64 noundef 0) #8
  %27 = call i32 @fclose(ptr noundef nonnull %14)
  %28 = call i32 @rl_delete_wal(ptr noundef nonnull %11)
  %.not84 = icmp eq i32 %28, 0
  br i1 %.not84, label %29, label %.thread88

29:                                               ; preds = %24
  %30 = getelementptr inbounds i8, ptr %0, i64 120
  %31 = load i64, ptr %30, align 8, !tbaa !17
  %32 = icmp sgt i64 %31, 0
  br i1 %32, label %33, label %36

33:                                               ; preds = %29
  %34 = load ptr, ptr %8, align 8, !tbaa !18
  %35 = call i32 @fflush(ptr noundef %34)
  br label %36

36:                                               ; preds = %33, %29
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %37) #8
  store ptr null, ptr %2, align 8, !tbaa !5
  br label %.thread88

38:                                               ; preds = %1
  %39 = getelementptr inbounds i8, ptr %0, i64 56
  %40 = load ptr, ptr %39, align 8, !tbaa !13
  %41 = getelementptr inbounds i8, ptr %0, i64 120
  %42 = load i64, ptr %41, align 8, !tbaa !17
  %43 = icmp sgt i64 %42, 0
  br i1 %43, label %44, label %.thread88

44:                                               ; preds = %38
  %45 = getelementptr inbounds i8, ptr %0, i64 128
  %46 = load ptr, ptr %45, align 8, !tbaa !19
  %47 = getelementptr ptr, ptr %46, i64 %42
  %48 = getelementptr i8, ptr %47, i64 -8
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  %50 = load i64, ptr %49, align 8, !tbaa !20
  %51 = add nsw i64 %50, 1
  %52 = getelementptr inbounds i8, ptr %0, i64 48
  %53 = load i64, ptr %52, align 8, !tbaa !22
  %54 = mul nsw i64 %51, %53
  %55 = getelementptr inbounds i8, ptr %40, i64 8
  %56 = load i64, ptr %55, align 8, !tbaa !23
  %57 = icmp sgt i64 %54, %56
  br i1 %57, label %58, label %.lr.ph

58:                                               ; preds = %44
  %59 = load ptr, ptr %40, align 8, !tbaa !25
  %60 = tail call ptr @realloc(ptr noundef %59, i64 noundef %54) #9
  %.not.not = icmp eq ptr %60, null
  br i1 %.not.not, label %.thread88, label %61

61:                                               ; preds = %58
  store ptr %60, ptr %40, align 8, !tbaa !25
  %62 = load i64, ptr %49, align 8, !tbaa !20
  %63 = add nsw i64 %62, 1
  %64 = load i64, ptr %52, align 8, !tbaa !22
  %65 = mul nsw i64 %63, %64
  store i64 %65, ptr %55, align 8, !tbaa !23
  %.pre = load i64, ptr %41, align 8, !tbaa !17
  %66 = icmp sgt i64 %.pre, 0
  br i1 %66, label %.lr.ph, label %.thread88

.lr.ph:                                           ; preds = %44, %61
  %67 = getelementptr inbounds i8, ptr %0, i64 128
  %68 = getelementptr inbounds i8, ptr %0, i64 48
  br label %69

69:                                               ; preds = %.lr.ph, %90
  %.396 = phi i32 [ 0, %.lr.ph ], [ %.4, %90 ]
  %.06795 = phi i64 [ 0, %.lr.ph ], [ %91, %90 ]
  %70 = load ptr, ptr %67, align 8, !tbaa !19
  %71 = getelementptr inbounds ptr, ptr %70, i64 %.06795
  %72 = load ptr, ptr %71, align 8, !tbaa !5
  %73 = load i64, ptr %72, align 8, !tbaa !20
  %74 = load ptr, ptr %40, align 8, !tbaa !25
  %75 = load i64, ptr %68, align 8, !tbaa !22
  %76 = mul nsw i64 %75, %73
  %77 = getelementptr inbounds i8, ptr %74, i64 %76
  tail call void @llvm.memset.p0.i64(ptr align 1 %77, i8 0, i64 %75, i1 false)
  %78 = getelementptr inbounds i8, ptr %72, i64 8
  %79 = load ptr, ptr %78, align 8, !tbaa !26
  %.not = icmp eq ptr %79, null
  br i1 %.not, label %90, label %80

80:                                               ; preds = %69
  %81 = getelementptr inbounds i8, ptr %79, i64 8
  %82 = load ptr, ptr %81, align 8, !tbaa !27
  %83 = getelementptr inbounds i8, ptr %72, i64 16
  %84 = load ptr, ptr %83, align 8, !tbaa !29
  %85 = load ptr, ptr %40, align 8, !tbaa !25
  %86 = load i64, ptr %68, align 8, !tbaa !22
  %87 = mul nsw i64 %86, %73
  %88 = getelementptr inbounds i8, ptr %85, i64 %87
  %89 = tail call i32 %82(ptr noundef nonnull %0, ptr noundef %84, ptr noundef %88) #8
  br label %90

90:                                               ; preds = %69, %80
  %.4 = phi i32 [ %89, %80 ], [ %.396, %69 ]
  %91 = add nuw nsw i64 %.06795, 1
  %92 = load i64, ptr %41, align 8, !tbaa !17
  %93 = icmp slt i64 %91, %92
  br i1 %93, label %69, label %.thread88, !llvm.loop !30

94:                                               ; preds = %20, %18, %16
  %.6 = phi i32 [ %17, %16 ], [ %19, %18 ], [ %23, %20 ]
  %95 = call i32 @fclose(ptr noundef nonnull %14)
  br label %.thread88

.thread88:                                        ; preds = %90, %38, %61, %58, %1, %24, %13, %6, %36, %94
  %.694 = phi i32 [ %.6, %94 ], [ 0, %1 ], [ %28, %24 ], [ 6, %13 ], [ 4, %6 ], [ 0, %36 ], [ 4, %58 ], [ 0, %61 ], [ 0, %38 ], [ %.4, %90 ]
  %.06693 = phi ptr [ %11, %94 ], [ null, %1 ], [ %11, %24 ], [ %11, %13 ], [ null, %6 ], [ %11, %36 ], [ null, %58 ], [ null, %61 ], [ null, %38 ], [ null, %90 ]
  %96 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %96) #8
  call void @free(ptr noundef %.06693) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #8
  ret i32 %.694
}

; Function Attrs: nounwind uwtable
declare hidden ptr @get_wal_filename(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden i32 @rl_apply_wal_data(ptr noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare i32 @ftruncate(i32 noundef, i64 noundef) local_unnamed_addr #4

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

; Function Attrs: nounwind uwtable
declare hidden i32 @rl_delete_wal(ptr noundef) local_unnamed_addr #3

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #5

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #6

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #7

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = { 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 #4 = { 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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #6 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, 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 #7 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #8 = { nounwind }
attributes #9 = { nounwind allocsize(1) }

!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, !12, i64 64}
!10 = !{!"rlite", !11, i64 0, !11, i64 8, !12, i64 16, !6, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !6, i64 56, !12, i64 64, !12, i64 68, !12, i64 72, !12, i64 76, !6, i64 80, !11, i64 88, !11, i64 96, !6, i64 104, !11, i64 112, !11, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 56}
!14 = !{!15, !6, i64 8}
!15 = !{!"", !6, i64 0, !6, i64 8, !12, i64 16}
!16 = !{!11, !11, i64 0}
!17 = !{!10, !11, i64 120}
!18 = !{!15, !6, i64 0}
!19 = !{!10, !6, i64 128}
!20 = !{!21, !11, i64 0}
!21 = !{!"", !11, i64 0, !6, i64 8, !6, i64 16}
!22 = !{!10, !11, i64 48}
!23 = !{!24, !11, i64 8}
!24 = !{!"", !6, i64 0, !11, i64 8}
!25 = !{!24, !6, i64 0}
!26 = !{!21, !6, i64 8}
!27 = !{!28, !6, i64 8}
!28 = !{!"rl_data_type", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!29 = !{!21, !6, i64 16}
!30 = distinct !{!30, !31}
!31 = !{!"llvm.loop.mustprogress"}


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