; LLVM IR from AngelPn/DBMS-Simulator :: src (HP)

; 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.HP_info = type { i32, i32, i8, ptr, i32, i32 }

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @HP_CreateFile(ptr noundef %0, i8 noundef signext %1, ptr noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca %struct.HP_info, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i8 %1, ptr %7, align 1, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !10
  call void (...) @BF_Init()
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = call i32 @BF_CreateFile(ptr noundef %15)
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %4
  call void @BF_PrintError(ptr noundef @.str)
  store i32 -1, ptr %5, align 4
  br label %71

19:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #7
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = call i32 @BF_OpenFile(ptr noundef %20)
  store i32 %21, ptr %10, align 4, !tbaa !10
  %22 = icmp slt i32 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %19
  call void @BF_PrintError(ptr noundef @.str.1)
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %70

24:                                               ; preds = %19
  %25 = load i32, ptr %10, align 4, !tbaa !10
  %26 = call i32 @BF_AllocateBlock(i32 noundef %25)
  %27 = icmp slt i32 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %24
  call void @BF_PrintError(ptr noundef @.str.2)
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %70

29:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #7
  store ptr null, ptr %12, align 8, !tbaa !5
  %30 = load i32, ptr %10, align 4, !tbaa !10
  %31 = load i32, ptr %10, align 4, !tbaa !10
  %32 = call i32 @BF_GetBlockCounter(i32 noundef %31)
  %33 = sub nsw i32 %32, 1
  %34 = call i32 @BF_ReadBlock(i32 noundef %30, i32 noundef %33, ptr noundef %12)
  %35 = icmp slt i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %29
  call void @BF_PrintError(ptr noundef @.str.3)
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %69

37:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 32, ptr %13) #7
  %38 = getelementptr inbounds %struct.HP_info, ptr %13, i32 0, i32 0
  store i32 0, ptr %38, align 8, !tbaa !12
  %39 = getelementptr inbounds %struct.HP_info, ptr %13, i32 0, i32 1
  %40 = load i32, ptr %10, align 4, !tbaa !10
  store i32 %40, ptr %39, align 4, !tbaa !14
  %41 = getelementptr inbounds %struct.HP_info, ptr %13, i32 0, i32 2
  %42 = load i8, ptr %7, align 1, !tbaa !9
  store i8 %42, ptr %41, align 8, !tbaa !15
  %43 = getelementptr inbounds %struct.HP_info, ptr %13, i32 0, i32 3
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = call i64 @strlen(ptr noundef %44) #8
  %46 = add i64 %45, 1
  %47 = mul i64 1, %46
  %48 = call noalias ptr @malloc(i64 noundef %47) #9
  store ptr %48, ptr %43, align 8, !tbaa !16
  %49 = getelementptr inbounds %struct.HP_info, ptr %13, i32 0, i32 4
  %50 = load i32, ptr %9, align 4, !tbaa !10
  store i32 %50, ptr %49, align 8, !tbaa !17
  %51 = getelementptr inbounds %struct.HP_info, ptr %13, i32 0, i32 5
  %52 = load i32, ptr %10, align 4, !tbaa !10
  %53 = call i32 @BF_GetBlockCounter(i32 noundef %52)
  %54 = sub nsw i32 %53, 1
  store i32 %54, ptr %51, align 4, !tbaa !18
  %55 = getelementptr inbounds %struct.HP_info, ptr %13, i32 0, i32 3
  %56 = load ptr, ptr %55, align 8, !tbaa !16
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = call ptr @strcpy(ptr noundef %56, ptr noundef %57) #7
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %59, ptr align 8 %13, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #7
  store i32 -1, ptr %14, align 4, !tbaa !10
  %60 = load ptr, ptr %12, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i64 512
  %62 = getelementptr inbounds i8, ptr %61, i64 -8
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %62, ptr align 4 %14, i64 4, i1 false)
  %63 = load i32, ptr %10, align 4, !tbaa !10
  %64 = call i32 @BF_WriteBlock(i32 noundef %63, i32 noundef 0)
  %65 = icmp slt i32 %64, 0
  br i1 %65, label %66, label %67

66:                                               ; preds = %37
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %68

67:                                               ; preds = %37
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %68

68:                                               ; preds = %67, %66
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #7
  call void @llvm.lifetime.end.p0(i64 32, ptr %13) #7
  br label %69

69:                                               ; preds = %68, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #7
  br label %70

70:                                               ; preds = %69, %28, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  br label %71

71:                                               ; preds = %70, %18
  %72 = load i32, ptr %5, align 4
  ret i32 %72
}

declare void @BF_Init(...) #1

declare i32 @BF_CreateFile(ptr noundef) #1

declare void @BF_PrintError(ptr noundef) #1

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

declare i32 @BF_OpenFile(ptr noundef) #1

declare i32 @BF_AllocateBlock(i32 noundef) #1

declare i32 @BF_ReadBlock(i32 noundef, i32 noundef, ptr noundef) #1

declare i32 @BF_GetBlockCounter(i32 noundef) #1

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

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

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #5

; 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) #6

declare i32 @BF_WriteBlock(i32 noundef, i32 noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 #5 = { 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 #6 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"HP_info", !11, i64 0, !11, i64 4, !7, i64 8, !6, i64 16, !11, i64 24, !11, i64 28}
!14 = !{!13, !11, i64 4}
!15 = !{!13, !7, i64 8}
!16 = !{!13, !6, i64 16}
!17 = !{!13, !11, i64 24}
!18 = !{!13, !11, i64 28}


; 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 [20 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @HP_CreateFile(ptr noundef %0, i8 noundef signext %1, ptr nocapture noundef readonly %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca ptr, align 8
  tail call void (...) @BF_Init() #6
  %6 = tail call i32 @BF_CreateFile(ptr noundef %0) #6
  %7 = icmp slt i32 %6, 0
  br i1 %7, label %8, label %9

8:                                                ; preds = %4
  tail call void @BF_PrintError(ptr noundef nonnull @.str) #6
  br label %35

9:                                                ; preds = %4
  %10 = tail call i32 @BF_OpenFile(ptr noundef %0) #6
  %11 = icmp slt i32 %10, 0
  br i1 %11, label %12, label %13

12:                                               ; preds = %9
  tail call void @BF_PrintError(ptr noundef nonnull @.str.1) #6
  br label %35

13:                                               ; preds = %9
  %14 = tail call i32 @BF_AllocateBlock(i32 noundef %10) #6
  %15 = icmp slt i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %13
  tail call void @BF_PrintError(ptr noundef nonnull @.str.2) #6
  br label %35

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #6
  store ptr null, ptr %5, align 8, !tbaa !5
  %18 = tail call i32 @BF_GetBlockCounter(i32 noundef %10) #6
  %19 = add nsw i32 %18, -1
  %20 = call i32 @BF_ReadBlock(i32 noundef %10, i32 noundef %19, ptr noundef nonnull %5) #6
  %21 = icmp slt i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %17
  call void @BF_PrintError(ptr noundef nonnull @.str.3) #6
  br label %34

23:                                               ; preds = %17
  %24 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #7
  %25 = add i64 %24, 1
  %26 = call noalias ptr @malloc(i64 noundef %25) #8
  %27 = call i32 @BF_GetBlockCounter(i32 noundef %10) #6
  %28 = add nsw i32 %27, -1
  %29 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %26, ptr noundef nonnull dereferenceable(1) %2) #6
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %30, align 1
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %30, i64 4
  store i32 %10, ptr %.sroa.4.0..sroa_idx, align 1
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %30, i64 8
  store i8 %1, ptr %.sroa.5.0..sroa_idx, align 1
  %.sroa.61.0..sroa_idx = getelementptr inbounds i8, ptr %30, i64 16
  store ptr %26, ptr %.sroa.61.0..sroa_idx, align 1
  %.sroa.8.0..sroa_idx = getelementptr inbounds i8, ptr %30, i64 24
  store i32 %3, ptr %.sroa.8.0..sroa_idx, align 1
  %.sroa.9.0..sroa_idx = getelementptr inbounds i8, ptr %30, i64 28
  store i32 %28, ptr %.sroa.9.0..sroa_idx, align 1
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i64 504
  store i32 -1, ptr %32, align 1
  %33 = call i32 @BF_WriteBlock(i32 noundef %10, i32 noundef 0) #6
  %.lobit = ashr i32 %33, 31
  br label %34

34:                                               ; preds = %23, %22
  %.1 = phi i32 [ -1, %22 ], [ %.lobit, %23 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #6
  br label %35

35:                                               ; preds = %12, %16, %34, %8
  %.3 = phi i32 [ -1, %8 ], [ -1, %12 ], [ -1, %16 ], [ %.1, %34 ]
  ret i32 %.3
}

declare void @BF_Init(...) local_unnamed_addr #1

declare i32 @BF_CreateFile(ptr noundef) local_unnamed_addr #1

declare void @BF_PrintError(ptr noundef) local_unnamed_addr #1

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

declare i32 @BF_OpenFile(ptr noundef) local_unnamed_addr #1

declare i32 @BF_AllocateBlock(i32 noundef) local_unnamed_addr #1

declare i32 @BF_ReadBlock(i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare i32 @BF_GetBlockCounter(i32 noundef) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #5

declare i32 @BF_WriteBlock(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { "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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 #5 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { 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"}


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