; LLVM IR from ejoy/ejoy2d :: lib (texture)

; 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.texture_pool = type { i32, [128 x %struct.texture] }
%struct.texture = type { i32, i32, float, float, i32, i32 }

@R = external hidden global ptr, align 8
@.str = external hidden unnamed_addr constant [17 x i8], align 1
@POOL = external hidden global %struct.texture_pool, align 4

; 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

; Function Attrs: nounwind uwtable
define dso_local ptr @texture_new_rt(i32 noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = icmp sge i32 %9, 128
  br i1 %10, label %11, label %12

11:                                               ; preds = %3
  store ptr @.str, ptr %4, align 8
  br label %58

12:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [128 x %struct.texture], ptr getelementptr inbounds (%struct.texture_pool, ptr @POOL, i32 0, i32 1), i64 0, i64 %14
  store ptr %15, ptr %8, align 8, !tbaa !9
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = load i32, ptr @POOL, align 4, !tbaa !11
  %18 = icmp sge i32 %16, %17
  br i1 %18, label %19, label %22

19:                                               ; preds = %12
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr @POOL, align 4, !tbaa !11
  br label %22

22:                                               ; preds = %19, %12
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = load ptr, ptr %8, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.texture, ptr %24, i32 0, i32 0
  store i32 %23, ptr %25, align 4, !tbaa !13
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = load ptr, ptr %8, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.texture, ptr %27, i32 0, i32 1
  store i32 %26, ptr %28, align 4, !tbaa !16
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = sitofp i32 %29 to float
  %31 = fdiv float 1.000000e+00, %30
  %32 = load ptr, ptr %8, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.texture, ptr %32, i32 0, i32 2
  store float %31, ptr %33, align 4, !tbaa !17
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = sitofp i32 %34 to float
  %36 = fdiv float 1.000000e+00, %35
  %37 = load ptr, ptr %8, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.texture, ptr %37, i32 0, i32 3
  store float %36, ptr %38, align 4, !tbaa !18
  %39 = load ptr, ptr %8, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.texture, ptr %39, i32 0, i32 4
  %41 = load i32, ptr %40, align 4, !tbaa !19
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %57

43:                                               ; preds = %22
  %44 = load ptr, ptr @R, align 8, !tbaa !9
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = call i32 @render_target_create(ptr noundef %44, i32 noundef %45, i32 noundef %46, i32 noundef 1)
  %48 = load ptr, ptr %8, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.texture, ptr %48, i32 0, i32 5
  store i32 %47, ptr %49, align 4, !tbaa !20
  %50 = load ptr, ptr @R, align 8, !tbaa !9
  %51 = load ptr, ptr %8, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.texture, ptr %51, i32 0, i32 5
  %53 = load i32, ptr %52, align 4, !tbaa !20
  %54 = call i32 @render_target_texture(ptr noundef %50, i32 noundef %53)
  %55 = load ptr, ptr %8, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.texture, ptr %55, i32 0, i32 4
  store i32 %54, ptr %56, align 4, !tbaa !19
  br label %57

57:                                               ; preds = %43, %22
  store ptr null, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %58

58:                                               ; preds = %57, %11
  %59 = load ptr, ptr %4, align 8
  ret ptr %59
}

declare i32 @render_target_create(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #2

declare i32 @render_target_texture(ptr noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"texture_pool", !6, i64 0, !7, i64 4}
!13 = !{!14, !6, i64 0}
!14 = !{!"texture", !6, i64 0, !6, i64 4, !15, i64 8, !15, i64 12, !6, i64 16, !6, i64 20}
!15 = !{!"float", !7, i64 0}
!16 = !{!14, !6, i64 4}
!17 = !{!14, !15, i64 8}
!18 = !{!14, !15, i64 12}
!19 = !{!14, !6, i64 16}
!20 = !{!14, !6, i64 20}


; 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.texture_pool = type { i32, [128 x %struct.texture] }
%struct.texture = type { i32, i32, float, float, i32, i32 }

@R = external hidden local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [17 x i8], align 1
@POOL = external hidden local_unnamed_addr global %struct.texture_pool, align 4

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @texture_new_rt(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp sgt i32 %0, 127
  br i1 %4, label %27, label %5

5:                                                ; preds = %3
  %6 = sext i32 %0 to i64
  %7 = getelementptr inbounds [128 x %struct.texture], ptr getelementptr inbounds (i8, ptr @POOL, i64 4), i64 0, i64 %6
  %8 = load i32, ptr @POOL, align 4, !tbaa !5
  %.not = icmp sgt i32 %8, %0
  br i1 %.not, label %11, label %9

9:                                                ; preds = %5
  %10 = add nsw i32 %0, 1
  store i32 %10, ptr @POOL, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %9, %5
  store i32 %1, ptr %7, align 4, !tbaa !10
  %12 = getelementptr inbounds i8, ptr %7, i64 4
  store i32 %2, ptr %12, align 4, !tbaa !13
  %13 = insertelement <2 x i32> poison, i32 %1, i64 0
  %14 = insertelement <2 x i32> %13, i32 %2, i64 1
  %15 = sitofp <2 x i32> %14 to <2 x float>
  %16 = getelementptr inbounds i8, ptr %7, i64 8
  %17 = fdiv <2 x float> <float 1.000000e+00, float 1.000000e+00>, %15
  store <2 x float> %17, ptr %16, align 4, !tbaa !14
  %18 = getelementptr inbounds i8, ptr %7, i64 16
  %19 = load i32, ptr %18, align 4, !tbaa !15
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %27

21:                                               ; preds = %11
  %22 = load ptr, ptr @R, align 8, !tbaa !16
  %23 = tail call i32 @render_target_create(ptr noundef %22, i32 noundef %1, i32 noundef %2, i32 noundef 1) #2
  %24 = getelementptr inbounds i8, ptr %7, i64 20
  store i32 %23, ptr %24, align 4, !tbaa !18
  %25 = load ptr, ptr @R, align 8, !tbaa !16
  %26 = tail call i32 @render_target_texture(ptr noundef %25, i32 noundef %23) #2
  store i32 %26, ptr %18, align 4, !tbaa !15
  br label %27

27:                                               ; preds = %11, %21, %3
  %.0 = phi ptr [ @.str, %3 ], [ null, %21 ], [ null, %11 ]
  ret ptr %.0
}

declare i32 @render_target_create(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare i32 @render_target_texture(ptr noundef, i32 noundef) local_unnamed_addr #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 = { "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 = !{!"texture_pool", !7, i64 0, !8, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 0}
!11 = !{!"texture", !7, i64 0, !7, i64 4, !12, i64 8, !12, i64 12, !7, i64 16, !7, i64 20}
!12 = !{!"float", !8, i64 0}
!13 = !{!11, !7, i64 4}
!14 = !{!12, !12, i64 0}
!15 = !{!11, !7, i64 16}
!16 = !{!17, !17, i64 0}
!17 = !{!"any pointer", !8, i64 0}
!18 = !{!11, !7, i64 20}


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