; LLVM IR from nde-jesu/Doom_Nukem :: libbmp/srcs/chunks (image)

; 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.s_info = type { %struct.s_hdr, %struct.s_dib, i8, i8, i8, i32, i32, i32 }
%struct.s_hdr = type { i32, i32 }
%struct.s_dib = type { %struct.s_vec, %struct.s_vec, i8, i8, i8, i8, i32, i32, i32 }
%struct.s_vec = type { i32, i32 }
%struct.s_file = type { [15 x ptr], %struct.s_info, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @build_image(ptr noundef %0, ptr noundef %1, ptr noundef byval(%struct.s_info) align 8 %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %10 = getelementptr inbounds %struct.s_info, ptr %2, i32 0, i32 1
  %11 = getelementptr inbounds %struct.s_dib, ptr %10, i32 0, i32 1
  %12 = getelementptr inbounds %struct.s_vec, ptr %11, i32 0, i32 1
  %13 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %13, ptr %6, align 4, !tbaa !15
  store i32 0, ptr %8, align 4, !tbaa !15
  br label %14

14:                                               ; preds = %62, %3
  %15 = load i32, ptr %6, align 4, !tbaa !15
  %16 = add nsw i32 %15, -1
  store i32 %16, ptr %6, align 4, !tbaa !15
  %17 = icmp sge i32 %16, 0
  br i1 %17, label %18, label %63

18:                                               ; preds = %14
  store i32 0, ptr %8, align 4, !tbaa !15
  store i32 0, ptr %7, align 4, !tbaa !15
  br label %19

19:                                               ; preds = %24, %18
  %20 = load i32, ptr %8, align 4, !tbaa !15
  %21 = getelementptr inbounds %struct.s_info, ptr %2, i32 0, i32 5
  %22 = load i32, ptr %21, align 4, !tbaa !16
  %23 = icmp ult i32 %20, %22
  br i1 %23, label %24, label %62

24:                                               ; preds = %19
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load i32, ptr %8, align 4, !tbaa !15
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds i8, ptr %25, i64 %27
  %29 = load i32, ptr %6, align 4, !tbaa !15
  %30 = getelementptr inbounds %struct.s_info, ptr %2, i32 0, i32 7
  %31 = load i32, ptr %30, align 4, !tbaa !17
  %32 = mul i32 %29, %31
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds i8, ptr %28, i64 %33
  %35 = call i32 @build_pixel(ptr noundef %34)
  store i32 %35, ptr %9, align 4, !tbaa !15
  %36 = load i32, ptr %9, align 4, !tbaa !15
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.s_file, ptr %37, i32 0, i32 3
  %39 = load ptr, ptr %38, align 8, !tbaa !18
  %40 = getelementptr inbounds %struct.s_info, ptr %2, i32 0, i32 1
  %41 = getelementptr inbounds %struct.s_dib, ptr %40, i32 0, i32 1
  %42 = getelementptr inbounds %struct.s_vec, ptr %41, i32 0, i32 1
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = load i32, ptr %6, align 4, !tbaa !15
  %45 = sub nsw i32 %43, %44
  %46 = sub nsw i32 %45, 1
  %47 = getelementptr inbounds %struct.s_info, ptr %2, i32 0, i32 1
  %48 = getelementptr inbounds %struct.s_dib, ptr %47, i32 0, i32 1
  %49 = getelementptr inbounds %struct.s_vec, ptr %48, i32 0, i32 0
  %50 = load i32, ptr %49, align 8, !tbaa !20
  %51 = mul nsw i32 %46, %50
  %52 = load i32, ptr %7, align 4, !tbaa !15
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %7, align 4, !tbaa !15
  %54 = add nsw i32 %51, %52
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i32, ptr %39, i64 %55
  store i32 %36, ptr %56, align 4, !tbaa !15
  %57 = getelementptr inbounds %struct.s_info, ptr %2, i32 0, i32 2
  %58 = load i8, ptr %57, align 8, !tbaa !21
  %59 = zext i8 %58 to i32
  %60 = load i32, ptr %8, align 4, !tbaa !15
  %61 = add i32 %60, %59
  store i32 %61, ptr %8, align 4, !tbaa !15
  br label %19, !llvm.loop !22

62:                                               ; preds = %19
  br label %14, !llvm.loop !24

63:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  ret void
}

; 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 hidden i32 @build_pixel(ptr noundef) #0

; 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 = { 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, !12, i64 20}
!10 = !{!"s_info", !11, i64 0, !13, i64 8, !7, i64 40, !7, i64 41, !7, i64 42, !12, i64 44, !12, i64 48, !12, i64 52}
!11 = !{!"s_hdr", !12, i64 0, !12, i64 4}
!12 = !{!"int", !7, i64 0}
!13 = !{!"s_dib", !14, i64 0, !14, i64 8, !7, i64 16, !7, i64 17, !7, i64 18, !7, i64 19, !12, i64 20, !12, i64 24, !12, i64 28}
!14 = !{!"s_vec", !12, i64 0, !12, i64 4}
!15 = !{!12, !12, i64 0}
!16 = !{!10, !12, i64 44}
!17 = !{!10, !12, i64 52}
!18 = !{!19, !6, i64 184}
!19 = !{!"s_file", !7, i64 0, !10, i64 120, !6, i64 176, !6, i64 184}
!20 = !{!10, !12, i64 16}
!21 = !{!10, !7, i64 40}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = distinct !{!24, !23}


; 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.s_info = type { %struct.s_hdr, %struct.s_dib, i8, i8, i8, i32, i32, i32 }
%struct.s_hdr = type { i32, i32 }
%struct.s_dib = type { %struct.s_vec, %struct.s_vec, i8, i8, i8, i8, i32, i32, i32 }
%struct.s_vec = type { i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local void @build_image(ptr nocapture noundef readonly %0, ptr noundef %1, ptr nocapture noundef readonly byval(%struct.s_info) align 8 %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %2, i64 20
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.preheader.lr.ph, label %._crit_edge

.preheader.lr.ph:                                 ; preds = %3
  %7 = getelementptr inbounds i8, ptr %2, i64 44
  %8 = load i32, ptr %7, align 4, !tbaa !13
  %.not = icmp eq i32 %8, 0
  %9 = getelementptr inbounds i8, ptr %2, i64 52
  %10 = load i32, ptr %9, align 4
  %11 = getelementptr inbounds i8, ptr %0, i64 184
  %12 = getelementptr inbounds i8, ptr %2, i64 40
  %13 = load i8, ptr %12, align 8
  %14 = zext i8 %13 to i32
  br i1 %.not, label %._crit_edge, label %.preheader.us.preheader

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %15 = getelementptr inbounds i8, ptr %2, i64 16
  %16 = load i32, ptr %15, align 8
  %17 = zext nneg i32 %5 to i64
  %18 = sext i32 %16 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %..loopexit_crit_edge.us
  %indvars.iv19 = phi i64 [ %17, %.preheader.us.preheader ], [ %indvars.iv.next20, %..loopexit_crit_edge.us ]
  %indvars.iv17.in = phi i64 [ %17, %.preheader.us.preheader ], [ %indvars.iv17, %..loopexit_crit_edge.us ]
  %indvars.iv17 = add nsw i64 %indvars.iv17.in, -1
  %19 = trunc nuw nsw i64 %indvars.iv17 to i32
  %20 = mul i32 %10, %19
  %21 = zext i32 %20 to i64
  %invariant.gep.us = getelementptr inbounds i8, ptr %1, i64 %21
  %22 = sub nuw nsw i64 %17, %indvars.iv19
  %23 = mul nsw i64 %22, %18
  br label %24

24:                                               ; preds = %.preheader.us, %24
  %indvars.iv = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next, %24 ]
  %.0913.us = phi i32 [ 0, %.preheader.us ], [ %30, %24 ]
  %25 = zext i32 %.0913.us to i64
  %gep.us = getelementptr inbounds i8, ptr %invariant.gep.us, i64 %25
  %26 = tail call i32 @build_pixel(ptr noundef %gep.us)
  %27 = load ptr, ptr %11, align 8, !tbaa !14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %28 = getelementptr i32, ptr %27, i64 %23
  %29 = getelementptr i32, ptr %28, i64 %indvars.iv
  store i32 %26, ptr %29, align 4, !tbaa !17
  %30 = add i32 %.0913.us, %14
  %31 = icmp ult i32 %30, %8
  br i1 %31, label %24, label %..loopexit_crit_edge.us, !llvm.loop !18

..loopexit_crit_edge.us:                          ; preds = %24
  %32 = icmp sgt i64 %indvars.iv17.in, 1
  %indvars.iv.next20 = add nsw i64 %indvars.iv19, -1
  br i1 %32, label %.preheader.us, label %._crit_edge, !llvm.loop !20

._crit_edge:                                      ; preds = %..loopexit_crit_edge.us, %.preheader.lr.ph, %3
  ret void
}

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

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

!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, !8, i64 20}
!6 = !{!"s_info", !7, i64 0, !11, i64 8, !9, i64 40, !9, i64 41, !9, i64 42, !8, i64 44, !8, i64 48, !8, i64 52}
!7 = !{!"s_hdr", !8, i64 0, !8, i64 4}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"s_dib", !12, i64 0, !12, i64 8, !9, i64 16, !9, i64 17, !9, i64 18, !9, i64 19, !8, i64 20, !8, i64 24, !8, i64 28}
!12 = !{!"s_vec", !8, i64 0, !8, i64 4}
!13 = !{!6, !8, i64 44}
!14 = !{!15, !16, i64 184}
!15 = !{!"s_file", !9, i64 0, !6, i64 120, !16, i64 176, !16, i64 184}
!16 = !{!"any pointer", !9, i64 0}
!17 = !{!8, !8, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass