; LLVM IR from Overload-Technologies/Overload :: Dependencies/assimp/code/Common (Bitmap)

; 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.aiTexture = type <{ i32, i32, [9 x i8], [7 x i8], ptr, %struct.aiString, [4 x i8] }>
%struct.aiString = type { i32, [1024 x i8] }
%struct.aiTexel = type { i8, i8, i8, i8 }

@_ZZN6Assimp6Bitmap9WriteDataEP9aiTexturePNS_8IOStreamEE12padding_data = external hidden constant [4 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: mustprogress uwtable
define dso_local void @_ZN6Assimp6Bitmap9WriteDataEP9aiTexturePNS_8IOStreamE(ptr noundef %0, ptr noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca [4 x i8], align 1
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.aiTexture, ptr %11, i32 0, i32 0
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = zext i32 %13 to i64
  %15 = mul i64 4, %14
  %16 = urem i64 %15, 4
  %17 = sub i64 4, %16
  %18 = urem i64 %17, 4
  %19 = trunc i64 %18 to i32
  store i32 %19, ptr %5, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 0, ptr %7, align 8, !tbaa !14
  br label %20

20:                                               ; preds = %93, %2
  %21 = load i64, ptr %7, align 8, !tbaa !14
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.aiTexture, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 4, !tbaa !16
  %25 = zext i32 %24 to i64
  %26 = icmp ult i64 %21, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %20
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %96

28:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store i64 0, ptr %9, align 8, !tbaa !14
  br label %29

29:                                               ; preds = %78, %28
  %30 = load i64, ptr %9, align 8, !tbaa !14
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.aiTexture, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !9
  %34 = zext i32 %33 to i64
  %35 = icmp ult i64 %30, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %29
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %81

37:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.aiTexture, ptr %38, i32 0, i32 4
  %40 = load ptr, ptr %39, align 8, !tbaa !17
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.aiTexture, ptr %41, i32 0, i32 1
  %43 = load i32, ptr %42, align 4, !tbaa !16
  %44 = zext i32 %43 to i64
  %45 = load i64, ptr %7, align 8, !tbaa !14
  %46 = sub i64 %44, %45
  %47 = sub i64 %46, 1
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.aiTexture, ptr %48, i32 0, i32 0
  %50 = load i32, ptr %49, align 8, !tbaa !9
  %51 = zext i32 %50 to i64
  %52 = mul i64 %47, %51
  %53 = load i64, ptr %9, align 8, !tbaa !14
  %54 = add i64 %52, %53
  %55 = getelementptr inbounds %struct.aiTexel, ptr %40, i64 %54
  store ptr %55, ptr %10, align 8, !tbaa !5
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.aiTexel, ptr %56, i32 0, i32 2
  %58 = load i8, ptr %57, align 1, !tbaa !18
  %59 = getelementptr inbounds [4 x i8], ptr %6, i64 0, i64 0
  store i8 %58, ptr %59, align 1, !tbaa !20
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.aiTexel, ptr %60, i32 0, i32 1
  %62 = load i8, ptr %61, align 1, !tbaa !21
  %63 = getelementptr inbounds [4 x i8], ptr %6, i64 0, i64 1
  store i8 %62, ptr %63, align 1, !tbaa !20
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.aiTexel, ptr %64, i32 0, i32 0
  %66 = load i8, ptr %65, align 1, !tbaa !22
  %67 = getelementptr inbounds [4 x i8], ptr %6, i64 0, i64 2
  store i8 %66, ptr %67, align 1, !tbaa !20
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.aiTexel, ptr %68, i32 0, i32 3
  %70 = load i8, ptr %69, align 1, !tbaa !23
  %71 = getelementptr inbounds [4 x i8], ptr %6, i64 0, i64 3
  store i8 %70, ptr %71, align 1, !tbaa !20
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds [4 x i8], ptr %6, i64 0, i64 0
  %74 = load ptr, ptr %72, align 8, !tbaa !24
  %75 = getelementptr inbounds ptr, ptr %74, i64 3
  %76 = load ptr, ptr %75, align 8
  %77 = call noundef i64 %76(ptr noundef nonnull align 8 dereferenceable(8) %72, ptr noundef %73, i64 noundef 4, i64 noundef 1)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %78

78:                                               ; preds = %37
  %79 = load i64, ptr %9, align 8, !tbaa !14
  %80 = add i64 %79, 1
  store i64 %80, ptr %9, align 8, !tbaa !14
  br label %29, !llvm.loop !26

81:                                               ; preds = %36
  %82 = load i32, ptr %5, align 4, !tbaa !13
  %83 = icmp ne i32 %82, 0
  br i1 %83, label %84, label %92

84:                                               ; preds = %81
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = load i32, ptr %5, align 4, !tbaa !13
  %87 = zext i32 %86 to i64
  %88 = load ptr, ptr %85, align 8, !tbaa !24
  %89 = getelementptr inbounds ptr, ptr %88, i64 3
  %90 = load ptr, ptr %89, align 8
  %91 = call noundef i64 %90(ptr noundef nonnull align 8 dereferenceable(8) %85, ptr noundef @_ZZN6Assimp6Bitmap9WriteDataEP9aiTexturePNS_8IOStreamEE12padding_data, i64 noundef %87, i64 noundef 1)
  br label %92

92:                                               ; preds = %84, %81
  br label %93

93:                                               ; preds = %92
  %94 = load i64, ptr %7, align 8, !tbaa !14
  %95 = add i64 %94, 1
  store i64 %95, ptr %7, align 8, !tbaa !14
  br label %20, !llvm.loop !28

96:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS9aiTexture", !11, i64 0, !11, i64 4, !7, i64 8, !6, i64 24, !12, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTS8aiString", !11, i64 0, !7, i64 4}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!10, !11, i64 4}
!17 = !{!10, !6, i64 24}
!18 = !{!19, !7, i64 2}
!19 = !{!"_ZTS7aiTexel", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3}
!20 = !{!7, !7, i64 0}
!21 = !{!19, !7, i64 1}
!22 = !{!19, !7, i64 0}
!23 = !{!19, !7, i64 3}
!24 = !{!25, !25, i64 0}
!25 = !{!"vtable pointer", !8, i64 0}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}
!28 = distinct !{!28, !27}


; 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.aiTexel = type { i8, i8, i8, i8 }

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6Assimp6Bitmap9WriteDataEP9aiTexturePNS_8IOStreamE(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = alloca [4 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #2
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %._crit_edge24, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = getelementptr inbounds i8, ptr %3, i64 1
  %8 = getelementptr inbounds i8, ptr %3, i64 2
  %9 = getelementptr inbounds i8, ptr %3, i64 3
  %.pre = load i32, ptr %0, align 8, !tbaa !12
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %10 = phi i32 [ %5, %.preheader.lr.ph ], [ %38, %._crit_edge ]
  %11 = phi i32 [ %.pre, %.preheader.lr.ph ], [ %39, %._crit_edge ]
  %.023 = phi i64 [ 0, %.preheader.lr.ph ], [ %40, %._crit_edge ]
  %.not25 = icmp eq i32 %11, 0
  br i1 %.not25, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %12 = zext i32 %11 to i64
  %13 = xor i64 %.023, -1
  br label %14

._crit_edge24:                                    ; preds = %._crit_edge, %2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #2
  ret void

14:                                               ; preds = %.lr.ph, %14
  %15 = phi i64 [ %12, %.lr.ph ], [ %36, %14 ]
  %.01922 = phi i64 [ 0, %.lr.ph ], [ %34, %14 ]
  %16 = load ptr, ptr %6, align 8, !tbaa !13
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = zext i32 %17 to i64
  %19 = add nsw i64 %18, %13
  %20 = mul i64 %19, %15
  %21 = getelementptr %struct.aiTexel, ptr %16, i64 %20
  %22 = getelementptr %struct.aiTexel, ptr %21, i64 %.01922
  %23 = getelementptr inbounds i8, ptr %22, i64 2
  %24 = load i8, ptr %23, align 1, !tbaa !14
  store i8 %24, ptr %3, align 1, !tbaa !16
  %25 = getelementptr inbounds i8, ptr %22, i64 1
  %26 = load i8, ptr %25, align 1, !tbaa !17
  store i8 %26, ptr %7, align 1, !tbaa !16
  %27 = load i8, ptr %22, align 1, !tbaa !18
  store i8 %27, ptr %8, align 1, !tbaa !16
  %28 = getelementptr inbounds i8, ptr %22, i64 3
  %29 = load i8, ptr %28, align 1, !tbaa !19
  store i8 %29, ptr %9, align 1, !tbaa !16
  %30 = load ptr, ptr %1, align 8, !tbaa !20
  %31 = getelementptr inbounds i8, ptr %30, i64 24
  %32 = load ptr, ptr %31, align 8
  %33 = call noundef i64 %32(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull %3, i64 noundef 4, i64 noundef 1)
  %34 = add nuw nsw i64 %.01922, 1
  %35 = load i32, ptr %0, align 8, !tbaa !12
  %36 = zext i32 %35 to i64
  %37 = icmp ult i64 %34, %36
  br i1 %37, label %14, label %._crit_edge.loopexit, !llvm.loop !22

._crit_edge.loopexit:                             ; preds = %14
  %.pre26 = load i32, ptr %4, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %38 = phi i32 [ %.pre26, %._crit_edge.loopexit ], [ %10, %.preheader ]
  %39 = phi i32 [ %35, %._crit_edge.loopexit ], [ 0, %.preheader ]
  %40 = add nuw nsw i64 %.023, 1
  %41 = zext i32 %38 to i64
  %42 = icmp ult i64 %40, %41
  br i1 %42, label %.preheader, label %._crit_edge24, !llvm.loop !24
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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 4}
!6 = !{!"_ZTS9aiTexture", !7, i64 0, !7, i64 4, !8, i64 8, !10, i64 24, !11, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_ZTS8aiString", !7, i64 0, !8, i64 4}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !10, i64 24}
!14 = !{!15, !8, i64 2}
!15 = !{!"_ZTS7aiTexel", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3}
!16 = !{!8, !8, i64 0}
!17 = !{!15, !8, i64 1}
!18 = !{!15, !8, i64 0}
!19 = !{!15, !8, i64 3}
!20 = !{!21, !21, i64 0}
!21 = !{!"vtable pointer", !9, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = distinct !{!24, !23}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass