; LLVM IR from facebookresearch/habitat-sim :: src/deps/basis-universal/encoder/jpgd.ll (ZN4jpgd12jpeg_decoder14coeff_buf_openEiiii)

; 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.jpgd::jpeg_decoder::coeff_buf" = type { ptr, i32, i32, i32, i32, i32 }

; 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: mustprogress uwtable
declare dso_local noundef ptr @_ZN4jpgd12jpeg_decoder5allocEmb(ptr noundef nonnull align 8 dereferenceable(13523), i64 noundef, i1 noundef zeroext) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN4jpgd12jpeg_decoder14coeff_buf_openEiiii(ptr noundef nonnull align 8 dereferenceable(13523) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #1 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  %12 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %13 = call noundef ptr @_ZN4jpgd12jpeg_decoder5allocEmb(ptr noundef nonnull align 8 dereferenceable(13523) %12, i64 noundef 32, i1 noundef zeroext false)
  store ptr %13, ptr %11, align 8, !tbaa !5
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = load ptr, ptr %11, align 8, !tbaa !5
  %16 = getelementptr inbounds %"struct.jpgd::jpeg_decoder::coeff_buf", ptr %15, i32 0, i32 1
  store i32 %14, ptr %16, align 8, !tbaa !11
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = load ptr, ptr %11, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.jpgd::jpeg_decoder::coeff_buf", ptr %18, i32 0, i32 2
  store i32 %17, ptr %19, align 4, !tbaa !13
  %20 = load i32, ptr %9, align 4, !tbaa !9
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  %22 = getelementptr inbounds %"struct.jpgd::jpeg_decoder::coeff_buf", ptr %21, i32 0, i32 3
  store i32 %20, ptr %22, align 8, !tbaa !14
  %23 = load i32, ptr %10, align 4, !tbaa !9
  %24 = load ptr, ptr %11, align 8, !tbaa !5
  %25 = getelementptr inbounds %"struct.jpgd::jpeg_decoder::coeff_buf", ptr %24, i32 0, i32 4
  store i32 %23, ptr %25, align 4, !tbaa !15
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = load i32, ptr %10, align 4, !tbaa !9
  %28 = mul nsw i32 %26, %27
  %29 = sext i32 %28 to i64
  %30 = mul i64 %29, 2
  %31 = trunc i64 %30 to i32
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = getelementptr inbounds %"struct.jpgd::jpeg_decoder::coeff_buf", ptr %32, i32 0, i32 5
  store i32 %31, ptr %33, align 8, !tbaa !16
  %34 = load ptr, ptr %11, align 8, !tbaa !5
  %35 = getelementptr inbounds %"struct.jpgd::jpeg_decoder::coeff_buf", ptr %34, i32 0, i32 5
  %36 = load i32, ptr %35, align 8, !tbaa !16
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = mul nsw i32 %36, %37
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = mul nsw i32 %38, %39
  %41 = sext i32 %40 to i64
  %42 = call noundef ptr @_ZN4jpgd12jpeg_decoder5allocEmb(ptr noundef nonnull align 8 dereferenceable(13523) %12, i64 noundef %41, i1 noundef zeroext true)
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  %44 = getelementptr inbounds %"struct.jpgd::jpeg_decoder::coeff_buf", ptr %43, i32 0, i32 0
  store ptr %42, ptr %44, align 8, !tbaa !17
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  ret ptr %45
}

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTSN4jpgd12jpeg_decoder9coeff_bufE", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24}
!13 = !{!12, !10, i64 12}
!14 = !{!12, !10, i64 16}
!15 = !{!12, !10, i64 20}
!16 = !{!12, !10, i64 24}
!17 = !{!12, !6, 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"

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN4jpgd12jpeg_decoder5allocEmb(ptr noundef nonnull align 8 dereferenceable(13523), i64 noundef, i1 noundef zeroext) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN4jpgd12jpeg_decoder14coeff_buf_openEiiii(ptr noundef nonnull align 8 dereferenceable(13523) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 align 2 {
  %6 = tail call noundef ptr @_ZN4jpgd12jpeg_decoder5allocEmb(ptr noundef nonnull align 8 dereferenceable(13523) %0, i64 noundef 32, i1 noundef zeroext false)
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  store i32 %1, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %6, i64 12
  store i32 %2, ptr %8, align 4, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %6, i64 16
  store i32 %3, ptr %9, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %6, i64 20
  store i32 %4, ptr %10, align 4, !tbaa !13
  %11 = shl i32 %3, 1
  %12 = mul i32 %11, %4
  %13 = getelementptr inbounds i8, ptr %6, i64 24
  store i32 %12, ptr %13, align 8, !tbaa !14
  %14 = mul i32 %2, %1
  %15 = mul i32 %14, %12
  %16 = sext i32 %15 to i64
  %17 = tail call noundef ptr @_ZN4jpgd12jpeg_decoder5allocEmb(ptr noundef nonnull align 8 dereferenceable(13523) %0, i64 noundef %16, i1 noundef zeroext true)
  store ptr %17, ptr %6, align 8, !tbaa !15
  ret ptr %6
}

attributes #0 = { 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" }

!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, !10, i64 8}
!6 = !{!"_ZTSN4jpgd12jpeg_decoder9coeff_bufE", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 12}
!12 = !{!6, !10, i64 16}
!13 = !{!6, !10, i64 20}
!14 = !{!6, !10, i64 24}
!15 = !{!6, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,TailCallElimPass