; LLVM IR from TobiasKozel/VAE :: external/tracy/libbacktrace (mmapio)

; 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.tracy::backtrace_view" = type { ptr, ptr, i64 }

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5tracy18backtrace_get_viewEPNS_15backtrace_stateEilmPFvPvPKciES2_PNS_14backtrace_viewE(ptr noundef %0, i32 noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6) #0 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  %18 = alloca i64, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store i32 %1, ptr %10, align 4, !tbaa !9
  store i64 %2, ptr %11, align 8, !tbaa !11
  store i64 %3, ptr %12, align 8, !tbaa !11
  store ptr %4, ptr %13, align 8, !tbaa !5
  store ptr %5, ptr %14, align 8, !tbaa !5
  store ptr %6, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %21 = load i64, ptr %12, align 8, !tbaa !11
  %22 = load i64, ptr %12, align 8, !tbaa !11
  %23 = icmp ne i64 %21, %22
  br i1 %23, label %24, label %27

24:                                               ; preds = %7
  %25 = load ptr, ptr %13, align 8, !tbaa !5
  %26 = load ptr, ptr %14, align 8, !tbaa !5
  call void %25(ptr noundef %26, ptr noundef @.str, i32 noundef 0)
  store i32 0, ptr %8, align 4
  store i32 1, ptr %20, align 4
  br label %74

27:                                               ; preds = %7
  %28 = call i32 @getpagesize() #5
  %29 = sext i32 %28 to i64
  store i64 %29, ptr %16, align 8, !tbaa !11
  %30 = load i64, ptr %11, align 8, !tbaa !11
  %31 = load i64, ptr %16, align 8, !tbaa !11
  %32 = urem i64 %30, %31
  %33 = trunc i64 %32 to i32
  store i32 %33, ptr %17, align 4, !tbaa !9
  %34 = load i64, ptr %11, align 8, !tbaa !11
  %35 = load i32, ptr %17, align 4, !tbaa !9
  %36 = zext i32 %35 to i64
  %37 = sub nsw i64 %34, %36
  store i64 %37, ptr %18, align 8, !tbaa !11
  %38 = load i32, ptr %17, align 4, !tbaa !9
  %39 = zext i32 %38 to i64
  %40 = load i64, ptr %12, align 8, !tbaa !11
  %41 = add i64 %40, %39
  store i64 %41, ptr %12, align 8, !tbaa !11
  %42 = load i64, ptr %12, align 8, !tbaa !11
  %43 = load i64, ptr %16, align 8, !tbaa !11
  %44 = sub i64 %43, 1
  %45 = add i64 %42, %44
  %46 = load i64, ptr %16, align 8, !tbaa !11
  %47 = sub i64 %46, 1
  %48 = xor i64 %47, -1
  %49 = and i64 %45, %48
  store i64 %49, ptr %12, align 8, !tbaa !11
  %50 = load i64, ptr %12, align 8, !tbaa !11
  %51 = load i32, ptr %10, align 4, !tbaa !9
  %52 = load i64, ptr %18, align 8, !tbaa !11
  %53 = call ptr @mmap(ptr noundef null, i64 noundef %50, i32 noundef 1, i32 noundef 2, i32 noundef %51, i64 noundef %52) #4
  store ptr %53, ptr %19, align 8, !tbaa !5
  %54 = load ptr, ptr %19, align 8, !tbaa !5
  %55 = icmp eq ptr %54, inttoptr (i64 -1 to ptr)
  br i1 %55, label %56, label %61

56:                                               ; preds = %27
  %57 = load ptr, ptr %13, align 8, !tbaa !5
  %58 = load ptr, ptr %14, align 8, !tbaa !5
  %59 = call ptr @__errno_location() #5
  %60 = load i32, ptr %59, align 4, !tbaa !9
  call void %57(ptr noundef %58, ptr noundef @.str.1, i32 noundef %60)
  store i32 0, ptr %8, align 4
  store i32 1, ptr %20, align 4
  br label %74

61:                                               ; preds = %27
  %62 = load ptr, ptr %19, align 8, !tbaa !5
  %63 = load i32, ptr %17, align 4, !tbaa !9
  %64 = zext i32 %63 to i64
  %65 = getelementptr inbounds i8, ptr %62, i64 %64
  %66 = load ptr, ptr %15, align 8, !tbaa !5
  %67 = getelementptr inbounds %"struct.tracy::backtrace_view", ptr %66, i32 0, i32 0
  store ptr %65, ptr %67, align 8, !tbaa !13
  %68 = load ptr, ptr %19, align 8, !tbaa !5
  %69 = load ptr, ptr %15, align 8, !tbaa !5
  %70 = getelementptr inbounds %"struct.tracy::backtrace_view", ptr %69, i32 0, i32 1
  store ptr %68, ptr %70, align 8, !tbaa !15
  %71 = load i64, ptr %12, align 8, !tbaa !11
  %72 = load ptr, ptr %15, align 8, !tbaa !5
  %73 = getelementptr inbounds %"struct.tracy::backtrace_view", ptr %72, i32 0, i32 2
  store i64 %71, ptr %73, align 8, !tbaa !16
  store i32 1, ptr %8, align 4
  store i32 1, ptr %20, align 4
  br label %74

74:                                               ; preds = %61, %56, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  %75 = load i32, ptr %8, align 4
  ret i32 %75
}

; 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(none)
declare i32 @getpagesize() #2

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

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { nounwind }
attributes #5 = { nounwind willreturn memory(none) }

!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}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTSN5tracy14backtrace_viewE", !6, i64 0, !6, i64 8, !12, i64 16}
!15 = !{!14, !6, i64 8}
!16 = !{!14, !12, i64 16}


; 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.1 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN5tracy18backtrace_get_viewEPNS_15backtrace_stateEilmPFvPvPKciES2_PNS_14backtrace_viewE(ptr nocapture noundef readnone %0, i32 noundef %1, i64 noundef %2, i64 noundef %3, ptr nocapture noundef readonly %4, ptr noundef %5, ptr nocapture noundef writeonly %6) local_unnamed_addr #0 {
  %8 = tail call i32 @getpagesize() #3
  %9 = sext i32 %8 to i64
  %10 = urem i64 %2, %9
  %11 = and i64 %10, 4294967295
  %12 = sub nsw i64 %2, %11
  %13 = add i64 %3, -1
  %14 = add i64 %13, %9
  %15 = add i64 %14, %11
  %16 = sub nsw i64 0, %9
  %17 = and i64 %15, %16
  %18 = tail call ptr @mmap(ptr noundef null, i64 noundef %17, i32 noundef 1, i32 noundef 2, i32 noundef %1, i64 noundef %12) #4
  %19 = icmp eq ptr %18, inttoptr (i64 -1 to ptr)
  br i1 %19, label %20, label %23

20:                                               ; preds = %7
  %21 = tail call ptr @__errno_location() #3
  %22 = load i32, ptr %21, align 4, !tbaa !5
  tail call void %4(ptr noundef %5, ptr noundef nonnull @.str.1, i32 noundef %22)
  br label %27

23:                                               ; preds = %7
  %24 = getelementptr inbounds i8, ptr %18, i64 %11
  store ptr %24, ptr %6, align 8, !tbaa !9
  %25 = getelementptr inbounds i8, ptr %6, i64 8
  store ptr %18, ptr %25, align 8, !tbaa !13
  %26 = getelementptr inbounds i8, ptr %6, i64 16
  store i64 %17, ptr %26, align 8, !tbaa !14
  br label %27

27:                                               ; preds = %23, %20
  %.0 = phi i32 [ 0, %20 ], [ 1, %23 ]
  ret i32 %.0
}

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare i32 @getpagesize() 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 #2

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

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 = { 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 #2 = { 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(none) }
attributes #4 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTSN5tracy14backtrace_viewE", !11, i64 0, !11, i64 8, !12, i64 16}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !11, i64 8}
!14 = !{!10, !12, i64 16}


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