; LLVM IR from aap/librw :: src/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
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 @_ZL32lodepng_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 %75

23:                                               ; preds = %16
  br label %24

24:                                               ; preds = %23, %5
  %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 !15
  %28 = icmp uge i64 %27, 256
  br i1 %28, label %29, label %30

29:                                               ; preds = %24
  store i32 108, ptr %6, align 4
  br label %75

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

75:                                               ; preds = %30, %29, %22
  %76 = load i32, ptr %6, align 4
  ret i32 %76
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL32lodepng_color_mode_alloc_paletteP16LodePNGColorMode(ptr noundef) #1

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

!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
define dso_local noundef range(i32 0, 109) 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 @_ZL32lodepng_color_mode_alloc_paletteP16LodePNGColorMode(ptr noundef nonnull %0)
  %9 = load ptr, ptr %6, align 8, !tbaa !5
  %.not18 = icmp eq ptr %9, null
  br i1 %.not18, label %35, 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 = icmp ugt i64 %13, 255
  br i1 %14, label %35, label %15

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

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL32lodepng_color_mode_alloc_paletteP16LodePNGColorMode(ptr noundef) local_unnamed_addr #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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass