; LLVM IR from xdevelnet/libsdb :: libsdb (sdb_open_fileno)

; 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.sdb_dbo_s = type { i32, ptr, ptr, i64, i64, i64, i64, %struct.sdb_defun }
%struct.sdb_defun = type { ptr, ptr, ptr, ptr, ptr }

@omit_buffer_size = external dso_local global i64, align 8
@my_calloc = external dso_local global ptr, align 8
@my_free = external dso_local global ptr, align 8
@.str = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @sdb_insert_fileno(ptr noundef, ptr noundef, ptr noundef) #0

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @sdb_update_fileno(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @sdb_select_fileno(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @sdb_delete_fileno(ptr noundef, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @sdb_open_fileno(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = icmp ne i32 %10, 1
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  br label %88

13:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store i64 0, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %14 = load i64, ptr @omit_buffer_size, align 8, !tbaa !11
  %15 = icmp ugt i64 %14, 0
  br i1 %15, label %16, label %18

16:                                               ; preds = %13
  %17 = load i64, ptr @omit_buffer_size, align 8, !tbaa !11
  store i64 %17, ptr %7, align 8, !tbaa !11
  br label %19

18:                                               ; preds = %13
  store i64 65535, ptr %7, align 8, !tbaa !11
  br label %19

19:                                               ; preds = %18, %16
  store i64 0, ptr @omit_buffer_size, align 8, !tbaa !11
  %20 = load ptr, ptr %5, align 8, !tbaa !9
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %26

22:                                               ; preds = %19
  %23 = load ptr, ptr %5, align 8, !tbaa !9
  %24 = call i64 @strlen(ptr noundef %23) #6
  %25 = add i64 %24, 1
  store i64 %25, ptr %6, align 8, !tbaa !11
  br label %26

26:                                               ; preds = %22, %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %27 = load ptr, ptr @my_calloc, align 8, !tbaa !9
  %28 = load i64, ptr %6, align 8, !tbaa !11
  %29 = add i64 96, %28
  %30 = load i64, ptr %7, align 8, !tbaa !11
  %31 = add i64 %29, %30
  %32 = call ptr %27(i64 noundef %31, i64 noundef 1)
  store ptr %32, ptr %8, align 8, !tbaa !9
  %33 = load ptr, ptr %8, align 8, !tbaa !9
  %34 = icmp eq ptr %33, null
  br i1 %34, label %35, label %36

35:                                               ; preds = %26
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %87

36:                                               ; preds = %26
  %37 = load ptr, ptr %5, align 8, !tbaa !9
  %38 = icmp eq ptr %37, null
  br i1 %38, label %39, label %42

39:                                               ; preds = %36
  %40 = load ptr, ptr %8, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.sdb_dbo_s, ptr %40, i32 0, i32 1
  store ptr @.str, ptr %41, align 8, !tbaa !13
  br label %49

42:                                               ; preds = %36
  %43 = load ptr, ptr %8, align 8, !tbaa !9
  %44 = getelementptr inbounds i8, ptr %43, i64 96
  %45 = load ptr, ptr %5, align 8, !tbaa !9
  %46 = load i64, ptr %6, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %44, ptr align 1 %45, i64 %46, i1 false)
  %47 = load ptr, ptr %8, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.sdb_dbo_s, ptr %47, i32 0, i32 1
  store ptr %44, ptr %48, align 8, !tbaa !13
  br label %49

49:                                               ; preds = %42, %39
  %50 = load i64, ptr %6, align 8, !tbaa !11
  %51 = add i64 %50, 96
  %52 = load ptr, ptr %8, align 8, !tbaa !9
  %53 = getelementptr inbounds i8, ptr %52, i64 %51
  %54 = load ptr, ptr %8, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.sdb_dbo_s, ptr %54, i32 0, i32 2
  store ptr %53, ptr %55, align 8, !tbaa !16
  %56 = load i64, ptr %7, align 8, !tbaa !11
  %57 = load ptr, ptr %8, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.sdb_dbo_s, ptr %57, i32 0, i32 4
  store i64 %56, ptr %58, align 8, !tbaa !17
  %59 = load ptr, ptr %8, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.sdb_dbo_s, ptr %59, i32 0, i32 1
  %61 = load ptr, ptr %60, align 8, !tbaa !13
  %62 = call i32 @access(ptr noundef %61, i32 noundef 2) #5
  %63 = icmp eq i32 %62, 0
  br i1 %63, label %64, label %84

64:                                               ; preds = %49
  %65 = load ptr, ptr %8, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.sdb_dbo_s, ptr %65, i32 0, i32 7
  %67 = getelementptr inbounds %struct.sdb_defun, ptr %66, i32 0, i32 0
  store ptr @sdb_insert_fileno, ptr %67, align 8, !tbaa !18
  %68 = load ptr, ptr %8, align 8, !tbaa !9
  %69 = getelementptr inbounds %struct.sdb_dbo_s, ptr %68, i32 0, i32 7
  %70 = getelementptr inbounds %struct.sdb_defun, ptr %69, i32 0, i32 1
  store ptr @sdb_update_fileno, ptr %70, align 8, !tbaa !19
  %71 = load ptr, ptr %8, align 8, !tbaa !9
  %72 = getelementptr inbounds %struct.sdb_dbo_s, ptr %71, i32 0, i32 7
  %73 = getelementptr inbounds %struct.sdb_defun, ptr %72, i32 0, i32 2
  store ptr @sdb_select_fileno, ptr %73, align 8, !tbaa !20
  %74 = load ptr, ptr %8, align 8, !tbaa !9
  %75 = getelementptr inbounds %struct.sdb_dbo_s, ptr %74, i32 0, i32 7
  %76 = getelementptr inbounds %struct.sdb_defun, ptr %75, i32 0, i32 3
  store ptr @sdb_delete_fileno, ptr %76, align 8, !tbaa !21
  %77 = load ptr, ptr %8, align 8, !tbaa !9
  %78 = getelementptr inbounds %struct.sdb_dbo_s, ptr %77, i32 0, i32 7
  %79 = getelementptr inbounds %struct.sdb_defun, ptr %78, i32 0, i32 4
  store ptr @sdb_exist_fileno, ptr %79, align 8, !tbaa !22
  %80 = load i32, ptr %4, align 4, !tbaa !5
  %81 = load ptr, ptr %8, align 8, !tbaa !9
  %82 = getelementptr inbounds %struct.sdb_dbo_s, ptr %81, i32 0, i32 0
  store i32 %80, ptr %82, align 8, !tbaa !23
  %83 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %83, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %87

84:                                               ; preds = %49
  %85 = load ptr, ptr @my_free, align 8, !tbaa !9
  %86 = load ptr, ptr %8, align 8, !tbaa !9
  call void %85(ptr noundef %86)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %87

87:                                               ; preds = %84, %64, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %88

88:                                               ; preds = %87, %12
  %89 = load ptr, ptr %3, align 8
  ret ptr %89
}

; 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

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 = { nounwind willreturn 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 "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 willreturn memory(read) }

!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 = !{!"int", !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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"sdb_dbo_s", !6, i64 0, !10, i64 8, !10, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !15, i64 56}
!15 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!16 = !{!14, !10, i64 16}
!17 = !{!14, !12, i64 32}
!18 = !{!14, !10, i64 56}
!19 = !{!14, !10, i64 64}
!20 = !{!14, !10, i64 72}
!21 = !{!14, !10, i64 80}
!22 = !{!14, !10, i64 88}
!23 = !{!14, !6, i64 0}


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

@omit_buffer_size = external dso_local local_unnamed_addr global i64, align 8
@my_calloc = external dso_local local_unnamed_addr global ptr, align 8
@my_free = external dso_local local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @sdb_insert_fileno(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @sdb_update_fileno(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @sdb_select_fileno(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @sdb_delete_fileno(ptr noundef, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @sdb_open_fileno(i32 noundef %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %.not = icmp eq i32 %0, 1
  br i1 %.not, label %3, label %32

3:                                                ; preds = %2
  %4 = load i64, ptr @omit_buffer_size, align 8, !tbaa !5
  %.not34 = icmp eq i64 %4, 0
  %. = select i1 %.not34, i64 65535, i64 %4
  store i64 0, ptr @omit_buffer_size, align 8, !tbaa !5
  %.not35 = icmp eq ptr %1, null
  br i1 %.not35, label %8, label %5

5:                                                ; preds = %3
  %6 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #4
  %7 = add i64 %6, 1
  br label %8

8:                                                ; preds = %5, %3
  %.028 = phi i64 [ %7, %5 ], [ 0, %3 ]
  %9 = load ptr, ptr @my_calloc, align 8, !tbaa !9
  %10 = add i64 %.028, 96
  %11 = add i64 %10, %.
  %12 = tail call ptr %9(i64 noundef %11, i64 noundef 1) #5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %32, label %14

14:                                               ; preds = %8
  br i1 %.not35, label %17, label %15

15:                                               ; preds = %14
  %16 = getelementptr inbounds i8, ptr %12, i64 96
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %16, ptr nonnull align 1 %1, i64 %.028, i1 false)
  br label %17

17:                                               ; preds = %14, %15
  %.sink = phi ptr [ %16, %15 ], [ @.str, %14 ]
  %18 = getelementptr inbounds i8, ptr %12, i64 8
  store ptr %.sink, ptr %18, align 8
  %19 = getelementptr inbounds i8, ptr %12, i64 %10
  %20 = getelementptr inbounds i8, ptr %12, i64 16
  store ptr %19, ptr %20, align 8, !tbaa !11
  %21 = getelementptr inbounds i8, ptr %12, i64 32
  store i64 %., ptr %21, align 8, !tbaa !15
  %22 = tail call i32 @access(ptr noundef nonnull %.sink, i32 noundef 2) #5
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %30

24:                                               ; preds = %17
  %25 = getelementptr inbounds i8, ptr %12, i64 56
  store ptr @sdb_insert_fileno, ptr %25, align 8, !tbaa !16
  %26 = getelementptr inbounds i8, ptr %12, i64 64
  store ptr @sdb_update_fileno, ptr %26, align 8, !tbaa !17
  %27 = getelementptr inbounds i8, ptr %12, i64 72
  store ptr @sdb_select_fileno, ptr %27, align 8, !tbaa !18
  %28 = getelementptr inbounds i8, ptr %12, i64 80
  store ptr @sdb_delete_fileno, ptr %28, align 8, !tbaa !19
  %29 = getelementptr inbounds i8, ptr %12, i64 88
  store ptr @sdb_exist_fileno, ptr %29, align 8, !tbaa !20
  store i32 1, ptr %12, align 8, !tbaa !21
  br label %32

30:                                               ; preds = %17
  %31 = load ptr, ptr @my_free, align 8, !tbaa !9
  tail call void %31(ptr noundef nonnull %12) #5
  br label %32

32:                                               ; preds = %24, %30, %8, %2
  %.1 = phi ptr [ null, %2 ], [ %12, %24 ], [ null, %30 ], [ null, %8 ]
  ret ptr %.1
}

; 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

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 = { mustprogress nofree nounwind willreturn memory(argmem: 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 #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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind willreturn memory(read) }
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 16}
!12 = !{!"sdb_dbo_s", !13, i64 0, !10, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !14, i64 56}
!13 = !{!"int", !7, i64 0}
!14 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!15 = !{!12, !6, i64 32}
!16 = !{!12, !10, i64 56}
!17 = !{!12, !10, i64 64}
!18 = !{!12, !10, i64 72}
!19 = !{!12, !10, i64 80}
!20 = !{!12, !10, i64 88}
!21 = !{!12, !13, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass