; LLVM IR from fwip/fastqz :: libzpaq.ll (ZN7libzpaq6allocxERPhRii)

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

@.str = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7libzpaq6allocxERPhRii(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull align 4 dereferenceable(4) %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %14, label %10

10:                                               ; preds = %3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %28

14:                                               ; preds = %10, %3
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %25

18:                                               ; preds = %14
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = call i32 @munmap(ptr noundef %20, i64 noundef %23) #3
  br label %25

25:                                               ; preds = %18, %14
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr null, ptr %26, align 8, !tbaa !5
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %27, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %25, %10
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = icmp sgt i32 %29, 0
  br i1 %30, label %31, label %51

31:                                               ; preds = %28
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = call ptr @mmap(ptr noundef null, i64 noundef %33, i32 noundef 7, i32 noundef 34, i32 noundef -1, i64 noundef 0) #3
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %34, ptr %35, align 8, !tbaa !5
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = icmp eq ptr %37, inttoptr (i64 -1 to ptr)
  br i1 %38, label %39, label %41

39:                                               ; preds = %31
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr null, ptr %40, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %39, %31
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  %44 = icmp ne ptr %43, null
  br i1 %44, label %45, label %48

45:                                               ; preds = %41
  %46 = load i32, ptr %6, align 4, !tbaa !9
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %46, ptr %47, align 4, !tbaa !9
  br label %50

48:                                               ; preds = %41
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %49, align 4, !tbaa !9
  call void @_ZN7libzpaq5errorEPKc(ptr noundef @.str)
  br label %50

50:                                               ; preds = %48, %45
  br label %51

51:                                               ; preds = %50, %28
  ret void
}

; Function Attrs: nounwind
declare i32 @munmap(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind
declare ptr @mmap(ptr noundef, i64 noundef, i32 noundef, i32 noundef, i32 noundef, i64 noundef) #1

declare void @_ZN7libzpaq5errorEPKc(ptr noundef) #2

attributes #0 = { 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 #1 = { 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 #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 }

!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 = !{!"int", !7, 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"

@.str = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7libzpaq6allocxERPhRii(ptr nocapture noundef nonnull align 8 dereferenceable(8) %0, ptr nocapture noundef nonnull align 4 dereferenceable(4) %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  %5 = load i32, ptr %1, align 4
  %.not16 = icmp eq i32 %5, 0
  %or.cond = select i1 %.not, i1 %.not16, i1 false
  br i1 %or.cond, label %11, label %6

6:                                                ; preds = %3
  br i1 %.not, label %10, label %7

7:                                                ; preds = %6
  %8 = sext i32 %5 to i64
  %9 = tail call i32 @munmap(ptr noundef nonnull %4, i64 noundef %8) #3
  br label %10

10:                                               ; preds = %7, %6
  store ptr null, ptr %0, align 8, !tbaa !5
  store i32 0, ptr %1, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %3, %10
  %12 = icmp sgt i32 %2, 0
  br i1 %12, label %13, label %19

13:                                               ; preds = %11
  %14 = zext nneg i32 %2 to i64
  %15 = tail call ptr @mmap(ptr noundef null, i64 noundef %14, i32 noundef 7, i32 noundef 34, i32 noundef -1, i64 noundef 0) #3
  %16 = icmp eq ptr %15, inttoptr (i64 -1 to ptr)
  %spec.select = select i1 %16, ptr null, ptr %15
  store ptr %spec.select, ptr %0, align 8, !tbaa !5
  %.not18 = icmp eq ptr %spec.select, null
  br i1 %.not18, label %18, label %17

17:                                               ; preds = %13
  store i32 %2, ptr %1, align 4, !tbaa !9
  br label %19

18:                                               ; preds = %13
  store i32 0, ptr %1, align 4, !tbaa !9
  tail call void @_ZN7libzpaq5errorEPKc(ptr noundef nonnull @.str)
  br label %19

19:                                               ; preds = %17, %18, %11
  ret void
}

; Function Attrs: nounwind
declare i32 @munmap(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare ptr @mmap(ptr noundef, i64 noundef, i32 noundef, i32 noundef, i32 noundef, i64 noundef) local_unnamed_addr #1

declare void @_ZN7libzpaq5errorEPKc(ptr noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { 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 #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 }

!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 = !{!"int", !7, i64 0}


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