; 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: nounwind uwtable
define dso_local ptr @texture_load(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, i32 noundef %5) #0 {
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  store i32 %0, ptr %8, align 4, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !5
  store i32 %2, ptr %10, align 4, !tbaa !5
  store i32 %3, ptr %11, align 4, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !9
  store i32 %5, ptr %13, align 4, !tbaa !5
  %16 = load i32, ptr %8, align 4, !tbaa !5
  %17 = icmp sge i32 %16, 128
  br i1 %17, label %18, label %19

18:                                               ; preds = %6
  store ptr @.str, ptr %7, align 8
  br label %79

19:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %20 = load i32, ptr %8, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [128 x %struct.texture], ptr getelementptr inbounds (%struct.texture_pool, ptr @POOL, i32 0, i32 1), i64 0, i64 %21
  store ptr %22, ptr %14, align 8, !tbaa !9
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = load i32, ptr @POOL, align 4, !tbaa !11
  %25 = icmp sge i32 %23, %24
  br i1 %25, label %26, label %29

26:                                               ; preds = %19
  %27 = load i32, ptr %8, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr @POOL, align 4, !tbaa !11
  br label %29

29:                                               ; preds = %26, %19
  %30 = load ptr, ptr %14, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.texture, ptr %30, i32 0, i32 5
  store i32 0, ptr %31, align 4, !tbaa !13
  %32 = load i32, ptr %10, align 4, !tbaa !5
  %33 = load ptr, ptr %14, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.texture, ptr %33, i32 0, i32 0
  store i32 %32, ptr %34, align 4, !tbaa !16
  %35 = load i32, ptr %11, align 4, !tbaa !5
  %36 = load ptr, ptr %14, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.texture, ptr %36, i32 0, i32 1
  store i32 %35, ptr %37, align 4, !tbaa !17
  %38 = load i32, ptr %10, align 4, !tbaa !5
  %39 = sitofp i32 %38 to float
  %40 = fdiv float 1.000000e+00, %39
  %41 = load ptr, ptr %14, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.texture, ptr %41, i32 0, i32 2
  store float %40, ptr %42, align 4, !tbaa !18
  %43 = load i32, ptr %11, align 4, !tbaa !5
  %44 = sitofp i32 %43 to float
  %45 = fdiv float 1.000000e+00, %44
  %46 = load ptr, ptr %14, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.texture, ptr %46, i32 0, i32 3
  store float %45, ptr %47, align 4, !tbaa !19
  %48 = load ptr, ptr %14, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.texture, ptr %48, i32 0, i32 4
  %50 = load i32, ptr %49, align 4, !tbaa !20
  %51 = icmp eq i32 %50, 0
  br i1 %51, label %52, label %60

52:                                               ; preds = %29
  %53 = load ptr, ptr @R, align 8, !tbaa !9
  %54 = load i32, ptr %10, align 4, !tbaa !5
  %55 = load i32, ptr %11, align 4, !tbaa !5
  %56 = load i32, ptr %9, align 4, !tbaa !5
  %57 = call i32 @render_texture_create(ptr noundef %53, i32 noundef %54, i32 noundef %55, i32 noundef %56, i32 noundef 0, i32 noundef 0)
  %58 = load ptr, ptr %14, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.texture, ptr %58, i32 0, i32 4
  store i32 %57, ptr %59, align 4, !tbaa !20
  br label %60

60:                                               ; preds = %52, %29
  %61 = load ptr, ptr %12, align 8, !tbaa !9
  %62 = icmp eq ptr %61, null
  br i1 %62, label %63, label %64

63:                                               ; preds = %60
  store ptr null, ptr %7, align 8
  store i32 1, ptr %15, align 4
  br label %78

64:                                               ; preds = %60
  %65 = load i32, ptr %13, align 4, !tbaa !5
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %70

67:                                               ; preds = %64
  %68 = load i32, ptr %9, align 4, !tbaa !5
  %69 = load ptr, ptr %12, align 8, !tbaa !9
  call void @texture_downsample(i32 noundef %68, ptr noundef %10, ptr noundef %11, ptr noundef %69)
  br label %70

70:                                               ; preds = %67, %64
  %71 = load ptr, ptr @R, align 8, !tbaa !9
  %72 = load ptr, ptr %14, align 8, !tbaa !9
  %73 = getelementptr inbounds %struct.texture, ptr %72, i32 0, i32 4
  %74 = load i32, ptr %73, align 4, !tbaa !20
  %75 = load i32, ptr %10, align 4, !tbaa !5
  %76 = load i32, ptr %11, align 4, !tbaa !5
  %77 = load ptr, ptr %12, align 8, !tbaa !9
  call void @render_texture_update(ptr noundef %71, i32 noundef %74, i32 noundef %75, i32 noundef %76, ptr noundef %77, i32 noundef 0, i32 noundef 0)
  store ptr null, ptr %7, align 8
  store i32 1, ptr %15, align 4
  br label %78

78:                                               ; preds = %70, %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  br label %79

79:                                               ; preds = %78, %18
  %80 = load ptr, ptr %7, align 8
  ret ptr %80
}

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

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

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

declare void @render_texture_update(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef) #2

; 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 = !{!"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 20}
!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 0}
!17 = !{!14, !6, i64 4}
!18 = !{!14, !15, i64 8}
!19 = !{!14, !15, i64 12}
!20 = !{!14, !6, 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"

%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_load(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %2, ptr %7, align 4, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !5
  %9 = icmp sgt i32 %0, 127
  br i1 %9, label %40, label %10

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

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

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

27:                                               ; preds = %16
  %28 = load ptr, ptr @R, align 8, !tbaa !18
  %29 = tail call i32 @render_texture_create(ptr noundef %28, i32 noundef %2, i32 noundef %3, i32 noundef %1, i32 noundef 0, i32 noundef 0) #2
  store i32 %29, ptr %24, align 4, !tbaa !17
  br label %30

30:                                               ; preds = %27, %16
  %31 = phi i32 [ %29, %27 ], [ %25, %16 ]
  %32 = icmp eq ptr %4, null
  br i1 %32, label %40, label %33

33:                                               ; preds = %30
  %.not19 = icmp eq i32 %5, 0
  br i1 %.not19, label %35, label %34

34:                                               ; preds = %33
  call void @texture_downsample(i32 noundef %1, ptr noundef nonnull %7, ptr noundef nonnull %8, ptr noundef nonnull %4)
  %.pre = load i32, ptr %24, align 4, !tbaa !17
  %.pre20 = load i32, ptr %7, align 4, !tbaa !5
  %.pre21 = load i32, ptr %8, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %34, %33
  %36 = phi i32 [ %.pre21, %34 ], [ %3, %33 ]
  %37 = phi i32 [ %.pre20, %34 ], [ %2, %33 ]
  %38 = phi i32 [ %.pre, %34 ], [ %31, %33 ]
  %39 = load ptr, ptr @R, align 8, !tbaa !18
  call void @render_texture_update(ptr noundef %39, i32 noundef %38, i32 noundef %37, i32 noundef %36, ptr noundef nonnull %4, i32 noundef 0, i32 noundef 0) #2
  br label %40

40:                                               ; preds = %35, %30, %6
  %.1 = phi ptr [ @.str, %6 ], [ null, %30 ], [ null, %35 ]
  ret ptr %.1
}

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

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

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


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