; LLVM IR from Discngine/fpocket :: src (writepocket)

; 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.c_lst_pockets = type { ptr, ptr, ptr, i64, ptr }
%struct.node_pocket = type { ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [21 x i8], align 1
@write_mode = external global [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [24 x i8], align 1
@stderr = external global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [36 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @write_each_pocket_for_DB(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = call i64 @strlen(ptr noundef %12) #6
  %14 = trunc i64 %13 to i32
  store i32 %14, ptr %7, align 4, !tbaa !9
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = add nsw i32 %15, 20
  %17 = zext i32 %16 to i64
  %18 = call ptr @llvm.stacksave.p0()
  store ptr %18, ptr %8, align 8
  %19 = alloca i8, i64 %17, align 16
  store i64 %17, ptr %9, align 8
  %20 = getelementptr inbounds i8, ptr %19, i64 0
  store i8 0, ptr %20, align 16, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !9
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %92

23:                                               ; preds = %3
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.c_lst_pockets, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !12
  store ptr %26, ptr %10, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %85, %23
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %91

30:                                               ; preds = %27
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i32, ptr %11, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  %34 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %19, ptr noundef @.str, ptr noundef %31, i32 noundef %33) #5
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.node_pocket, ptr %35, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !15
  call void @write_pocket_pqr_DB(ptr noundef %19, ptr noundef %37)
  %38 = load i8, ptr @write_mode, align 1, !tbaa !11
  %39 = sext i8 %38 to i32
  %40 = icmp eq i32 %39, 112
  br i1 %40, label %45, label %41

41:                                               ; preds = %30
  %42 = load i8, ptr @write_mode, align 1, !tbaa !11
  %43 = sext i8 %42 to i32
  %44 = icmp eq i32 %43, 98
  br i1 %44, label %45, label %61

45:                                               ; preds = %41, %30
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load i32, ptr %11, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  %49 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %19, ptr noundef @.str.1, ptr noundef %46, i32 noundef %48) #5
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.node_pocket, ptr %50, i32 0, i32 2
  %52 = load ptr, ptr %51, align 8, !tbaa !15
  call void @write_pocket_pdb(ptr noundef %19, ptr noundef %52)
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = add nsw i32 %54, 1
  %56 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %19, ptr noundef @.str.2, ptr noundef %53, i32 noundef %55) #5
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.node_pocket, ptr %57, i32 0, i32 2
  %59 = load ptr, ptr %58, align 8, !tbaa !15
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  call void @write_pocket_pdb_DB(ptr noundef %19, ptr noundef %59, ptr noundef %60)
  br label %61

61:                                               ; preds = %45, %41
  %62 = load i8, ptr @write_mode, align 1, !tbaa !11
  %63 = sext i8 %62 to i32
  %64 = icmp eq i32 %63, 109
  br i1 %64, label %69, label %65

65:                                               ; preds = %61
  %66 = load i8, ptr @write_mode, align 1, !tbaa !11
  %67 = sext i8 %66 to i32
  %68 = icmp eq i32 %67, 98
  br i1 %68, label %69, label %85

69:                                               ; preds = %65, %61
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = load i32, ptr %11, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  %73 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %19, ptr noundef @.str.3, ptr noundef %70, i32 noundef %72) #5
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.node_pocket, ptr %74, i32 0, i32 2
  %76 = load ptr, ptr %75, align 8, !tbaa !15
  call void @write_pocket_mmcif(ptr noundef %19, ptr noundef %76)
  %77 = load ptr, ptr %4, align 8, !tbaa !5
  %78 = load i32, ptr %11, align 4, !tbaa !9
  %79 = add nsw i32 %78, 1
  %80 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %19, ptr noundef @.str.4, ptr noundef %77, i32 noundef %79) #5
  %81 = load ptr, ptr %10, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.node_pocket, ptr %81, i32 0, i32 2
  %83 = load ptr, ptr %82, align 8, !tbaa !15
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  call void @write_pocket_mmcif_DB(ptr noundef %19, ptr noundef %83, ptr noundef %84)
  br label %85

85:                                               ; preds = %69, %65
  %86 = load ptr, ptr %10, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.node_pocket, ptr %86, i32 0, i32 0
  %88 = load ptr, ptr %87, align 8, !tbaa !17
  store ptr %88, ptr %10, align 8, !tbaa !5
  %89 = load i32, ptr %11, align 4, !tbaa !9
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %11, align 4, !tbaa !9
  br label %27, !llvm.loop !18

91:                                               ; preds = %27
  br label %95

92:                                               ; preds = %3
  %93 = load ptr, ptr @stderr, align 8, !tbaa !5
  %94 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %93, ptr noundef @.str.5, ptr noundef %19) #5
  br label %95

95:                                               ; preds = %92, %91
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %96 = load ptr, ptr %8, align 8
  call void @llvm.stackrestore.p0(ptr %96)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  ret void
}

; 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
declare ptr @llvm.stacksave.p0() #3

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

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

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

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

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

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

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #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 = { 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 = { nocallback nofree nosync nounwind willreturn }
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 = { 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 = !{!"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 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"c_lst_pockets", !6, i64 0, !6, i64 8, !6, i64 16, !14, i64 24, !6, i64 32}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !6, i64 16}
!16 = !{!"node_pocket", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!16, !6, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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 [21 x i8], align 1
@write_mode = external local_unnamed_addr global [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [24 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [36 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @write_each_pocket_for_DB(ptr noundef %0, ptr noundef readonly %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #3
  %5 = add i64 %4, 20
  %6 = and i64 %5, 4294967295
  %7 = alloca i8, i64 %6, align 16
  store i8 0, ptr %7, align 16, !tbaa !5
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %26, label %.preheader

.preheader:                                       ; preds = %3
  %.02932 = load ptr, ptr %1, align 8, !tbaa !8
  %.not3133 = icmp eq ptr %.02932, null
  br i1 %.not3133, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %25
  %.02935 = phi ptr [ %.029, %25 ], [ %.02932, %.preheader ]
  %.034 = phi i32 [ %8, %25 ], [ 0, %.preheader ]
  %8 = add nuw nsw i32 %.034, 1
  %9 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %7, ptr noundef nonnull dereferenceable(1) @.str, ptr noundef %0, i32 noundef %8) #4
  %10 = getelementptr inbounds i8, ptr %.02935, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !10
  call void @write_pocket_pqr_DB(ptr noundef nonnull %7, ptr noundef %11)
  %12 = load i8, ptr @write_mode, align 1
  switch i8 %12, label %18 [
    i8 112, label %13
    i8 98, label %13
  ]

13:                                               ; preds = %.lr.ph, %.lr.ph
  %14 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %7, ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef %0, i32 noundef %8) #4
  %15 = load ptr, ptr %10, align 8, !tbaa !10
  call void @write_pocket_pdb(ptr noundef nonnull %7, ptr noundef %15)
  %16 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %7, ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef %0, i32 noundef %8) #4
  %17 = load ptr, ptr %10, align 8, !tbaa !10
  call void @write_pocket_pdb_DB(ptr noundef nonnull %7, ptr noundef %17, ptr noundef %2)
  %.pr = load i8, ptr @write_mode, align 1
  br label %18

18:                                               ; preds = %.lr.ph, %13
  %19 = phi i8 [ %12, %.lr.ph ], [ %.pr, %13 ]
  switch i8 %19, label %25 [
    i8 109, label %20
    i8 98, label %20
  ]

20:                                               ; preds = %18, %18
  %21 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %7, ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef %0, i32 noundef %8) #4
  %22 = load ptr, ptr %10, align 8, !tbaa !10
  call void @write_pocket_mmcif(ptr noundef nonnull %7, ptr noundef %22)
  %23 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %7, ptr noundef nonnull dereferenceable(1) @.str.4, ptr noundef %0, i32 noundef %8) #4
  %24 = load ptr, ptr %10, align 8, !tbaa !10
  call void @write_pocket_mmcif_DB(ptr noundef nonnull %7, ptr noundef %24, ptr noundef %2)
  br label %25

25:                                               ; preds = %18, %20
  %.029 = load ptr, ptr %.02935, align 8, !tbaa !8
  %.not31 = icmp eq ptr %.029, null
  br i1 %.not31, label %.loopexit, label %.lr.ph, !llvm.loop !12

26:                                               ; preds = %3
  %27 = load ptr, ptr @stderr, align 8, !tbaa !8
  %28 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef nonnull @.str.5, ptr noundef nonnull %7) #5
  br label %.loopexit

.loopexit:                                        ; preds = %25, %.preheader, %26
  ret void
}

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

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

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

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

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

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

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

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

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 = { nounwind willreturn memory(read) }
attributes #4 = { nounwind }
attributes #5 = { cold 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !9, i64 16}
!11 = !{!"node_pocket", !9, i64 0, !9, i64 8, !9, i64 16}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass