; LLVM IR from adventure-db/adventure :: src/db (adv)

; 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.adv_db = type { ptr, %struct.adv_meta, ptr, ptr }
%struct.adv_meta = type { [10 x i64], i64, i64, i64, i64, i64 }

@.str = external hidden unnamed_addr constant [6 x i8], align 1
@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [65 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [69 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [72 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @adv_open(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #7
  %10 = call ptr @sdsempty()
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call ptr (ptr, ptr, ...) @sdscatprintf(ptr noundef %10, ptr noundef @.str, ptr noundef %11)
  store ptr %12, ptr %7, align 8, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = and i32 %13, 1
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %36

16:                                               ; preds = %2
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = call i32 @fs_create_dir(ptr noundef %17)
  store i32 %18, ptr %6, align 4, !tbaa !9
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %35, label %21

21:                                               ; preds = %16
  %22 = load ptr, ptr @stderr, align 8, !tbaa !5
  %23 = call ptr @__errno_location() #8
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %21
  br label %31

27:                                               ; preds = %21
  %28 = call ptr @__errno_location() #8
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = call ptr @strerror(i32 noundef %29) #7
  br label %31

31:                                               ; preds = %27, %26
  %32 = phi ptr [ @.str.3, %26 ], [ %30, %27 ]
  %33 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 28, ptr noundef %32) #7
  %34 = call ptr @__errno_location() #8
  store i32 0, ptr %34, align 4, !tbaa !9
  br label %92

35:                                               ; preds = %16
  br label %36

36:                                               ; preds = %35, %2
  %37 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 144) #9
  store ptr %37, ptr %8, align 8, !tbaa !5
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = call ptr @sdsnew(ptr noundef %38)
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.adv_db, ptr %40, i32 0, i32 0
  store ptr %39, ptr %41, align 8, !tbaa !11
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = call ptr @adv_dbf_open(ptr noundef %42, ptr noundef @.str.4, i32 noundef %43)
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.adv_db, ptr %45, i32 0, i32 2
  store ptr %44, ptr %46, align 8, !tbaa !15
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.adv_db, ptr %47, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !15
  %50 = icmp ne ptr %49, null
  br i1 %50, label %65, label %51

51:                                               ; preds = %36
  %52 = load ptr, ptr @stderr, align 8, !tbaa !5
  %53 = call ptr @__errno_location() #8
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %56, label %57

56:                                               ; preds = %51
  br label %61

57:                                               ; preds = %51
  %58 = call ptr @__errno_location() #8
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = call ptr @strerror(i32 noundef %59) #7
  br label %61

61:                                               ; preds = %57, %56
  %62 = phi ptr [ @.str.3, %56 ], [ %60, %57 ]
  %63 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %52, ptr noundef @.str.5, ptr noundef @.str.2, i32 noundef 37, ptr noundef %62) #7
  %64 = call ptr @__errno_location() #8
  store i32 0, ptr %64, align 4, !tbaa !9
  br label %92

65:                                               ; preds = %36
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = load i32, ptr %5, align 4, !tbaa !9
  %68 = call ptr @adv_dbf_open(ptr noundef %66, ptr noundef @.str.6, i32 noundef %67)
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.adv_db, ptr %69, i32 0, i32 3
  store ptr %68, ptr %70, align 8, !tbaa !16
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.adv_db, ptr %71, i32 0, i32 3
  %73 = load ptr, ptr %72, align 8, !tbaa !16
  %74 = icmp ne ptr %73, null
  br i1 %74, label %89, label %75

75:                                               ; preds = %65
  %76 = load ptr, ptr @stderr, align 8, !tbaa !5
  %77 = call ptr @__errno_location() #8
  %78 = load i32, ptr %77, align 4, !tbaa !9
  %79 = icmp eq i32 %78, 0
  br i1 %79, label %80, label %81

80:                                               ; preds = %75
  br label %85

81:                                               ; preds = %75
  %82 = call ptr @__errno_location() #8
  %83 = load i32, ptr %82, align 4, !tbaa !9
  %84 = call ptr @strerror(i32 noundef %83) #7
  br label %85

85:                                               ; preds = %81, %80
  %86 = phi ptr [ @.str.3, %80 ], [ %84, %81 ]
  %87 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %76, ptr noundef @.str.7, ptr noundef @.str.2, i32 noundef 41, ptr noundef %86) #7
  %88 = call ptr @__errno_location() #8
  store i32 0, ptr %88, align 4, !tbaa !9
  br label %92

89:                                               ; preds = %65
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  call void @sdsfree(ptr noundef %90)
  %91 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %91, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %94

92:                                               ; preds = %85, %61, %31
  %93 = load ptr, ptr %7, align 8, !tbaa !5
  call void @sdsfree(ptr noundef %93)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %94

94:                                               ; preds = %92, %89
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  %95 = load ptr, ptr %3, align 8
  ret ptr %95
}

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

declare ptr @sdscatprintf(ptr noundef, ptr noundef, ...) #2

declare ptr @sdsempty() #2

declare i32 @fs_create_dir(ptr noundef) #2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #4

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

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

declare ptr @sdsnew(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @adv_dbf_open(ptr noundef, ptr noundef, i32 noundef) #6

declare void @sdsfree(ptr noundef) #2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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 willreturn memory(none) "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 allocsize(0,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 #6 = { inlinehint nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(none) }
attributes #9 = { nounwind allocsize(0,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, !6, i64 0}
!12 = !{!"adv_db", !6, i64 0, !13, i64 8, !6, i64 128, !6, i64 136}
!13 = !{!"adv_meta", !7, i64 0, !14, i64 80, !14, i64 88, !14, i64 96, !14, i64 104, !14, i64 112}
!14 = !{!"long", !7, i64 0}
!15 = !{!12, !6, i64 128}
!16 = !{!12, !6, i64 136}


; 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 [6 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [65 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [69 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [72 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @adv_open(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call ptr @sdsempty() #7
  %4 = tail call ptr (ptr, ptr, ...) @sdscatprintf(ptr noundef %3, ptr noundef nonnull @.str, ptr noundef %0) #7
  %5 = and i32 %1, 1
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %19, label %6

6:                                                ; preds = %2
  %7 = tail call i32 @fs_create_dir(ptr noundef %4) #7
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %19, label %9

9:                                                ; preds = %6
  %10 = load ptr, ptr @stderr, align 8, !tbaa !5
  %11 = tail call ptr @__errno_location() #8
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %16, label %14

14:                                               ; preds = %9
  %15 = tail call ptr @strerror(i32 noundef %12) #7
  br label %16

16:                                               ; preds = %9, %14
  %17 = phi ptr [ %15, %14 ], [ @.str.3, %9 ]
  %18 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %10, ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef 28, ptr noundef %17) #9
  br label %47

19:                                               ; preds = %6, %2
  %20 = tail call noalias dereferenceable_or_null(144) ptr @calloc(i64 noundef 1, i64 noundef 144) #10
  %21 = tail call ptr @sdsnew(ptr noundef %0) #7
  store ptr %21, ptr %20, align 8, !tbaa !11
  %22 = tail call ptr @adv_dbf_open(ptr noundef %4, ptr noundef nonnull @.str.4, i32 noundef %1)
  %23 = getelementptr inbounds i8, ptr %20, i64 128
  store ptr %22, ptr %23, align 8, !tbaa !15
  %.not20 = icmp eq ptr %22, null
  br i1 %.not20, label %24, label %34

24:                                               ; preds = %19
  %25 = load ptr, ptr @stderr, align 8, !tbaa !5
  %26 = tail call ptr @__errno_location() #8
  %27 = load i32, ptr %26, align 4, !tbaa !9
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %31, label %29

29:                                               ; preds = %24
  %30 = tail call ptr @strerror(i32 noundef %27) #7
  br label %31

31:                                               ; preds = %24, %29
  %32 = phi ptr [ %30, %29 ], [ @.str.3, %24 ]
  %33 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.2, i32 noundef 37, ptr noundef %32) #9
  br label %47

34:                                               ; preds = %19
  %35 = tail call ptr @adv_dbf_open(ptr noundef %4, ptr noundef nonnull @.str.6, i32 noundef %1)
  %36 = getelementptr inbounds i8, ptr %20, i64 136
  store ptr %35, ptr %36, align 8, !tbaa !16
  %.not21 = icmp eq ptr %35, null
  br i1 %.not21, label %37, label %48

37:                                               ; preds = %34
  %38 = load ptr, ptr @stderr, align 8, !tbaa !5
  %39 = tail call ptr @__errno_location() #8
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = icmp eq i32 %40, 0
  br i1 %41, label %44, label %42

42:                                               ; preds = %37
  %43 = tail call ptr @strerror(i32 noundef %40) #7
  br label %44

44:                                               ; preds = %37, %42
  %45 = phi ptr [ %43, %42 ], [ @.str.3, %37 ]
  %46 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %38, ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.2, i32 noundef 41, ptr noundef %45) #9
  br label %47

47:                                               ; preds = %44, %31, %16
  %.sink = phi ptr [ %39, %44 ], [ %26, %31 ], [ %11, %16 ]
  store i32 0, ptr %.sink, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %34, %47
  %.0 = phi ptr [ null, %47 ], [ %20, %34 ]
  tail call void @sdsfree(ptr noundef %4) #7
  ret ptr %.0
}

declare ptr @sdscatprintf(ptr noundef, ptr noundef, ...) local_unnamed_addr #1

declare ptr @sdsempty() local_unnamed_addr #1

declare i32 @fs_create_dir(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #3

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #4

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

declare ptr @sdsnew(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @adv_dbf_open(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #6

declare void @sdsfree(ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #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 = { 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 #3 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) 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 #6 = { inlinehint nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(none) }
attributes #9 = { cold nounwind }
attributes #10 = { nounwind allocsize(0,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, !6, i64 0}
!12 = !{!"adv_db", !6, i64 0, !13, i64 8, !6, i64 128, !6, i64 136}
!13 = !{!"adv_meta", !7, i64 0, !14, i64 80, !14, i64 88, !14, i64 96, !14, i64 104, !14, i64 112}
!14 = !{!"long", !7, i64 0}
!15 = !{!12, !6, i64 128}
!16 = !{!12, !6, i64 136}


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