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

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

@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [13 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

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

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #1

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

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

; Function Attrs: nounwind
declare i32 @ferror(ptr noundef) #1

declare i32 @fclose(ptr noundef) #2

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

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @open_index(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [4096 x i8], align 16
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %9 = call noalias ptr @malloc(i64 noundef 1608) #6
  store ptr %9, ptr %4, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.table, ptr %10, i32 0, i32 1
  store i8 1, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4096, ptr %5) #5
  %12 = getelementptr inbounds [4096 x i8], ptr %5, i64 0, i64 0
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %12, ptr noundef @.str.22, ptr noundef %13) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %15 = getelementptr inbounds [4096 x i8], ptr %5, i64 0, i64 0
  %16 = call noalias ptr @fopen(ptr noundef %15, ptr noundef @.str.4)
  store ptr %16, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.table, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = call i64 @fread(ptr noundef %18, i64 noundef 1584, i64 noundef 1, ptr noundef %19)
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = call i32 @ferror(ptr noundef %21) #5
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %26

24:                                               ; preds = %1
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %25) #5
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %66

26:                                               ; preds = %1
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = call i32 @fclose(ptr noundef %27)
  %29 = getelementptr inbounds [4096 x i8], ptr %5, i64 0, i64 0
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %29, ptr noundef @.str.23, ptr noundef %30) #5
  %32 = getelementptr inbounds [4096 x i8], ptr %5, i64 0, i64 0
  %33 = call noalias ptr @fopen(ptr noundef %32, ptr noundef @.str.4)
  store ptr %33, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.table, ptr %34, i32 0, i32 0
  %36 = call i64 @row_size(ptr noundef byval(%struct.table_info) align 8 %35)
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.table, ptr %37, i32 0, i32 0
  %39 = getelementptr inbounds %struct.table_info, ptr %38, i32 0, i32 3
  %40 = load i64, ptr %39, align 8, !tbaa !15
  %41 = mul i64 %36, %40
  %42 = mul i64 %41, 1
  store i64 %42, ptr %8, align 8, !tbaa !16
  %43 = load i64, ptr %8, align 8, !tbaa !16
  %44 = call noalias ptr @malloc(i64 noundef %43) #6
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.table, ptr %45, i32 0, i32 3
  store ptr %44, ptr %46, align 8, !tbaa !17
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.table, ptr %47, i32 0, i32 3
  %49 = load ptr, ptr %48, align 8, !tbaa !17
  %50 = load i64, ptr %8, align 8, !tbaa !16
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = call i64 @fread(ptr noundef %49, i64 noundef %50, i64 noundef 1, ptr noundef %51)
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = call i32 @ferror(ptr noundef %53) #5
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %61

56:                                               ; preds = %26
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.table, ptr %57, i32 0, i32 3
  %59 = load ptr, ptr %58, align 8, !tbaa !17
  call void @free(ptr noundef %59) #5
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %60) #5
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %65

61:                                               ; preds = %26
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = call i32 @fclose(ptr noundef %62)
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %64, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %65

65:                                               ; preds = %61, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %66

66:                                               ; preds = %65, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4096, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %67 = load ptr, ptr %2, align 8
  ret ptr %67
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 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 #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, !14, i64 1584}
!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 = !{!10, !6, i64 1600}


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

@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [13 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

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

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

; Function Attrs: nofree nounwind memory(read)
declare noundef i32 @ferror(ptr nocapture noundef) local_unnamed_addr #2

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

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

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

; 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: nounwind uwtable
define dso_local noundef ptr @open_index(ptr noundef %0) local_unnamed_addr #3 {
  %2 = alloca [4096 x i8], align 16
  %3 = tail call noalias dereferenceable_or_null(1608) ptr @malloc(i64 noundef 1608) #6
  %4 = getelementptr inbounds i8, ptr %3, i64 1584
  store i8 1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4096, ptr nonnull %2) #7
  %5 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %2, ptr noundef nonnull dereferenceable(1) @.str.22, ptr noundef %0) #7
  %6 = call noalias ptr @fopen(ptr noundef nonnull %2, ptr noundef nonnull @.str.4)
  %7 = tail call i64 @fread(ptr noundef %3, i64 noundef 1584, i64 noundef 1, ptr noundef %6)
  %8 = tail call i32 @ferror(ptr noundef %6) #7
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %10, label %9

9:                                                ; preds = %1
  tail call void @free(ptr noundef nonnull %3) #7
  br label %26

10:                                               ; preds = %1
  %11 = tail call i32 @fclose(ptr noundef %6)
  %12 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %2, ptr noundef nonnull dereferenceable(1) @.str.23, ptr noundef %0) #7
  %13 = call noalias ptr @fopen(ptr noundef nonnull %2, ptr noundef nonnull @.str.4)
  %14 = tail call i64 @row_size(ptr noundef nonnull byval(%struct.table_info) align 8 %3)
  %15 = getelementptr inbounds i8, ptr %3, i64 1576
  %16 = load i64, ptr %15, align 8, !tbaa !14
  %17 = mul i64 %16, %14
  %18 = tail call noalias ptr @malloc(i64 noundef %17) #6
  %19 = getelementptr inbounds i8, ptr %3, i64 1600
  store ptr %18, ptr %19, align 8, !tbaa !15
  %20 = tail call i64 @fread(ptr noundef %18, i64 noundef %17, i64 noundef 1, ptr noundef %13)
  %21 = tail call i32 @ferror(ptr noundef %13) #7
  %.not20 = icmp eq i32 %21, 0
  br i1 %.not20, label %24, label %22

22:                                               ; preds = %10
  %23 = load ptr, ptr %19, align 8, !tbaa !15
  tail call void @free(ptr noundef %23) #7
  tail call void @free(ptr noundef nonnull %3) #7
  br label %26

24:                                               ; preds = %10
  %25 = tail call i32 @fclose(ptr noundef %13)
  br label %26

26:                                               ; preds = %22, %24, %9
  %.1 = phi ptr [ null, %9 ], [ null, %22 ], [ %3, %24 ]
  call void @llvm.lifetime.end.p0(i64 4096, ptr nonnull %2) #7
  ret ptr %.1
}

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 = { nofree nounwind memory(read) "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 = { 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 #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 = { nounwind allocsize(0) }
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, !12, i64 1584}
!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 = !{!6, !13, i64 1600}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass