; LLVM IR from recrsn/tinydb :: database (table_to_temp_table)

; 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.table_info = type { [32 x i8], i32, [32 x %struct.field], i64 }
%struct.field = type { [32 x i8], i64, i32 }
%struct.table = type { %struct.table_info, i8, ptr, ptr }

; 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

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @row_size(ptr noundef byval(%struct.table_info) align 8) #2

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @seek_pos(ptr noundef byval(%struct.table_info) align 8, i64 noundef, i32 noundef) #2

declare i32 @fseek(ptr noundef, i64 noundef, i32 noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @table_to_temp_table(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.table, ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds %struct.table_info, ptr %12, i32 0, i32 1
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.table, ptr %15, i32 0, i32 0
  %17 = getelementptr inbounds %struct.table_info, ptr %16, i32 0, i32 2
  %18 = getelementptr inbounds [32 x %struct.field], ptr %17, i64 0, i64 0
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.table, ptr %19, i32 0, i32 0
  %21 = getelementptr inbounds %struct.table_info, ptr %20, i32 0, i32 3
  %22 = load i64, ptr %21, align 8, !tbaa !15
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = call i64 @count_included_rows(i64 noundef %22, ptr noundef %23)
  %25 = call ptr @create_temp_table(i32 noundef %14, ptr noundef %18, i64 noundef %24)
  store ptr %25, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !16
  br label %26

26:                                               ; preds = %76, %2
  %27 = load i64, ptr %7, align 8, !tbaa !16
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.table, ptr %28, i32 0, i32 0
  %30 = getelementptr inbounds %struct.table_info, ptr %29, i32 0, i32 3
  %31 = load i64, ptr %30, align 8, !tbaa !15
  %32 = icmp ult i64 %27, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %79

34:                                               ; preds = %26
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = load i64, ptr %7, align 8, !tbaa !16
  %37 = getelementptr inbounds i8, ptr %35, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !17, !range !18, !noundef !19
  %39 = trunc i8 %38 to i1
  br i1 %39, label %40, label %75

40:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.table, ptr %41, i32 0, i32 0
  %43 = getelementptr inbounds %struct.table_info, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 8, !tbaa !9
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.table, ptr %45, i32 0, i32 0
  %47 = getelementptr inbounds %struct.table_info, ptr %46, i32 0, i32 2
  %48 = getelementptr inbounds [32 x %struct.field], ptr %47, i64 0, i64 0
  %49 = load i64, ptr %6, align 8, !tbaa !16
  %50 = add i64 %49, 1
  store i64 %50, ptr %6, align 8, !tbaa !16
  %51 = call i64 @mem_offset(i32 noundef %44, ptr noundef %48, i64 noundef %49, i32 noundef 0)
  store i64 %51, ptr %8, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.table, ptr %52, i32 0, i32 0
  %54 = load i64, ptr %7, align 8, !tbaa !16
  %55 = call i64 @seek_pos(ptr noundef byval(%struct.table_info) align 8 %53, i64 noundef %54, i32 noundef 0)
  store i64 %55, ptr %9, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.table, ptr %56, i32 0, i32 0
  %58 = call i64 @row_size(ptr noundef byval(%struct.table_info) align 8 %57)
  %59 = mul i64 %58, 1
  store i64 %59, ptr %10, align 8, !tbaa !16
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.table, ptr %60, i32 0, i32 2
  %62 = load ptr, ptr %61, align 8, !tbaa !20
  %63 = load i64, ptr %9, align 8, !tbaa !16
  %64 = call i32 @fseek(ptr noundef %62, i64 noundef %63, i32 noundef 0)
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.table, ptr %65, i32 0, i32 3
  %67 = load ptr, ptr %66, align 8, !tbaa !21
  %68 = load i64, ptr %8, align 8, !tbaa !16
  %69 = getelementptr inbounds i8, ptr %67, i64 %68
  %70 = load i64, ptr %10, align 8, !tbaa !16
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.table, ptr %71, i32 0, i32 2
  %73 = load ptr, ptr %72, align 8, !tbaa !20
  %74 = call i64 @fread(ptr noundef %69, i64 noundef %70, i64 noundef 1, ptr noundef %73)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %75

75:                                               ; preds = %40, %34
  br label %76

76:                                               ; preds = %75
  %77 = load i64, ptr %7, align 8, !tbaa !16
  %78 = add i64 %77, 1
  store i64 %78, ptr %7, align 8, !tbaa !16
  br label %26, !llvm.loop !22

79:                                               ; preds = %33
  %80 = load i64, ptr %6, align 8, !tbaa !16
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.table, ptr %81, i32 0, i32 0
  %83 = getelementptr inbounds %struct.table_info, ptr %82, i32 0, i32 3
  store i64 %80, ptr %83, align 8, !tbaa !15
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret ptr %84
}

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 }

!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 32}
!10 = !{!"", !11, i64 0, !14, i64 1584, !6, i64 1592, !6, i64 1600}
!11 = !{!"", !7, i64 0, !12, i64 32, !7, i64 40, !13, i64 1576}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!10, !13, i64 1576}
!16 = !{!13, !13, i64 0}
!17 = !{!14, !14, i64 0}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!10, !6, i64 1592}
!21 = !{!10, !6, i64 1600}
!22 = distinct !{!22, !23}
!23 = !{!"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"

%struct.table_info = type { [32 x i8], i32, [32 x %struct.field], i64 }
%struct.field = type { [32 x i8], i64, i32 }

; Function Attrs: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @row_size(ptr noundef byval(%struct.table_info) align 8) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @seek_pos(ptr noundef byval(%struct.table_info) align 8, i64 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fseek(ptr nocapture noundef, i64 noundef, i32 noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @table_to_temp_table(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 40
  %6 = getelementptr inbounds i8, ptr %0, i64 1576
  %7 = load i64, ptr %6, align 8, !tbaa !14
  %8 = tail call i64 @count_included_rows(i64 noundef %7, ptr noundef %1)
  %9 = tail call ptr @create_temp_table(i32 noundef %4, ptr noundef nonnull %5, i64 noundef %8)
  %10 = load i64, ptr %6, align 8, !tbaa !14
  %.not = icmp eq i64 %10, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %11 = getelementptr inbounds i8, ptr %0, i64 1592
  %12 = getelementptr inbounds i8, ptr %9, i64 1600
  br label %14

._crit_edge:                                      ; preds = %31, %2
  %.0.lcssa = phi i64 [ 0, %2 ], [ %.1, %31 ]
  %13 = getelementptr inbounds i8, ptr %9, i64 1576
  store i64 %.0.lcssa, ptr %13, align 8, !tbaa !14
  ret ptr %9

14:                                               ; preds = %.lr.ph, %31
  %15 = phi i64 [ %10, %.lr.ph ], [ %32, %31 ]
  %.025 = phi i64 [ 0, %.lr.ph ], [ %.1, %31 ]
  %.02324 = phi i64 [ 0, %.lr.ph ], [ %33, %31 ]
  %16 = getelementptr inbounds i8, ptr %1, i64 %.02324
  %17 = load i8, ptr %16, align 1, !tbaa !15, !range !16, !noundef !17
  %18 = trunc nuw i8 %17 to i1
  br i1 %18, label %19, label %31

19:                                               ; preds = %14
  %20 = load i32, ptr %3, align 8, !tbaa !5
  %21 = add i64 %.025, 1
  %22 = tail call i64 @mem_offset(i32 noundef %20, ptr noundef nonnull %5, i64 noundef %.025, i32 noundef 0)
  %23 = tail call i64 @seek_pos(ptr noundef nonnull byval(%struct.table_info) align 8 %0, i64 noundef %.02324, i32 noundef 0)
  %24 = tail call i64 @row_size(ptr noundef nonnull byval(%struct.table_info) align 8 %0)
  %25 = load ptr, ptr %11, align 8, !tbaa !18
  %26 = tail call i32 @fseek(ptr noundef %25, i64 noundef %23, i32 noundef 0)
  %27 = load ptr, ptr %12, align 8, !tbaa !19
  %28 = getelementptr inbounds i8, ptr %27, i64 %22
  %29 = load ptr, ptr %11, align 8, !tbaa !18
  %30 = tail call i64 @fread(ptr noundef %28, i64 noundef %24, i64 noundef 1, ptr noundef %29)
  %.pre = load i64, ptr %6, align 8, !tbaa !14
  br label %31

31:                                               ; preds = %14, %19
  %32 = phi i64 [ %.pre, %19 ], [ %15, %14 ]
  %.1 = phi i64 [ %21, %19 ], [ %.025, %14 ]
  %33 = add nuw i64 %.02324, 1
  %34 = icmp ult i64 %33, %32
  br i1 %34, label %14, label %._crit_edge, !llvm.loop !20
}

attributes #0 = { 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 #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" }

!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, !10, i64 32}
!6 = !{!"", !7, i64 0, !12, i64 1584, !13, i64 1592, !13, i64 1600}
!7 = !{!"", !8, i64 0, !10, i64 32, !8, i64 40, !11, i64 1576}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"_Bool", !8, i64 0}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!6, !11, i64 1576}
!15 = !{!12, !12, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!6, !13, i64 1592}
!19 = !{!6, !13, i64 1600}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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