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

; 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"

@result_string_pointer = external dso_local global ptr, align 8
@.str.36 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [12 x i8], align 1

; 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
declare dso_local i32 @stbi_write_bmp(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) #1

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

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

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

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

20:                                               ; preds = %7
  %21 = load i32, ptr %12, align 4, !tbaa !9
  %22 = icmp slt i32 %21, 1
  br i1 %22, label %35, label %23

23:                                               ; preds = %20
  %24 = load i32, ptr %13, align 4, !tbaa !9
  %25 = icmp slt i32 %24, 1
  br i1 %25, label %35, label %26

26:                                               ; preds = %23
  %27 = load i32, ptr %13, align 4, !tbaa !9
  %28 = icmp sgt i32 %27, 4
  br i1 %28, label %35, label %29

29:                                               ; preds = %26
  %30 = load ptr, ptr %14, align 8, !tbaa !5
  %31 = icmp eq ptr %30, null
  br i1 %31, label %35, label %32

32:                                               ; preds = %29
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = icmp eq ptr %33, null
  br i1 %34, label %35, label %36

35:                                               ; preds = %32, %29, %26, %23, %20, %7
  store i32 0, ptr %8, align 4
  store i32 1, ptr %17, align 4
  br label %99

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

39:                                               ; preds = %36
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = load i32, ptr %11, align 4, !tbaa !9
  %42 = load i32, ptr %12, align 4, !tbaa !9
  %43 = load i32, ptr %13, align 4, !tbaa !9
  %44 = load ptr, ptr %14, align 8, !tbaa !5
  %45 = call i32 @stbi_write_bmp(ptr noundef %40, i32 noundef %41, i32 noundef %42, i32 noundef %43, ptr noundef %44)
  store i32 %45, ptr %16, align 4, !tbaa !9
  br label %92

46:                                               ; preds = %36
  %47 = load i32, ptr %10, align 4, !tbaa !9
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %56

49:                                               ; preds = %46
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = load i32, ptr %11, align 4, !tbaa !9
  %52 = load i32, ptr %12, align 4, !tbaa !9
  %53 = load i32, ptr %13, align 4, !tbaa !9
  %54 = load ptr, ptr %14, align 8, !tbaa !5
  %55 = call i32 @stbi_write_tga(ptr noundef %50, i32 noundef %51, i32 noundef %52, i32 noundef %53, ptr noundef %54)
  store i32 %55, ptr %16, align 4, !tbaa !9
  br label %91

56:                                               ; preds = %46
  %57 = load i32, ptr %10, align 4, !tbaa !9
  %58 = icmp eq i32 %57, 3
  br i1 %58, label %59, label %66

59:                                               ; preds = %56
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = load i32, ptr %11, align 4, !tbaa !9
  %62 = load i32, ptr %12, align 4, !tbaa !9
  %63 = load i32, ptr %13, align 4, !tbaa !9
  %64 = load ptr, ptr %14, align 8, !tbaa !5
  %65 = call i32 @save_image_as_DDS(ptr noundef %60, i32 noundef %61, i32 noundef %62, i32 noundef %63, ptr noundef %64)
  store i32 %65, ptr %16, align 4, !tbaa !9
  br label %90

66:                                               ; preds = %56
  %67 = load i32, ptr %10, align 4, !tbaa !9
  %68 = icmp eq i32 %67, 2
  br i1 %68, label %69, label %76

69:                                               ; preds = %66
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = load i32, ptr %11, align 4, !tbaa !9
  %72 = load i32, ptr %12, align 4, !tbaa !9
  %73 = load i32, ptr %13, align 4, !tbaa !9
  %74 = load ptr, ptr %14, align 8, !tbaa !5
  %75 = call i32 @stbi_write_png(ptr noundef %70, i32 noundef %71, i32 noundef %72, i32 noundef %73, ptr noundef %74, i32 noundef 0)
  store i32 %75, ptr %16, align 4, !tbaa !9
  br label %89

76:                                               ; preds = %66
  %77 = load i32, ptr %10, align 4, !tbaa !9
  %78 = icmp eq i32 %77, 4
  br i1 %78, label %79, label %87

79:                                               ; preds = %76
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  %81 = load ptr, ptr %14, align 8, !tbaa !5
  %82 = load i32, ptr %11, align 4, !tbaa !9
  %83 = load i32, ptr %12, align 4, !tbaa !9
  %84 = load i32, ptr %13, align 4, !tbaa !9
  %85 = load i32, ptr %15, align 4, !tbaa !9
  %86 = call i32 @jo_write_jpg(ptr noundef %80, ptr noundef %81, i32 noundef %82, i32 noundef %83, i32 noundef %84, i32 noundef %85)
  store i32 %86, ptr %16, align 4, !tbaa !9
  br label %88

87:                                               ; preds = %76
  store i32 0, ptr %16, align 4, !tbaa !9
  br label %88

88:                                               ; preds = %87, %79
  br label %89

89:                                               ; preds = %88, %69
  br label %90

90:                                               ; preds = %89, %59
  br label %91

91:                                               ; preds = %90, %49
  br label %92

92:                                               ; preds = %91, %39
  %93 = load i32, ptr %16, align 4, !tbaa !9
  %94 = icmp eq i32 %93, 0
  br i1 %94, label %95, label %96

95:                                               ; preds = %92
  store ptr @.str.36, ptr @result_string_pointer, align 8, !tbaa !5
  br label %97

96:                                               ; preds = %92
  store ptr @.str.37, ptr @result_string_pointer, align 8, !tbaa !5
  br label %97

97:                                               ; preds = %96, %95
  %98 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %98, ptr %8, align 4
  store i32 1, ptr %17, align 4
  br label %99

99:                                               ; preds = %97, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  %100 = load i32, ptr %8, align 4
  ret i32 %100
}

declare i32 @save_image_as_DDS(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr 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 = !{!"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}


; 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"

@result_string_pointer = external dso_local local_unnamed_addr global ptr, align 8
@.str.36 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [12 x i8], align 1

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @SOIL_save_image_quality(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5, i32 noundef %6) local_unnamed_addr #0 {
  %8 = icmp slt i32 %2, 1
  %9 = icmp slt i32 %3, 1
  %or.cond = or i1 %8, %9
  %10 = add i32 %4, -5
  %11 = icmp ult i32 %10, -4
  %or.cond5 = or i1 %or.cond, %11
  %12 = icmp eq ptr %5, null
  %or.cond7 = or i1 %12, %or.cond5
  %13 = icmp eq ptr %0, null
  %or.cond9 = or i1 %13, %or.cond7
  br i1 %or.cond9, label %28, label %14

14:                                               ; preds = %7
  switch i32 %1, label %.thread [
    i32 1, label %15
    i32 0, label %17
    i32 3, label %19
    i32 2, label %21
    i32 4, label %23
  ]

15:                                               ; preds = %14
  %16 = tail call i32 @stbi_write_bmp(ptr noundef nonnull %0, i32 noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef nonnull %5)
  br label %25

17:                                               ; preds = %14
  %18 = tail call i32 @stbi_write_tga(ptr noundef nonnull %0, i32 noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef nonnull %5)
  br label %25

19:                                               ; preds = %14
  %20 = tail call i32 @save_image_as_DDS(ptr noundef nonnull %0, i32 noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef nonnull %5) #2
  br label %25

21:                                               ; preds = %14
  %22 = tail call i32 @stbi_write_png(ptr noundef nonnull %0, i32 noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef nonnull %5, i32 noundef 0)
  br label %25

23:                                               ; preds = %14
  %24 = tail call i32 @jo_write_jpg(ptr noundef nonnull %0, ptr noundef nonnull %5, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %6)
  br label %25

25:                                               ; preds = %17, %21, %23, %19, %15
  %.0 = phi i32 [ %16, %15 ], [ %18, %17 ], [ %20, %19 ], [ %22, %21 ], [ %24, %23 ]
  %.0.fr = freeze i32 %.0
  %26 = icmp eq i32 %.0.fr, 0
  %spec.select = select i1 %26, ptr @.str.36, ptr @.str.37
  br label %.thread

.thread:                                          ; preds = %25, %14
  %.055 = phi i32 [ 0, %14 ], [ %.0.fr, %25 ]
  %27 = phi ptr [ @.str.36, %14 ], [ %spec.select, %25 ]
  store ptr %27, ptr @result_string_pointer, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %7, %.thread
  %.048 = phi i32 [ %.055, %.thread ], [ 0, %7 ]
  ret i32 %.048
}

declare i32 @save_image_as_DDS(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass