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

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

%"class.jpgd::jpeg_decoder" = type <{ [1 x %struct.__jmp_buf_tag], i32, [4 x i8], ptr, i32, i32, ptr, i32, [8 x i8], [4 x i8], [8 x ptr], [8 x ptr], [4 x ptr], i32, i32, [4 x i32], [4 x i32], [4 x i32], [4 x i32], [4 x i32], [4 x i32], i32, [4 x i32], [4 x i32], [4 x i32], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [10 x i32], i32, i32, i32, i32, i32, i32, [4 x i8], [8 x ptr], [4 x ptr], [4 x ptr], i32, [4 x i32], [4 x i8], ptr, i32, i32, [64 x i8], [8320 x i8], [64 x i8], i32, i32, i32, i32, i32, i32, i32, i32, [4 x i32], ptr, [10 x i32], ptr, ptr, [256 x i32], [256 x i32], [256 x i32], [256 x i32], ptr, ptr, i32, i32, i8, i8, i8, [5 x i8] }>
%struct.__jmp_buf_tag = type { [8 x i64], i32, %struct.__sigset_t }
%struct.__sigset_t = type { [16 x i64] }

; 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 nounwind uwtable
define dso_local void @_ZN4jpgd12jpeg_decoder15create_look_upsEv(ptr noundef nonnull align 8 dereferenceable(13523) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %42, %1
  %7 = load i32, ptr %3, align 4, !tbaa !9
  %8 = icmp sle i32 %7, 255
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %45

10:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %11 = load i32, ptr %3, align 4, !tbaa !9
  %12 = sub nsw i32 %11, 128
  store i32 %12, ptr %4, align 4, !tbaa !9
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = mul nsw i32 91881, %13
  %15 = add nsw i32 %14, 32768
  %16 = ashr i32 %15, 16
  %17 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 68
  %18 = load i32, ptr %3, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [256 x i32], ptr %17, i64 0, i64 %19
  store i32 %16, ptr %20, align 4, !tbaa !9
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = mul nsw i32 116130, %21
  %23 = add nsw i32 %22, 32768
  %24 = ashr i32 %23, 16
  %25 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 69
  %26 = load i32, ptr %3, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [256 x i32], ptr %25, i64 0, i64 %27
  store i32 %24, ptr %28, align 4, !tbaa !9
  %29 = load i32, ptr %4, align 4, !tbaa !9
  %30 = mul nsw i32 -46802, %29
  %31 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 70
  %32 = load i32, ptr %3, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [256 x i32], ptr %31, i64 0, i64 %33
  store i32 %30, ptr %34, align 4, !tbaa !9
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = mul nsw i32 -22554, %35
  %37 = add nsw i32 %36, 32768
  %38 = getelementptr inbounds %"class.jpgd::jpeg_decoder", ptr %5, i32 0, i32 71
  %39 = load i32, ptr %3, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [256 x i32], ptr %38, i64 0, i64 %40
  store i32 %37, ptr %41, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %42

42:                                               ; preds = %10
  %43 = load i32, ptr %3, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %3, align 4, !tbaa !9
  br label %6, !llvm.loop !11

45:                                               ; preds = %9
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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 = distinct !{!11, !12}
!12 = !{!"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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(argmem: write) uwtable
define dso_local void @_ZN4jpgd12jpeg_decoder15create_look_upsEv(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(13523) %0) local_unnamed_addr #0 align 2 {
vector.ph:
  %1 = getelementptr inbounds i8, ptr %0, i64 9400
  %2 = getelementptr inbounds i8, ptr %0, i64 10424
  %3 = getelementptr inbounds i8, ptr %0, i64 11448
  %4 = getelementptr inbounds i8, ptr %0, i64 12472
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <4 x i64> [ <i64 0, i64 1, i64 2, i64 3>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %5 = add nsw <4 x i64> %vec.ind, <i64 -128, i64 -128, i64 -128, i64 -128>
  %6 = trunc <4 x i64> %5 to <4 x i32>
  %7 = mul <4 x i32> %6, <i32 91881, i32 91881, i32 91881, i32 91881>
  %8 = add <4 x i32> %7, <i32 32768, i32 32768, i32 32768, i32 32768>
  %9 = ashr <4 x i32> %8, <i32 16, i32 16, i32 16, i32 16>
  %10 = getelementptr inbounds [256 x i32], ptr %1, i64 0, i64 %index
  store <4 x i32> %9, ptr %10, align 8, !tbaa !5
  %11 = trunc <4 x i64> %5 to <4 x i32>
  %12 = mul <4 x i32> %11, <i32 116130, i32 116130, i32 116130, i32 116130>
  %13 = add <4 x i32> %12, <i32 32768, i32 32768, i32 32768, i32 32768>
  %14 = ashr <4 x i32> %13, <i32 16, i32 16, i32 16, i32 16>
  %15 = getelementptr inbounds [256 x i32], ptr %2, i64 0, i64 %index
  store <4 x i32> %14, ptr %15, align 8, !tbaa !5
  %16 = getelementptr inbounds [256 x i32], ptr %3, i64 0, i64 %index
  %17 = trunc <4 x i64> %5 to <4 x i32>
  %18 = mul <4 x i32> %17, <i32 -46802, i32 -46802, i32 -46802, i32 -46802>
  store <4 x i32> %18, ptr %16, align 8, !tbaa !5
  %19 = getelementptr inbounds [256 x i32], ptr %4, i64 0, i64 %index
  %20 = trunc <4 x i64> %5 to <4 x i32>
  %21 = mul <4 x i32> %20, <i32 -22554, i32 -22554, i32 -22554, i32 -22554>
  %22 = add <4 x i32> %21, <i32 32768, i32 32768, i32 32768, i32 32768>
  store <4 x i32> %22, ptr %19, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %vec.ind.next = add <4 x i64> %vec.ind, <i64 4, i64 4, i64 4, i64 4>
  %23 = icmp eq i64 %index.next, 256
  br i1 %23, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: write) 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass