; LLVM IR from facebookresearch/habitat-sim :: src/deps/basis-universal/encoder (lodepng)

; 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.LodePNGColorMode = type { i32, i32, ptr, i64, 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 nounwind uwtable
declare hidden noundef ptr @_ZL15lodepng_reallocPvm(ptr noundef, i64 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z19lodepng_palette_addP16LodePNGColorModehhhh(ptr noundef %0, i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext %3, i8 noundef zeroext %4) #2 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca i8, align 1
  %10 = alloca i8, align 1
  %11 = alloca i8, align 1
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i8 %1, ptr %8, align 1, !tbaa !9
  store i8 %2, ptr %9, align 1, !tbaa !9
  store i8 %3, ptr %10, align 1, !tbaa !9
  store i8 %4, ptr %11, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.LodePNGColorMode, ptr %14, i32 0, i32 2
  %16 = load ptr, ptr %15, align 8, !tbaa !10
  %17 = icmp ne ptr %16, null
  br i1 %17, label %31, label %18

18:                                               ; preds = %5
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.LodePNGColorMode, ptr %19, i32 0, i32 2
  %21 = load ptr, ptr %20, align 8, !tbaa !10
  %22 = call noundef ptr @_ZL15lodepng_reallocPvm(ptr noundef %21, i64 noundef 1024)
  store ptr %22, ptr %12, align 8, !tbaa !5
  %23 = load ptr, ptr %12, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %26, label %25

25:                                               ; preds = %18
  store i32 83, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %76

26:                                               ; preds = %18
  %27 = load ptr, ptr %12, align 8, !tbaa !5
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.LodePNGColorMode, ptr %28, i32 0, i32 2
  store ptr %27, ptr %29, align 8, !tbaa !10
  br label %30

30:                                               ; preds = %26
  br label %31

31:                                               ; preds = %30, %5
  %32 = load i8, ptr %8, align 1, !tbaa !9
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.LodePNGColorMode, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !10
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.LodePNGColorMode, ptr %36, i32 0, i32 3
  %38 = load i64, ptr %37, align 8, !tbaa !15
  %39 = mul i64 4, %38
  %40 = add i64 %39, 0
  %41 = getelementptr inbounds i8, ptr %35, i64 %40
  store i8 %32, ptr %41, align 1, !tbaa !9
  %42 = load i8, ptr %9, align 1, !tbaa !9
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.LodePNGColorMode, ptr %43, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !10
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.LodePNGColorMode, ptr %46, i32 0, i32 3
  %48 = load i64, ptr %47, align 8, !tbaa !15
  %49 = mul i64 4, %48
  %50 = add i64 %49, 1
  %51 = getelementptr inbounds i8, ptr %45, i64 %50
  store i8 %42, ptr %51, align 1, !tbaa !9
  %52 = load i8, ptr %10, align 1, !tbaa !9
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.LodePNGColorMode, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !10
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.LodePNGColorMode, ptr %56, i32 0, i32 3
  %58 = load i64, ptr %57, align 8, !tbaa !15
  %59 = mul i64 4, %58
  %60 = add i64 %59, 2
  %61 = getelementptr inbounds i8, ptr %55, i64 %60
  store i8 %52, ptr %61, align 1, !tbaa !9
  %62 = load i8, ptr %11, align 1, !tbaa !9
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.LodePNGColorMode, ptr %63, i32 0, i32 2
  %65 = load ptr, ptr %64, align 8, !tbaa !10
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.LodePNGColorMode, ptr %66, i32 0, i32 3
  %68 = load i64, ptr %67, align 8, !tbaa !15
  %69 = mul i64 4, %68
  %70 = add i64 %69, 3
  %71 = getelementptr inbounds i8, ptr %65, i64 %70
  store i8 %62, ptr %71, align 1, !tbaa !9
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.LodePNGColorMode, ptr %72, i32 0, i32 3
  %74 = load i64, ptr %73, align 8, !tbaa !15
  %75 = add i64 %74, 1
  store i64 %75, ptr %73, align 8, !tbaa !15
  store i32 0, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %76

76:                                               ; preds = %31, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %77 = load i32, ptr %6, align 4
  ret i32 %77
}

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 = { 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 #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++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 8}
!11 = !{!"_ZTS16LodePNGColorMode", !12, i64 0, !13, i64 4, !6, i64 8, !14, i64 16, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36}
!12 = !{!"_ZTS16LodePNGColorType", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!11, !14, i64 16}


; 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 nounwind uwtable
declare hidden noundef ptr @_ZL15lodepng_reallocPvm(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i32 0, 84) i32 @_Z19lodepng_palette_addP16LodePNGColorModehhhh(ptr nocapture noundef %0, i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext %3, i8 noundef zeroext %4) local_unnamed_addr #0 {
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %8, label %11

8:                                                ; preds = %5
  %9 = tail call noundef ptr @_ZL15lodepng_reallocPvm(ptr noundef null, i64 noundef 1024)
  %.not20 = icmp eq ptr %9, null
  br i1 %.not20, label %34, label %10

10:                                               ; preds = %8
  store ptr %9, ptr %6, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %10, %5
  %12 = phi ptr [ %9, %10 ], [ %7, %5 ]
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  %14 = load i64, ptr %13, align 8, !tbaa !13
  %15 = shl i64 %14, 2
  %16 = getelementptr inbounds i8, ptr %12, i64 %15
  store i8 %1, ptr %16, align 1, !tbaa !14
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load i64, ptr %13, align 8, !tbaa !13
  %19 = shl i64 %18, 2
  %20 = or disjoint i64 %19, 1
  %21 = getelementptr inbounds i8, ptr %17, i64 %20
  store i8 %2, ptr %21, align 1, !tbaa !14
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load i64, ptr %13, align 8, !tbaa !13
  %24 = shl i64 %23, 2
  %25 = or disjoint i64 %24, 2
  %26 = getelementptr inbounds i8, ptr %22, i64 %25
  store i8 %3, ptr %26, align 1, !tbaa !14
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = load i64, ptr %13, align 8, !tbaa !13
  %29 = shl i64 %28, 2
  %30 = or disjoint i64 %29, 3
  %31 = getelementptr inbounds i8, ptr %27, i64 %30
  store i8 %4, ptr %31, align 1, !tbaa !14
  %32 = load i64, ptr %13, align 8, !tbaa !13
  %33 = add i64 %32, 1
  store i64 %33, ptr %13, align 8, !tbaa !13
  br label %34

34:                                               ; preds = %8, %11
  %.0 = phi i32 [ 0, %11 ], [ 83, %8 ]
  ret i32 %.0
}

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

!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, !11, i64 8}
!6 = !{!"_ZTS16LodePNGColorMode", !7, i64 0, !10, i64 4, !11, i64 8, !12, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36}
!7 = !{!"_ZTS16LodePNGColorType", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"long", !8, i64 0}
!13 = !{!6, !12, i64 16}
!14 = !{!8, !8, i64 0}


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