; LLVM IR from TheNachoBIT/GeoFenix-Engine :: Libraries/SOIL2/include (image_DXT)

; 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.DDS_header = type { i32, i32, i32, i32, i32, i32, i32, i32, [11 x i32], %struct.anon, %struct.anon.0, i32 }
%struct.anon = type { i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.anon.0 = type { i32, i32, i32, i32 }

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

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

19:                                               ; preds = %5
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = icmp slt i32 %20, 1
  br i1 %21, label %34, label %22

22:                                               ; preds = %19
  %23 = load i32, ptr %9, align 4, !tbaa !9
  %24 = icmp slt i32 %23, 1
  br i1 %24, label %34, label %25

25:                                               ; preds = %22
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = icmp slt i32 %26, 1
  br i1 %27, label %34, label %28

28:                                               ; preds = %25
  %29 = load i32, ptr %10, align 4, !tbaa !9
  %30 = icmp sgt i32 %29, 4
  br i1 %30, label %34, label %31

31:                                               ; preds = %28
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = icmp eq ptr %32, null
  br i1 %33, label %34, label %35

34:                                               ; preds = %31, %28, %25, %22, %19, %5
  store i32 0, ptr %6, align 4
  store i32 1, ptr %16, align 4
  br label %89

35:                                               ; preds = %31
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = and i32 %36, 1
  %38 = icmp eq i32 %37, 1
  br i1 %38, label %39, label %45

39:                                               ; preds = %35
  %40 = load ptr, ptr %11, align 8, !tbaa !5
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = load i32, ptr %9, align 4, !tbaa !9
  %43 = load i32, ptr %10, align 4, !tbaa !9
  %44 = call ptr @convert_image_to_DXT1(ptr noundef %40, i32 noundef %41, i32 noundef %42, i32 noundef %43, ptr noundef %15)
  store ptr %44, ptr %13, align 8, !tbaa !5
  br label %51

45:                                               ; preds = %35
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = load i32, ptr %10, align 4, !tbaa !9
  %50 = call ptr @convert_image_to_DXT5(ptr noundef %46, i32 noundef %47, i32 noundef %48, i32 noundef %49, ptr noundef %15)
  store ptr %50, ptr %13, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %45, %39
  call void @llvm.memset.p0.i64(ptr align 4 %14, i8 0, i64 128, i1 false)
  %52 = getelementptr inbounds %struct.DDS_header, ptr %14, i32 0, i32 0
  store i32 542327876, ptr %52, align 4, !tbaa !11
  %53 = getelementptr inbounds %struct.DDS_header, ptr %14, i32 0, i32 1
  store i32 124, ptr %53, align 4, !tbaa !15
  %54 = getelementptr inbounds %struct.DDS_header, ptr %14, i32 0, i32 2
  store i32 528391, ptr %54, align 4, !tbaa !16
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = getelementptr inbounds %struct.DDS_header, ptr %14, i32 0, i32 4
  store i32 %55, ptr %56, align 4, !tbaa !17
  %57 = load i32, ptr %9, align 4, !tbaa !9
  %58 = getelementptr inbounds %struct.DDS_header, ptr %14, i32 0, i32 3
  store i32 %57, ptr %58, align 4, !tbaa !18
  %59 = load i32, ptr %15, align 4, !tbaa !9
  %60 = getelementptr inbounds %struct.DDS_header, ptr %14, i32 0, i32 5
  store i32 %59, ptr %60, align 4, !tbaa !19
  %61 = getelementptr inbounds %struct.DDS_header, ptr %14, i32 0, i32 9
  %62 = getelementptr inbounds %struct.anon, ptr %61, i32 0, i32 0
  store i32 32, ptr %62, align 4, !tbaa !20
  %63 = getelementptr inbounds %struct.DDS_header, ptr %14, i32 0, i32 9
  %64 = getelementptr inbounds %struct.anon, ptr %63, i32 0, i32 1
  store i32 4, ptr %64, align 4, !tbaa !21
  %65 = load i32, ptr %10, align 4, !tbaa !9
  %66 = and i32 %65, 1
  %67 = icmp eq i32 %66, 1
  br i1 %67, label %68, label %71

68:                                               ; preds = %51
  %69 = getelementptr inbounds %struct.DDS_header, ptr %14, i32 0, i32 9
  %70 = getelementptr inbounds %struct.anon, ptr %69, i32 0, i32 2
  store i32 827611204, ptr %70, align 4, !tbaa !22
  br label %74

71:                                               ; preds = %51
  %72 = getelementptr inbounds %struct.DDS_header, ptr %14, i32 0, i32 9
  %73 = getelementptr inbounds %struct.anon, ptr %72, i32 0, i32 2
  store i32 894720068, ptr %73, align 4, !tbaa !22
  br label %74

74:                                               ; preds = %71, %68
  %75 = getelementptr inbounds %struct.DDS_header, ptr %14, i32 0, i32 10
  %76 = getelementptr inbounds %struct.anon.0, ptr %75, i32 0, i32 0
  store i32 4096, ptr %76, align 4, !tbaa !23
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = call noalias ptr @fopen(ptr noundef %77, ptr noundef @.str)
  store ptr %78, ptr %12, align 8, !tbaa !5
  %79 = load ptr, ptr %12, align 8, !tbaa !5
  %80 = call i64 @fwrite(ptr noundef %14, i64 noundef 128, i64 noundef 1, ptr noundef %79)
  %81 = load ptr, ptr %13, align 8, !tbaa !5
  %82 = load i32, ptr %15, align 4, !tbaa !9
  %83 = sext i32 %82 to i64
  %84 = load ptr, ptr %12, align 8, !tbaa !5
  %85 = call i64 @fwrite(ptr noundef %81, i64 noundef 1, i64 noundef %83, ptr noundef %84)
  %86 = load ptr, ptr %12, align 8, !tbaa !5
  %87 = call i32 @fclose(ptr noundef %86)
  %88 = load ptr, ptr %13, align 8, !tbaa !5
  call void @free(ptr noundef %88) #5
  store i32 1, ptr %6, align 4
  store i32 1, ptr %16, align 4
  br label %89

89:                                               ; preds = %74, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 128, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %90 = load i32, ptr %6, align 4
  ret i32 %90
}

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare noalias ptr @fopen(ptr noundef, ptr noundef) #3

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #3

declare i32 @fclose(ptr noundef) #3

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

; 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 "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 #5 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !7, i64 32, !13, i64 76, !14, i64 108, !10, i64 124}
!13 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!14 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!15 = !{!12, !10, i64 4}
!16 = !{!12, !10, i64 8}
!17 = !{!12, !10, i64 16}
!18 = !{!12, !10, i64 12}
!19 = !{!12, !10, i64 20}
!20 = !{!12, !10, i64 76}
!21 = !{!12, !10, i64 80}
!22 = !{!12, !10, i64 84}
!23 = !{!12, !10, i64 108}


; 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.DDS_header = type { i32, i32, i32, i32, i32, i32, i32, i32, [11 x i32], %struct.anon, %struct.anon.0, i32 }
%struct.anon = type { i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.anon.0 = type { i32, i32, i32, i32 }

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @save_image_as_DDS(ptr noundef readonly %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = alloca %struct.DDS_header, align 4
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #5
  %8 = icmp eq ptr %0, null
  %9 = icmp slt i32 %1, 1
  %or.cond = or i1 %8, %9
  %10 = icmp slt i32 %2, 1
  %or.cond3 = or i1 %or.cond, %10
  %11 = add i32 %3, -5
  %12 = icmp ult i32 %11, -4
  %or.cond7 = or i1 %or.cond3, %12
  %13 = icmp eq ptr %4, null
  %or.cond9 = or i1 %13, %or.cond7
  br i1 %or.cond9, label %38, label %14

14:                                               ; preds = %5
  %15 = and i32 %3, 1
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %18, label %16

16:                                               ; preds = %14
  %17 = call ptr @convert_image_to_DXT1(ptr noundef nonnull %4, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef nonnull %7)
  br label %20

18:                                               ; preds = %14
  %19 = call ptr @convert_image_to_DXT5(ptr noundef nonnull %4, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef nonnull %7)
  br label %20

20:                                               ; preds = %18, %16
  %spec.select = phi i32 [ 827611204, %16 ], [ 894720068, %18 ]
  %.0 = phi ptr [ %17, %16 ], [ %19, %18 ]
  %21 = getelementptr inbounds i8, ptr %6, i64 24
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(128) %21, i8 0, i64 104, i1 false)
  store i32 542327876, ptr %6, align 4, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %6, i64 4
  store i32 124, ptr %22, align 4, !tbaa !12
  %23 = getelementptr inbounds i8, ptr %6, i64 8
  store i32 528391, ptr %23, align 4, !tbaa !13
  %24 = getelementptr inbounds i8, ptr %6, i64 16
  store i32 %1, ptr %24, align 4, !tbaa !14
  %25 = getelementptr inbounds i8, ptr %6, i64 12
  store i32 %2, ptr %25, align 4, !tbaa !15
  %26 = load i32, ptr %7, align 4, !tbaa !16
  %27 = getelementptr inbounds i8, ptr %6, i64 20
  store i32 %26, ptr %27, align 4, !tbaa !17
  %28 = getelementptr inbounds i8, ptr %6, i64 76
  store i32 32, ptr %28, align 4, !tbaa !18
  %29 = getelementptr inbounds i8, ptr %6, i64 80
  store i32 4, ptr %29, align 4, !tbaa !19
  %30 = getelementptr inbounds i8, ptr %6, i64 84
  store i32 %spec.select, ptr %30, align 4
  %31 = getelementptr inbounds i8, ptr %6, i64 108
  store i32 4096, ptr %31, align 4, !tbaa !20
  %32 = call noalias ptr @fopen(ptr noundef nonnull %0, ptr noundef nonnull @.str)
  %33 = call i64 @fwrite(ptr noundef nonnull %6, i64 noundef 128, i64 noundef 1, ptr noundef %32)
  %34 = load i32, ptr %7, align 4, !tbaa !16
  %35 = sext i32 %34 to i64
  %36 = call i64 @fwrite(ptr noundef %.0, i64 noundef 1, i64 noundef %35, ptr noundef %32)
  %37 = call i32 @fclose(ptr noundef %32)
  call void @free(ptr noundef %.0) #5
  br label %38

38:                                               ; preds = %5, %20
  %.033 = phi i32 [ 1, %20 ], [ 0, %5 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %6) #5
  ret i32 %.033
}

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

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #4

; 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nofree 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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #5 = { 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 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !8, i64 32, !10, i64 76, !11, i64 108, !7, i64 124}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28}
!11 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!12 = !{!6, !7, i64 4}
!13 = !{!6, !7, i64 8}
!14 = !{!6, !7, i64 16}
!15 = !{!6, !7, i64 12}
!16 = !{!7, !7, i64 0}
!17 = !{!6, !7, i64 20}
!18 = !{!6, !7, i64 76}
!19 = !{!6, !7, i64 80}
!20 = !{!6, !7, i64 108}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass