; LLVM IR from steps3d/graphics-book :: Code/Libs/SOIL (SOIL)

; 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.3 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [43 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: nounwind uwtable
declare dso_local i32 @SOIL_direct_load_DDS(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #1

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

declare ptr @stbi_failure_reason() #2

; Function Attrs: nounwind uwtable
declare dso_local void @SOIL_free_image_data(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
declare dso_local i32 @query_cubemap_capability() #1

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

21:                                               ; preds = %5
  store ptr @.str.5, ptr @result_string_pointer, align 8, !tbaa !5
  store i32 0, ptr %6, align 4
  store i32 1, ptr %18, align 4
  br label %136

22:                                               ; preds = %5
  %23 = load i32, ptr %11, align 4, !tbaa !9
  %24 = and i32 %23, 64
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %36

26:                                               ; preds = %22
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = load i32, ptr %11, align 4, !tbaa !9
  %30 = call i32 @SOIL_direct_load_DDS(ptr noundef %27, i32 noundef %28, i32 noundef %29, i32 noundef 1)
  store i32 %30, ptr %17, align 4, !tbaa !9
  %31 = load i32, ptr %17, align 4, !tbaa !9
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %35

33:                                               ; preds = %26
  %34 = load i32, ptr %17, align 4, !tbaa !9
  store i32 %34, ptr %6, align 4
  store i32 1, ptr %18, align 4
  br label %136

35:                                               ; preds = %26
  br label %36

36:                                               ; preds = %35, %22
  store i32 0, ptr %16, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %90, %36
  %38 = load i32, ptr %16, align 4, !tbaa !9
  %39 = icmp slt i32 %38, 6
  br i1 %39, label %40, label %93

40:                                               ; preds = %37
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = load i32, ptr %16, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i8, ptr %41, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !11
  %46 = sext i8 %45 to i32
  %47 = icmp ne i32 %46, 78
  br i1 %47, label %48, label %89

48:                                               ; preds = %40
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = load i32, ptr %16, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i8, ptr %49, i64 %51
  %53 = load i8, ptr %52, align 1, !tbaa !11
  %54 = sext i8 %53 to i32
  %55 = icmp ne i32 %54, 83
  br i1 %55, label %56, label %89

56:                                               ; preds = %48
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = load i32, ptr %16, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i8, ptr %57, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !11
  %62 = sext i8 %61 to i32
  %63 = icmp ne i32 %62, 87
  br i1 %63, label %64, label %89

64:                                               ; preds = %56
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = load i32, ptr %16, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds i8, ptr %65, i64 %67
  %69 = load i8, ptr %68, align 1, !tbaa !11
  %70 = sext i8 %69 to i32
  %71 = icmp ne i32 %70, 69
  br i1 %71, label %72, label %89

72:                                               ; preds = %64
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = load i32, ptr %16, align 4, !tbaa !9
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds i8, ptr %73, i64 %75
  %77 = load i8, ptr %76, align 1, !tbaa !11
  %78 = sext i8 %77 to i32
  %79 = icmp ne i32 %78, 85
  br i1 %79, label %80, label %89

80:                                               ; preds = %72
  %81 = load ptr, ptr %8, align 8, !tbaa !5
  %82 = load i32, ptr %16, align 4, !tbaa !9
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds i8, ptr %81, i64 %83
  %85 = load i8, ptr %84, align 1, !tbaa !11
  %86 = sext i8 %85 to i32
  %87 = icmp ne i32 %86, 68
  br i1 %87, label %88, label %89

88:                                               ; preds = %80
  store ptr @.str.6, ptr @result_string_pointer, align 8, !tbaa !5
  store i32 0, ptr %6, align 4
  store i32 1, ptr %18, align 4
  br label %136

89:                                               ; preds = %80, %72, %64, %56, %48, %40
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr %16, align 4, !tbaa !9
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %16, align 4, !tbaa !9
  br label %37, !llvm.loop !12

93:                                               ; preds = %37
  %94 = call i32 @query_cubemap_capability()
  %95 = icmp ne i32 %94, 1
  br i1 %95, label %96, label %97

96:                                               ; preds = %93
  store ptr @.str.3, ptr @result_string_pointer, align 8, !tbaa !5
  store i32 0, ptr %6, align 4
  store i32 1, ptr %18, align 4
  br label %136

97:                                               ; preds = %93
  %98 = load ptr, ptr %7, align 8, !tbaa !5
  %99 = load i32, ptr %9, align 4, !tbaa !9
  %100 = call ptr @SOIL_load_image(ptr noundef %98, ptr noundef %13, ptr noundef %14, ptr noundef %15, i32 noundef %99)
  store ptr %100, ptr %12, align 8, !tbaa !5
  %101 = load i32, ptr %9, align 4, !tbaa !9
  %102 = icmp sge i32 %101, 1
  br i1 %102, label %103, label %108

103:                                              ; preds = %97
  %104 = load i32, ptr %9, align 4, !tbaa !9
  %105 = icmp sle i32 %104, 4
  br i1 %105, label %106, label %108

106:                                              ; preds = %103
  %107 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %107, ptr %15, align 4, !tbaa !9
  br label %108

108:                                              ; preds = %106, %103, %97
  %109 = load ptr, ptr %12, align 8, !tbaa !5
  %110 = icmp eq ptr null, %109
  br i1 %110, label %111, label %113

111:                                              ; preds = %108
  %112 = call ptr @stbi_failure_reason()
  store ptr %112, ptr @result_string_pointer, align 8, !tbaa !5
  store i32 0, ptr %6, align 4
  store i32 1, ptr %18, align 4
  br label %136

113:                                              ; preds = %108
  %114 = load i32, ptr %13, align 4, !tbaa !9
  %115 = load i32, ptr %14, align 4, !tbaa !9
  %116 = mul nsw i32 6, %115
  %117 = icmp ne i32 %114, %116
  br i1 %117, label %118, label %125

118:                                              ; preds = %113
  %119 = load i32, ptr %13, align 4, !tbaa !9
  %120 = mul nsw i32 6, %119
  %121 = load i32, ptr %14, align 4, !tbaa !9
  %122 = icmp ne i32 %120, %121
  br i1 %122, label %123, label %125

123:                                              ; preds = %118
  %124 = load ptr, ptr %12, align 8, !tbaa !5
  call void @SOIL_free_image_data(ptr noundef %124)
  store ptr @.str.7, ptr @result_string_pointer, align 8, !tbaa !5
  store i32 0, ptr %6, align 4
  store i32 1, ptr %18, align 4
  br label %136

125:                                              ; preds = %118, %113
  %126 = load ptr, ptr %12, align 8, !tbaa !5
  %127 = load i32, ptr %13, align 4, !tbaa !9
  %128 = load i32, ptr %14, align 4, !tbaa !9
  %129 = load i32, ptr %15, align 4, !tbaa !9
  %130 = load ptr, ptr %8, align 8, !tbaa !5
  %131 = load i32, ptr %10, align 4, !tbaa !9
  %132 = load i32, ptr %11, align 4, !tbaa !9
  %133 = call i32 @SOIL_create_OGL_single_cubemap(ptr noundef %126, i32 noundef %127, i32 noundef %128, i32 noundef %129, ptr noundef %130, i32 noundef %131, i32 noundef %132)
  store i32 %133, ptr %17, align 4, !tbaa !9
  %134 = load ptr, ptr %12, align 8, !tbaa !5
  call void @SOIL_free_image_data(ptr noundef %134)
  %135 = load i32, ptr %17, align 4, !tbaa !9
  store i32 %135, ptr %6, align 4
  store i32 1, ptr %18, align 4
  br label %136

136:                                              ; preds = %125, %123, %111, %96, %88, %33, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %137 = load i32, ptr %6, align 4
  ret i32 %137
}

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

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}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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.3 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [43 x i8], align 1

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

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

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

declare ptr @stbi_failure_reason() local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @SOIL_free_image_data(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress 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 @query_cubemap_capability() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @SOIL_load_OGL_single_cubemap(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #1 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8) #3
  %9 = icmp eq ptr %0, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %5
  store ptr @.str.5, ptr @result_string_pointer, align 8, !tbaa !5
  br label %53

11:                                               ; preds = %5
  %12 = and i32 %4, 64
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %15, label %13

13:                                               ; preds = %11
  %14 = tail call i32 @SOIL_direct_load_DDS(ptr noundef nonnull %0, i32 noundef %3, i32 noundef %4, i32 noundef 1)
  %.not42 = icmp eq i32 %14, 0
  br i1 %.not42, label %15, label %53

15:                                               ; preds = %13, %11
  %16 = load i8, ptr %1, align 1, !tbaa !9
  switch i8 %16, label %17 [
    i8 78, label %18
    i8 83, label %18
    i8 87, label %18
    i8 69, label %18
    i8 85, label %18
    i8 68, label %18
  ]

17:                                               ; preds = %30, %27, %24, %21, %18, %15
  store ptr @.str.6, ptr @result_string_pointer, align 8, !tbaa !5
  br label %53

18:                                               ; preds = %15, %15, %15, %15, %15, %15
  %19 = getelementptr inbounds i8, ptr %1, i64 1
  %20 = load i8, ptr %19, align 1, !tbaa !9
  switch i8 %20, label %17 [
    i8 78, label %21
    i8 83, label %21
    i8 87, label %21
    i8 69, label %21
    i8 85, label %21
    i8 68, label %21
  ]

21:                                               ; preds = %18, %18, %18, %18, %18, %18
  %22 = getelementptr inbounds i8, ptr %1, i64 2
  %23 = load i8, ptr %22, align 1, !tbaa !9
  switch i8 %23, label %17 [
    i8 78, label %24
    i8 83, label %24
    i8 87, label %24
    i8 69, label %24
    i8 85, label %24
    i8 68, label %24
  ]

24:                                               ; preds = %21, %21, %21, %21, %21, %21
  %25 = getelementptr inbounds i8, ptr %1, i64 3
  %26 = load i8, ptr %25, align 1, !tbaa !9
  switch i8 %26, label %17 [
    i8 78, label %27
    i8 83, label %27
    i8 87, label %27
    i8 69, label %27
    i8 85, label %27
    i8 68, label %27
  ]

27:                                               ; preds = %24, %24, %24, %24, %24, %24
  %28 = getelementptr inbounds i8, ptr %1, i64 4
  %29 = load i8, ptr %28, align 1, !tbaa !9
  switch i8 %29, label %17 [
    i8 78, label %30
    i8 83, label %30
    i8 87, label %30
    i8 69, label %30
    i8 85, label %30
    i8 68, label %30
  ]

30:                                               ; preds = %27, %27, %27, %27, %27, %27
  %31 = getelementptr inbounds i8, ptr %1, i64 5
  %32 = load i8, ptr %31, align 1, !tbaa !9
  switch i8 %32, label %17 [
    i8 78, label %33
    i8 83, label %33
    i8 87, label %33
    i8 69, label %33
    i8 85, label %33
    i8 68, label %33
  ]

33:                                               ; preds = %30, %30, %30, %30, %30, %30
  %34 = tail call i32 @query_cubemap_capability()
  %.not43 = icmp eq i32 %34, 1
  br i1 %.not43, label %36, label %35

35:                                               ; preds = %33
  store ptr @.str.3, ptr @result_string_pointer, align 8, !tbaa !5
  br label %53

36:                                               ; preds = %33
  %37 = call ptr @SOIL_load_image(ptr noundef nonnull %0, ptr noundef nonnull %6, ptr noundef nonnull %7, ptr noundef nonnull %8, i32 noundef %2)
  %38 = add i32 %2, -1
  %or.cond = icmp ult i32 %38, 4
  br i1 %or.cond, label %39, label %40

39:                                               ; preds = %36
  store i32 %2, ptr %8, align 4, !tbaa !10
  br label %40

40:                                               ; preds = %39, %36
  %41 = icmp eq ptr %37, null
  br i1 %41, label %42, label %44

42:                                               ; preds = %40
  %43 = call ptr @stbi_failure_reason() #3
  store ptr %43, ptr @result_string_pointer, align 8, !tbaa !5
  br label %53

44:                                               ; preds = %40
  %45 = load i32, ptr %6, align 4, !tbaa !10
  %46 = load i32, ptr %7, align 4, !tbaa !10
  %47 = mul nsw i32 %46, 6
  %.not44 = icmp eq i32 %45, %47
  %48 = mul nsw i32 %45, 6
  %.not45 = icmp eq i32 %48, %46
  %or.cond52 = select i1 %.not44, i1 true, i1 %.not45
  br i1 %or.cond52, label %50, label %49

49:                                               ; preds = %44
  call void @SOIL_free_image_data(ptr noundef nonnull %37)
  store ptr @.str.7, ptr @result_string_pointer, align 8, !tbaa !5
  br label %53

50:                                               ; preds = %44
  %51 = load i32, ptr %8, align 4, !tbaa !10
  %52 = call i32 @SOIL_create_OGL_single_cubemap(ptr noundef nonnull %37, i32 noundef %45, i32 noundef %46, i32 noundef %51, ptr noundef nonnull %1, i32 noundef %3, i32 noundef %4)
  call void @SOIL_free_image_data(ptr noundef nonnull %37)
  br label %53

53:                                               ; preds = %13, %50, %49, %42, %35, %17, %10
  %.035 = phi i32 [ 0, %10 ], [ 0, %17 ], [ 0, %35 ], [ 0, %42 ], [ 0, %49 ], [ %52, %50 ], [ %14, %13 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  ret i32 %.035
}

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

attributes #0 = { mustprogress 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass