; LLVM IR from artagnon/phoenixfs :: xdiff (xprepare)

; 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.s_xdlclassifier = type { i32, i64, ptr, %struct.s_chastore, i64, i64 }
%struct.s_chastore = type { ptr, ptr, i64, i64, ptr, ptr, i64 }
%struct.s_xpparam = type { i64 }
%struct.s_xdfenv = type { %struct.s_xdfile, %struct.s_xdfile }
%struct.s_xdfile = type { %struct.s_chastore, i64, i32, ptr, i64, i64, ptr, ptr, ptr, i64, ptr }

; Function Attrs: nounwind uwtable
define dso_local i32 @xdl_prepare_env(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca %struct.s_xdlclassifier, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 96, ptr %12) #3
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = call i64 @xdl_guess_lines(ptr noundef %14)
  %16 = add nsw i64 %15, 1
  store i64 %16, ptr %10, align 8, !tbaa !9
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = call i64 @xdl_guess_lines(ptr noundef %17)
  %19 = add nsw i64 %18, 1
  store i64 %19, ptr %11, align 8, !tbaa !9
  %20 = load i64, ptr %10, align 8, !tbaa !9
  %21 = load i64, ptr %11, align 8, !tbaa !9
  %22 = add nsw i64 %20, %21
  %23 = add nsw i64 %22, 1
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.s_xpparam, ptr %24, i32 0, i32 0
  %26 = load i64, ptr %25, align 8, !tbaa !11
  %27 = call i32 @xdl_init_classifier(ptr noundef %12, i64 noundef %23, i64 noundef %26)
  %28 = icmp slt i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %4
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %69

30:                                               ; preds = %4
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load i64, ptr %10, align 8, !tbaa !9
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.s_xdfenv, ptr %34, i32 0, i32 0
  %36 = call i32 @xdl_prepare_ctx(ptr noundef %31, i64 noundef %32, ptr noundef %33, ptr noundef %12, ptr noundef %35)
  %37 = icmp slt i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %30
  call void @xdl_free_classifier(ptr noundef %12)
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %69

39:                                               ; preds = %30
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load i64, ptr %11, align 8, !tbaa !9
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.s_xdfenv, ptr %43, i32 0, i32 1
  %45 = call i32 @xdl_prepare_ctx(ptr noundef %40, i64 noundef %41, ptr noundef %42, ptr noundef %12, ptr noundef %44)
  %46 = icmp slt i32 %45, 0
  br i1 %46, label %47, label %50

47:                                               ; preds = %39
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.s_xdfenv, ptr %48, i32 0, i32 0
  call void @xdl_free_ctx(ptr noundef %49)
  call void @xdl_free_classifier(ptr noundef %12)
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %69

50:                                               ; preds = %39
  call void @xdl_free_classifier(ptr noundef %12)
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.s_xpparam, ptr %51, i32 0, i32 0
  %53 = load i64, ptr %52, align 8, !tbaa !11
  %54 = and i64 %53, 32
  %55 = icmp ne i64 %54, 0
  br i1 %55, label %68, label %56

56:                                               ; preds = %50
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.s_xdfenv, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.s_xdfenv, ptr %59, i32 0, i32 1
  %61 = call i32 @xdl_optimize_ctxs(ptr noundef %58, ptr noundef %60)
  %62 = icmp slt i32 %61, 0
  br i1 %62, label %63, label %68

63:                                               ; preds = %56
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.s_xdfenv, ptr %64, i32 0, i32 1
  call void @xdl_free_ctx(ptr noundef %65)
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.s_xdfenv, ptr %66, i32 0, i32 0
  call void @xdl_free_ctx(ptr noundef %67)
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %69

68:                                               ; preds = %56, %50
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %69

69:                                               ; preds = %68, %63, %47, %38, %29
  call void @llvm.lifetime.end.p0(i64 96, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %70 = load i32, ptr %5, align 4
  ret i32 %70
}

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

declare i64 @xdl_guess_lines(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @xdl_init_classifier(ptr noundef, i64 noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @xdl_prepare_ctx(ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @xdl_free_classifier(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @xdl_free_ctx(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @xdl_optimize_ctxs(ptr noundef, ptr noundef) #0

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

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 = { "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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"s_xpparam", !10, 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"

%struct.s_xdlclassifier = type { i32, i64, ptr, %struct.s_chastore, i64, i64 }
%struct.s_chastore = type { ptr, ptr, i64, i64, ptr, ptr, i64 }

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @xdl_prepare_env(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = alloca %struct.s_xdlclassifier, align 8
  call void @llvm.lifetime.start.p0(i64 96, ptr nonnull %5) #3
  %6 = tail call i64 @xdl_guess_lines(ptr noundef %0) #3
  %7 = tail call i64 @xdl_guess_lines(ptr noundef %1) #3
  %8 = add nsw i64 %7, 1
  %9 = add i64 %6, 2
  %10 = add i64 %9, %8
  %11 = load i64, ptr %2, align 8, !tbaa !5
  %12 = call i32 @xdl_init_classifier(ptr noundef nonnull %5, i64 noundef %10, i64 noundef %11)
  %13 = icmp slt i32 %12, 0
  br i1 %13, label %31, label %14

14:                                               ; preds = %4
  %15 = add nsw i64 %6, 1
  %16 = call i32 @xdl_prepare_ctx(ptr noundef %0, i64 noundef %15, ptr noundef nonnull %2, ptr noundef nonnull %5, ptr noundef %3)
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %14
  call void @xdl_free_classifier(ptr noundef nonnull %5)
  br label %31

19:                                               ; preds = %14
  %20 = getelementptr inbounds i8, ptr %3, i64 136
  %21 = call i32 @xdl_prepare_ctx(ptr noundef %1, i64 noundef %8, ptr noundef nonnull %2, ptr noundef nonnull %5, ptr noundef nonnull %20)
  %22 = icmp slt i32 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %19
  call void @xdl_free_ctx(ptr noundef %3)
  call void @xdl_free_classifier(ptr noundef nonnull %5)
  br label %31

24:                                               ; preds = %19
  call void @xdl_free_classifier(ptr noundef nonnull %5)
  %25 = load i64, ptr %2, align 8, !tbaa !5
  %26 = and i64 %25, 32
  %.not = icmp eq i64 %26, 0
  br i1 %.not, label %27, label %31

27:                                               ; preds = %24
  %28 = call i32 @xdl_optimize_ctxs(ptr noundef %3, ptr noundef nonnull %20)
  %29 = icmp slt i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %27
  call void @xdl_free_ctx(ptr noundef nonnull %20)
  call void @xdl_free_ctx(ptr noundef %3)
  br label %31

31:                                               ; preds = %24, %27, %4, %30, %23, %18
  %.0 = phi i32 [ -1, %18 ], [ -1, %23 ], [ -1, %30 ], [ -1, %4 ], [ 0, %27 ], [ 0, %24 ]
  call void @llvm.lifetime.end.p0(i64 96, ptr nonnull %5) #3
  ret i32 %.0
}

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

declare i64 @xdl_guess_lines(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @xdl_init_classifier(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @xdl_prepare_ctx(ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @xdl_free_classifier(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @xdl_free_ctx(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @xdl_optimize_ctxs(ptr noundef, ptr noundef) local_unnamed_addr #0

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

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !7, i64 0}
!6 = !{!"s_xpparam", !7, i64 0}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}


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