; LLVM IR from octu0/blurry :: mt (libprepare_ncc_tpl)

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

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

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

declare void @free_buf(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @libprepare_ncc_tpl(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.prepared_ncc_template_t, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.prepared_ncc_template_t, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !12
  %18 = call ptr @create_rgba_buffer(ptr noundef %11, i32 noundef %14, i32 noundef %17)
  store ptr %18, ptr %6, align 8, !tbaa !5
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %2
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %70

22:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.prepared_ncc_template_t, ptr %23, i32 0, i32 2
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.prepared_ncc_template_t, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 8, !tbaa !9
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.prepared_ncc_template_t, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 4, !tbaa !12
  %32 = call ptr @create_float_array_buffer(ptr noundef %25, i32 noundef %28, i32 noundef %31)
  store ptr %32, ptr %8, align 8, !tbaa !5
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = icmp eq ptr %33, null
  br i1 %34, label %35, label %37

35:                                               ; preds = %22
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free_buf(ptr noundef %36)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %69

37:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.prepared_ncc_template_t, ptr %38, i32 0, i32 3
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.prepared_ncc_template_t, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !9
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.prepared_ncc_template_t, ptr %44, i32 0, i32 1
  %46 = load i32, ptr %45, align 4, !tbaa !12
  %47 = call ptr @create_float_array_buffer(ptr noundef %40, i32 noundef %43, i32 noundef %46)
  store ptr %47, ptr %9, align 8, !tbaa !5
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = icmp eq ptr %48, null
  br i1 %49, label %50, label %53

50:                                               ; preds = %37
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free_buf(ptr noundef %51)
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free_buf(ptr noundef %52)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %68

53:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.prepared_ncc_template_t, ptr %55, i32 0, i32 0
  %57 = load i32, ptr %56, align 8, !tbaa !9
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.prepared_ncc_template_t, ptr %58, i32 0, i32 1
  %60 = load i32, ptr %59, align 4, !tbaa !12
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = call i32 @prepare_ncc_template(ptr noundef %54, i32 noundef %57, i32 noundef %60, ptr noundef %61, ptr noundef %62)
  store i32 %63, ptr %10, align 4, !tbaa !15
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free_buf(ptr noundef %64)
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free_buf(ptr noundef %65)
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  call void @free_buf(ptr noundef %66)
  %67 = load i32, ptr %10, align 4, !tbaa !15
  store i32 %67, ptr %3, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %68

68:                                               ; preds = %53, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %69

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

70:                                               ; preds = %69, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %71 = load i32, ptr %3, align 4
  ret i32 %71
}

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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, !11, i64 0}
!10 = !{!"prepared_ncc_template_t", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!10, !6, i64 8}
!14 = !{!10, !6, i64 16}
!15 = !{!11, !11, 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"

declare ptr @create_rgba_buffer(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare void @free_buf(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @libprepare_ncc_tpl(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = load i32, ptr %1, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %1, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !11
  %6 = tail call ptr @create_rgba_buffer(ptr noundef %0, i32 noundef %3, i32 noundef %5) #2
  %7 = icmp eq ptr %6, null
  br i1 %7, label %26, label %8

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = load i32, ptr %1, align 8, !tbaa !5
  %12 = load i32, ptr %4, align 4, !tbaa !11
  %13 = tail call ptr @create_float_array_buffer(ptr noundef %10, i32 noundef %11, i32 noundef %12) #2
  %14 = icmp eq ptr %13, null
  br i1 %14, label %.sink.split, label %15

15:                                               ; preds = %8
  %16 = getelementptr inbounds i8, ptr %1, i64 16
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %18 = load i32, ptr %1, align 8, !tbaa !5
  %19 = load i32, ptr %4, align 4, !tbaa !11
  %20 = tail call ptr @create_float_array_buffer(ptr noundef %17, i32 noundef %18, i32 noundef %19) #2
  %21 = icmp eq ptr %20, null
  br i1 %21, label %.sink.split.sink.split, label %22

22:                                               ; preds = %15
  %23 = load i32, ptr %1, align 8, !tbaa !5
  %24 = load i32, ptr %4, align 4, !tbaa !11
  %25 = tail call i32 @prepare_ncc_template(ptr noundef nonnull %6, i32 noundef %23, i32 noundef %24, ptr noundef nonnull %13, ptr noundef nonnull %20) #2
  tail call void @free_buf(ptr noundef nonnull %6) #2
  br label %.sink.split.sink.split

.sink.split.sink.split:                           ; preds = %15, %22
  %.sink27 = phi ptr [ %13, %22 ], [ %6, %15 ]
  %.sink.ph = phi ptr [ %20, %22 ], [ %13, %15 ]
  %.2.ph.ph = phi i32 [ %25, %22 ], [ 1, %15 ]
  tail call void @free_buf(ptr noundef nonnull %.sink27) #2
  br label %.sink.split

.sink.split:                                      ; preds = %.sink.split.sink.split, %8
  %.sink = phi ptr [ %6, %8 ], [ %.sink.ph, %.sink.split.sink.split ]
  %.2.ph = phi i32 [ 1, %8 ], [ %.2.ph.ph, %.sink.split.sink.split ]
  tail call void @free_buf(ptr noundef nonnull %.sink) #2
  br label %26

26:                                               ; preds = %.sink.split, %2
  %.2 = phi i32 [ 1, %2 ], [ %.2.ph, %.sink.split ]
  ret i32 %.2
}

declare ptr @create_float_array_buffer(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare i32 @prepare_ncc_template(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

attributes #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 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 = { 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 = !{!"prepared_ncc_template_t", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !10, i64 8}
!13 = !{!6, !10, i64 16}


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