; LLVM IR from cruppstahl/upscaledb :: src/1os/os_posix.ll (ZN9upscaledb4File6pwriteEmPKvm)

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

%"class.upscaledb::File" = type { i32, i32, i32 }

@.str.2 = external hidden unnamed_addr constant [74 x i8], align 1
@_ZTIN9upscaledb9ExceptionE = external dso_local constant { ptr, ptr }, align 8
@__FUNCTION__._ZN9upscaledb4File6pwriteEmPKvm = external hidden unnamed_addr constant [7 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [37 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

declare i32 @__gxx_personality_v0(...)

declare ptr @__cxa_allocate_exception(i64)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN9upscaledb9ExceptionC2Ei(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) unnamed_addr #1 align 2

declare void @__cxa_free_exception(ptr)

declare void @__cxa_throw(ptr, ptr, ptr)

declare void @_ZN9upscaledb11dbg_prepareEiPKciS1_S1_(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef) #2

declare void @_ZN9upscaledb7dbg_logEPKcz(ptr noundef, ...) #2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9upscaledb4File6pwriteEmPKvm(ptr noundef nonnull align 4 dereferenceable(12) %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) #5 align 2 personality ptr @__gxx_personality_v0 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i64 %3, ptr %8, align 8, !tbaa !9
  %13 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %48, %4
  %15 = load i64, ptr %10, align 8, !tbaa !9
  %16 = load i64, ptr %8, align 8, !tbaa !9
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %18, label %52

18:                                               ; preds = %14
  %19 = getelementptr inbounds %"class.upscaledb::File", ptr %13, i32 0, i32 0
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load i64, ptr %8, align 8, !tbaa !9
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = load i64, ptr %10, align 8, !tbaa !9
  %25 = add i64 %23, %24
  %26 = call i64 @pwrite64(i32 noundef %20, ptr noundef %21, i64 noundef %22, i64 noundef %25)
  store i64 %26, ptr %9, align 8, !tbaa !9
  %27 = load i64, ptr %9, align 8, !tbaa !9
  %28 = icmp slt i64 %27, 0
  br i1 %28, label %29, label %44

29:                                               ; preds = %18
  br label %30

30:                                               ; preds = %29
  call void @_ZN9upscaledb11dbg_prepareEiPKciS1_S1_(i32 noundef 1, ptr noundef @.str.2, i32 noundef 265, ptr noundef @__FUNCTION__._ZN9upscaledb4File6pwriteEmPKvm, ptr noundef null)
  %31 = call ptr @__errno_location() #7
  %32 = load i32, ptr %31, align 4, !tbaa !14
  %33 = call ptr @__errno_location() #7
  %34 = load i32, ptr %33, align 4, !tbaa !14
  %35 = call ptr @strerror(i32 noundef %34) #6
  call void (ptr, ...) @_ZN9upscaledb7dbg_logEPKcz(ptr noundef @.str.6, i32 noundef %32, ptr noundef %35)
  br label %36

36:                                               ; preds = %30
  br label %37

37:                                               ; preds = %36
  %38 = call ptr @__cxa_allocate_exception(i64 4) #6
  invoke void @_ZN9upscaledb9ExceptionC2Ei(ptr noundef nonnull align 4 dereferenceable(4) %38, i32 noundef -18)
          to label %39 unwind label %40

39:                                               ; preds = %37
  call void @__cxa_throw(ptr %38, ptr @_ZTIN9upscaledb9ExceptionE, ptr null) #8
  unreachable

40:                                               ; preds = %37
  %41 = landingpad { ptr, i32 }
          cleanup
  %42 = extractvalue { ptr, i32 } %41, 0
  store ptr %42, ptr %11, align 8
  %43 = extractvalue { ptr, i32 } %41, 1
  store i32 %43, ptr %12, align 4
  call void @__cxa_free_exception(ptr %38) #6
  br label %70

44:                                               ; preds = %18
  %45 = load i64, ptr %9, align 8, !tbaa !9
  %46 = icmp eq i64 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %44
  br label %52

48:                                               ; preds = %44
  %49 = load i64, ptr %9, align 8, !tbaa !9
  %50 = load i64, ptr %10, align 8, !tbaa !9
  %51 = add i64 %50, %49
  store i64 %51, ptr %10, align 8, !tbaa !9
  br label %14, !llvm.loop !15

52:                                               ; preds = %47, %14
  %53 = load i64, ptr %10, align 8, !tbaa !9
  %54 = load i64, ptr %8, align 8, !tbaa !9
  %55 = icmp ne i64 %53, %54
  br i1 %55, label %56, label %69

56:                                               ; preds = %52
  br label %57

57:                                               ; preds = %56
  call void @_ZN9upscaledb11dbg_prepareEiPKciS1_S1_(i32 noundef 1, ptr noundef @.str.2, i32 noundef 274, ptr noundef @__FUNCTION__._ZN9upscaledb4File6pwriteEmPKvm, ptr noundef null)
  %58 = call ptr @__errno_location() #7
  %59 = load i32, ptr %58, align 4, !tbaa !14
  %60 = call ptr @strerror(i32 noundef %59) #6
  call void (ptr, ...) @_ZN9upscaledb7dbg_logEPKcz(ptr noundef @.str.7, ptr noundef %60)
  br label %61

61:                                               ; preds = %57
  br label %62

62:                                               ; preds = %61
  %63 = call ptr @__cxa_allocate_exception(i64 4) #6
  invoke void @_ZN9upscaledb9ExceptionC2Ei(ptr noundef nonnull align 4 dereferenceable(4) %63, i32 noundef -18)
          to label %64 unwind label %65

64:                                               ; preds = %62
  call void @__cxa_throw(ptr %63, ptr @_ZTIN9upscaledb9ExceptionE, ptr null) #8
  unreachable

65:                                               ; preds = %62
  %66 = landingpad { ptr, i32 }
          cleanup
  %67 = extractvalue { ptr, i32 } %66, 0
  store ptr %67, ptr %11, align 8
  %68 = extractvalue { ptr, i32 } %66, 1
  store i32 %68, ptr %12, align 4
  call void @__cxa_free_exception(ptr %63) #6
  br label %70

69:                                               ; preds = %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  ret void

70:                                               ; preds = %65, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  br label %71

71:                                               ; preds = %70
  %72 = load ptr, ptr %11, align 8
  %73 = load i32, ptr %12, align 4
  %74 = insertvalue { ptr, i32 } poison, ptr %72, 0
  %75 = insertvalue { ptr, i32 } %74, i32 %73, 1
  resume { ptr, i32 } %75
}

declare i64 @pwrite64(i32 noundef, ptr noundef, i64 noundef, i64 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #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 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 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(none) }
attributes #8 = { noreturn }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTSN9upscaledb4FileE", !13, i64 0, !13, i64 4, !13, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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.2 = external hidden unnamed_addr constant [74 x i8], align 1
@_ZTIN9upscaledb9ExceptionE = external dso_local constant { ptr, ptr }, align 8
@__FUNCTION__._ZN9upscaledb4File6pwriteEmPKvm = external hidden unnamed_addr constant [7 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [37 x i8], align 1

declare i32 @__gxx_personality_v0(...)

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN9upscaledb9ExceptionC2Ei(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) unnamed_addr #0 align 2

declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr

declare void @_ZN9upscaledb11dbg_prepareEiPKciS1_S1_(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @_ZN9upscaledb7dbg_logEPKcz(ptr noundef, ...) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9upscaledb4File6pwriteEmPKvm(ptr nocapture noundef nonnull readonly align 4 dereferenceable(12) %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #4 align 2 personality ptr @__gxx_personality_v0 {
  %.not18 = icmp eq i64 %3, 0
  br i1 %.not18, label %._crit_edge, label %.lr.ph

5:                                                ; preds = %17
  %6 = add i64 %10, %.015
  %7 = icmp ult i64 %6, %3
  br i1 %7, label %.lr.ph, label %._crit_edge, !llvm.loop !5

.lr.ph:                                           ; preds = %4, %5
  %.015 = phi i64 [ %6, %5 ], [ 0, %4 ]
  %8 = load i32, ptr %0, align 4, !tbaa !7
  %9 = add i64 %.015, %1
  %10 = tail call i64 @pwrite64(i32 noundef %8, ptr noundef %2, i64 noundef %3, i64 noundef %9)
  %11 = icmp slt i64 %10, 0
  br i1 %11, label %12, label %17

12:                                               ; preds = %.lr.ph
  tail call void @_ZN9upscaledb11dbg_prepareEiPKciS1_S1_(i32 noundef 1, ptr noundef nonnull @.str.2, i32 noundef 265, ptr noundef nonnull @__FUNCTION__._ZN9upscaledb4File6pwriteEmPKvm, ptr noundef null)
  %13 = tail call ptr @__errno_location() #5
  %14 = load i32, ptr %13, align 4, !tbaa !12
  %15 = tail call ptr @strerror(i32 noundef %14) #6
  tail call void (ptr, ...) @_ZN9upscaledb7dbg_logEPKcz(ptr noundef nonnull @.str.6, i32 noundef %14, ptr noundef %15)
  %16 = tail call ptr @__cxa_allocate_exception(i64 4) #6
  tail call void @_ZN9upscaledb9ExceptionC2Ei(ptr noundef nonnull align 4 dereferenceable(4) %16, i32 noundef -18)
  tail call void @__cxa_throw(ptr nonnull %16, ptr nonnull @_ZTIN9upscaledb9ExceptionE, ptr null) #7
  unreachable

17:                                               ; preds = %.lr.ph
  %18 = icmp eq i64 %10, 0
  br i1 %18, label %._crit_edge, label %5

._crit_edge:                                      ; preds = %5, %17, %4
  %.0.lcssa = phi i64 [ 0, %4 ], [ %.015, %17 ], [ %6, %5 ]
  %.not = icmp eq i64 %.0.lcssa, %3
  br i1 %.not, label %24, label %19

19:                                               ; preds = %._crit_edge
  tail call void @_ZN9upscaledb11dbg_prepareEiPKciS1_S1_(i32 noundef 1, ptr noundef nonnull @.str.2, i32 noundef 274, ptr noundef nonnull @__FUNCTION__._ZN9upscaledb4File6pwriteEmPKvm, ptr noundef null)
  %20 = tail call ptr @__errno_location() #5
  %21 = load i32, ptr %20, align 4, !tbaa !12
  %22 = tail call ptr @strerror(i32 noundef %21) #6
  tail call void (ptr, ...) @_ZN9upscaledb7dbg_logEPKcz(ptr noundef nonnull @.str.7, ptr noundef %22)
  %23 = tail call ptr @__cxa_allocate_exception(i64 4) #6
  tail call void @_ZN9upscaledb9ExceptionC2Ei(ptr noundef nonnull align 4 dereferenceable(4) %23, i32 noundef -18)
  tail call void @__cxa_throw(ptr nonnull %23, ptr nonnull @_ZTIN9upscaledb9ExceptionE, ptr null) #7
  unreachable

24:                                               ; preds = %._crit_edge
  ret void
}

declare i64 @pwrite64(i32 noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 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 #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 = { mustprogress 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 #5 = { nounwind willreturn memory(none) }
attributes #6 = { nounwind }
attributes #7 = { noreturn }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !9, i64 0}
!8 = !{!"_ZTSN9upscaledb4FileE", !9, i64 0, !9, i64 4, !9, i64 8}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!9, !9, i64 0}


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