; LLVM IR from venumb/ZSPACE :: cpp/depends/lodePNG/lodepng.ll (Z19lodepng_palette_addP16LodePNGColorModehhhh)

; 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: mustprogress uwtable
declare dso_local void @_Z32lodepng_color_mode_alloc_paletteP16LodePNGColorMode(ptr noundef) #0

; 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) #0 {
  %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
  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
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.LodePNGColorMode, ptr %12, i32 0, i32 2
  %14 = load ptr, ptr %13, align 8, !tbaa !10
  %15 = icmp ne ptr %14, null
  br i1 %15, label %24, label %16

16:                                               ; preds = %5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_Z32lodepng_color_mode_alloc_paletteP16LodePNGColorMode(ptr noundef %17)
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.LodePNGColorMode, ptr %18, i32 0, i32 2
  %20 = load ptr, ptr %19, align 8, !tbaa !10
  %21 = icmp ne ptr %20, null
  br i1 %21, label %23, label %22

22:                                               ; preds = %16
  store i32 83, ptr %6, align 4
  br label %69

23:                                               ; preds = %16
  br label %24

24:                                               ; preds = %23, %5
  %25 = load i8, ptr %8, align 1, !tbaa !9
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.LodePNGColorMode, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !10
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.LodePNGColorMode, ptr %29, i32 0, i32 3
  %31 = load i64, ptr %30, align 8, !tbaa !15
  %32 = mul i64 4, %31
  %33 = add i64 %32, 0
  %34 = getelementptr inbounds i8, ptr %28, i64 %33
  store i8 %25, ptr %34, align 1, !tbaa !9
  %35 = load i8, ptr %9, align 1, !tbaa !9
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.LodePNGColorMode, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !10
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.LodePNGColorMode, ptr %39, i32 0, i32 3
  %41 = load i64, ptr %40, align 8, !tbaa !15
  %42 = mul i64 4, %41
  %43 = add i64 %42, 1
  %44 = getelementptr inbounds i8, ptr %38, i64 %43
  store i8 %35, ptr %44, align 1, !tbaa !9
  %45 = load i8, ptr %10, align 1, !tbaa !9
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.LodePNGColorMode, ptr %46, i32 0, i32 2
  %48 = load ptr, ptr %47, align 8, !tbaa !10
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.LodePNGColorMode, ptr %49, i32 0, i32 3
  %51 = load i64, ptr %50, align 8, !tbaa !15
  %52 = mul i64 4, %51
  %53 = add i64 %52, 2
  %54 = getelementptr inbounds i8, ptr %48, i64 %53
  store i8 %45, ptr %54, align 1, !tbaa !9
  %55 = load i8, ptr %11, 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 !10
  %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 !15
  %62 = mul i64 4, %61
  %63 = add i64 %62, 3
  %64 = getelementptr inbounds i8, ptr %58, i64 %63
  store i8 %55, ptr %64, align 1, !tbaa !9
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.LodePNGColorMode, ptr %65, i32 0, i32 3
  %67 = load i64, ptr %66, align 8, !tbaa !15
  %68 = add i64 %67, 1
  store i64 %68, ptr %66, align 8, !tbaa !15
  store i32 0, ptr %6, align 4
  br label %69

69:                                               ; preds = %24, %22
  %70 = load i32, ptr %6, align 4
  ret i32 %70
}

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, !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 uwtable
declare dso_local void @_Z32lodepng_color_mode_alloc_paletteP16LodePNGColorMode(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 84) i32 @_Z19lodepng_palette_addP16LodePNGColorModehhhh(ptr 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 %10

8:                                                ; preds = %5
  tail call void @_Z32lodepng_color_mode_alloc_paletteP16LodePNGColorMode(ptr noundef nonnull %0)
  %9 = load ptr, ptr %6, align 8, !tbaa !5
  %.not16 = icmp eq ptr %9, null
  br i1 %.not16, label %33, label %10

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

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

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, !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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass