; LLVM IR from CubbyFlow/RenderFlow :: Extensions/FlowEditor/sample_utils (file_png)

; 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 @_ZL9myreallocPvm(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 i64, align 8
  %14 = 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
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.LodePNGColorMode, ptr %15, i32 0, i32 3
  %17 = load i64, ptr %16, align 8, !tbaa !10
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.LodePNGColorMode, ptr %18, i32 0, i32 3
  %20 = load i64, ptr %19, align 8, !tbaa !10
  %21 = sub i64 %20, 1
  %22 = and i64 %17, %21
  %23 = icmp ne i64 %22, 0
  br i1 %23, label %54, label %24

24:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.LodePNGColorMode, ptr %25, i32 0, i32 3
  %27 = load i64, ptr %26, align 8, !tbaa !10
  %28 = icmp eq i64 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %24
  br label %36

30:                                               ; preds = %24
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.LodePNGColorMode, ptr %31, i32 0, i32 3
  %33 = load i64, ptr %32, align 8, !tbaa !10
  %34 = mul i64 %33, 4
  %35 = mul i64 %34, 2
  br label %36

36:                                               ; preds = %30, %29
  %37 = phi i64 [ 4, %29 ], [ %35, %30 ]
  store i64 %37, ptr %13, align 8, !tbaa !15
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.LodePNGColorMode, ptr %38, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !16
  %41 = load i64, ptr %13, align 8, !tbaa !15
  %42 = call noundef ptr @_ZL9myreallocPvm(ptr noundef %40, i64 noundef %41)
  store ptr %42, ptr %12, align 8, !tbaa !5
  %43 = load ptr, ptr %12, align 8, !tbaa !5
  %44 = icmp ne ptr %43, null
  br i1 %44, label %46, label %45

45:                                               ; preds = %36
  store i32 83, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %51

46:                                               ; preds = %36
  %47 = load ptr, ptr %12, align 8, !tbaa !5
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.LodePNGColorMode, ptr %48, i32 0, i32 2
  store ptr %47, ptr %49, align 8, !tbaa !16
  br label %50

50:                                               ; preds = %46
  store i32 0, ptr %14, align 4
  br label %51

51:                                               ; preds = %50, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  %52 = load i32, ptr %14, align 4
  switch i32 %52, label %99 [
    i32 0, label %53
  ]

53:                                               ; preds = %51
  br label %54

54:                                               ; preds = %53, %5
  %55 = load i8, ptr %8, align 1, !tbaa !9
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.LodePNGColorMode, ptr %56, i32 0, i32 2
  %58 = load ptr, ptr %57, align 8, !tbaa !16
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.LodePNGColorMode, ptr %59, i32 0, i32 3
  %61 = load i64, ptr %60, align 8, !tbaa !10
  %62 = mul i64 4, %61
  %63 = add i64 %62, 0
  %64 = getelementptr inbounds i8, ptr %58, i64 %63
  store i8 %55, ptr %64, align 1, !tbaa !9
  %65 = load i8, ptr %9, align 1, !tbaa !9
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.LodePNGColorMode, ptr %66, i32 0, i32 2
  %68 = load ptr, ptr %67, align 8, !tbaa !16
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.LodePNGColorMode, ptr %69, i32 0, i32 3
  %71 = load i64, ptr %70, align 8, !tbaa !10
  %72 = mul i64 4, %71
  %73 = add i64 %72, 1
  %74 = getelementptr inbounds i8, ptr %68, i64 %73
  store i8 %65, ptr %74, align 1, !tbaa !9
  %75 = load i8, ptr %10, align 1, !tbaa !9
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.LodePNGColorMode, ptr %76, i32 0, i32 2
  %78 = load ptr, ptr %77, align 8, !tbaa !16
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.LodePNGColorMode, ptr %79, i32 0, i32 3
  %81 = load i64, ptr %80, align 8, !tbaa !10
  %82 = mul i64 4, %81
  %83 = add i64 %82, 2
  %84 = getelementptr inbounds i8, ptr %78, i64 %83
  store i8 %75, ptr %84, align 1, !tbaa !9
  %85 = load i8, ptr %11, align 1, !tbaa !9
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.LodePNGColorMode, ptr %86, i32 0, i32 2
  %88 = load ptr, ptr %87, align 8, !tbaa !16
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.LodePNGColorMode, ptr %89, i32 0, i32 3
  %91 = load i64, ptr %90, align 8, !tbaa !10
  %92 = mul i64 4, %91
  %93 = add i64 %92, 3
  %94 = getelementptr inbounds i8, ptr %88, i64 %93
  store i8 %85, ptr %94, align 1, !tbaa !9
  %95 = load ptr, ptr %7, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.LodePNGColorMode, ptr %95, i32 0, i32 3
  %97 = load i64, ptr %96, align 8, !tbaa !10
  %98 = add i64 %97, 1
  store i64 %98, ptr %96, align 8, !tbaa !10
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %99

99:                                               ; preds = %54, %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %100 = load i32, ptr %6, align 4
  ret i32 %100
}

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, !14, i64 16}
!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 = !{!14, !14, i64 0}
!16 = !{!11, !6, i64 8}


; 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 @_ZL9myreallocPvm(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 16
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = tail call range(i64 0, 65) i64 @llvm.ctpop.i64(i64 %7)
  %.not = icmp ult i64 %8, 2
  br i1 %.not, label %9, label %._crit_edge

._crit_edge:                                      ; preds = %5
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 8
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !13
  br label %16

9:                                                ; preds = %5
  %10 = icmp eq i64 %7, 0
  %11 = shl i64 %7, 3
  %spec.select = select i1 %10, i64 4, i64 %11
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = tail call noundef ptr @_ZL9myreallocPvm(ptr noundef %13, i64 noundef %spec.select)
  %.not26.not = icmp eq ptr %14, null
  br i1 %.not26.not, label %.critedge, label %15

15:                                               ; preds = %9
  store ptr %14, ptr %12, align 8, !tbaa !13
  %.pre27 = load i64, ptr %6, align 8, !tbaa !5
  br label %16

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

.critedge:                                        ; preds = %9, %16
  %.1 = phi i32 [ 0, %16 ], [ 83, %9 ]
  ret i32 %.1
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.ctpop.i64(i64) #1

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" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !12, i64 16}
!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, !11, i64 8}
!14 = !{!8, !8, i64 0}


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