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

; 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.LodePNGInfo = type { i32, i32, i32, %struct.LodePNGColorMode, i32, i32, i32, i32, i64, ptr, ptr, i64, ptr, ptr, ptr, ptr, i32, %struct.LodePNGTime, i32, i32, i32, i32, [3 x ptr], [3 x i64] }
%struct.LodePNGColorMode = type { i32, i32, ptr, i64, i32, i32, i32, i32 }
%struct.LodePNGTime = type { i32, i32, 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 void @_ZL6myfreePv(ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZL9myreallocPvm(ptr noundef, i64 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z16lodepng_add_textP11LodePNGInfoPKcS2_(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.LodePNGInfo, ptr %11, i32 0, i32 9
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.LodePNGInfo, ptr %14, i32 0, i32 8
  %16 = load i64, ptr %15, align 8, !tbaa !16
  %17 = add i64 %16, 1
  %18 = mul i64 8, %17
  %19 = call noundef ptr @_ZL9myreallocPvm(ptr noundef %13, i64 noundef %18)
  store ptr %19, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.LodePNGInfo, ptr %20, i32 0, i32 10
  %22 = load ptr, ptr %21, align 8, !tbaa !17
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.LodePNGInfo, ptr %23, i32 0, i32 8
  %25 = load i64, ptr %24, align 8, !tbaa !16
  %26 = add i64 %25, 1
  %27 = mul i64 8, %26
  %28 = call noundef ptr @_ZL9myreallocPvm(ptr noundef %22, i64 noundef %27)
  store ptr %28, ptr %9, align 8, !tbaa !5
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %34

31:                                               ; preds = %3
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %37, label %34

34:                                               ; preds = %31, %3
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZL6myfreePv(ptr noundef %35)
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  call void @_ZL6myfreePv(ptr noundef %36)
  store i32 83, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %82

37:                                               ; preds = %31
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.LodePNGInfo, ptr %38, i32 0, i32 8
  %40 = load i64, ptr %39, align 8, !tbaa !16
  %41 = add i64 %40, 1
  store i64 %41, ptr %39, align 8, !tbaa !16
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.LodePNGInfo, ptr %43, i32 0, i32 9
  store ptr %42, ptr %44, align 8, !tbaa !9
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.LodePNGInfo, ptr %46, i32 0, i32 10
  store ptr %45, ptr %47, align 8, !tbaa !17
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.LodePNGInfo, ptr %48, i32 0, i32 9
  %50 = load ptr, ptr %49, align 8, !tbaa !9
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.LodePNGInfo, ptr %51, i32 0, i32 8
  %53 = load i64, ptr %52, align 8, !tbaa !16
  %54 = sub i64 %53, 1
  %55 = getelementptr inbounds ptr, ptr %50, i64 %54
  call void @_ZL11string_initPPc(ptr noundef %55)
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.LodePNGInfo, ptr %56, i32 0, i32 9
  %58 = load ptr, ptr %57, align 8, !tbaa !9
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.LodePNGInfo, ptr %59, i32 0, i32 8
  %61 = load i64, ptr %60, align 8, !tbaa !16
  %62 = sub i64 %61, 1
  %63 = getelementptr inbounds ptr, ptr %58, i64 %62
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZL10string_setPPcPKc(ptr noundef %63, ptr noundef %64)
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.LodePNGInfo, ptr %65, i32 0, i32 10
  %67 = load ptr, ptr %66, align 8, !tbaa !17
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.LodePNGInfo, ptr %68, i32 0, i32 8
  %70 = load i64, ptr %69, align 8, !tbaa !16
  %71 = sub i64 %70, 1
  %72 = getelementptr inbounds ptr, ptr %67, i64 %71
  call void @_ZL11string_initPPc(ptr noundef %72)
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.LodePNGInfo, ptr %73, i32 0, i32 10
  %75 = load ptr, ptr %74, align 8, !tbaa !17
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.LodePNGInfo, ptr %76, i32 0, i32 8
  %78 = load i64, ptr %77, align 8, !tbaa !16
  %79 = sub i64 %78, 1
  %80 = getelementptr inbounds ptr, ptr %75, i64 %79
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZL10string_setPPcPKc(ptr noundef %80, ptr noundef %81)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %82

82:                                               ; preds = %37, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %83 = load i32, ptr %4, align 4
  ret i32 %83
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL11string_initPPc(ptr noundef) #2

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

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 = !{!10, !6, i64 80}
!10 = !{!"_ZTS11LodePNGInfo", !11, i64 0, !11, i64 4, !11, i64 8, !12, i64 16, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !14, i64 72, !6, i64 80, !6, i64 88, !14, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !11, i64 136, !15, i64 140, !11, i64 164, !11, i64 168, !11, i64 172, !11, i64 176, !7, i64 184, !7, i64 208}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTS16LodePNGColorMode", !13, i64 0, !11, i64 4, !6, i64 8, !14, i64 16, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36}
!13 = !{!"_ZTS16LodePNGColorType", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"_ZTS11LodePNGTime", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!16 = !{!10, !14, i64 72}
!17 = !{!10, !6, i64 88}


; 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 void @_ZL6myfreePv(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZL9myreallocPvm(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 84) i32 @_Z16lodepng_add_textP11LodePNGInfoPKcS2_(ptr nocapture noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 80
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 72
  %7 = load i64, ptr %6, align 8, !tbaa !15
  %8 = shl i64 %7, 3
  %9 = add i64 %8, 8
  %10 = tail call noundef ptr @_ZL9myreallocPvm(ptr noundef %5, i64 noundef %9)
  %11 = getelementptr inbounds i8, ptr %0, i64 88
  %12 = load ptr, ptr %11, align 8, !tbaa !16
  %13 = load i64, ptr %6, align 8, !tbaa !15
  %14 = shl i64 %13, 3
  %15 = add i64 %14, 8
  %16 = tail call noundef ptr @_ZL9myreallocPvm(ptr noundef %12, i64 noundef %15)
  %17 = icmp ne ptr %10, null
  %18 = icmp ne ptr %16, null
  %or.cond = and i1 %17, %18
  br i1 %or.cond, label %20, label %19

19:                                               ; preds = %3
  tail call void @_ZL6myfreePv(ptr noundef %10)
  tail call void @_ZL6myfreePv(ptr noundef %16)
  br label %36

20:                                               ; preds = %3
  %21 = load i64, ptr %6, align 8, !tbaa !15
  %22 = add i64 %21, 1
  store i64 %22, ptr %6, align 8, !tbaa !15
  store ptr %10, ptr %4, align 8, !tbaa !5
  store ptr %16, ptr %11, align 8, !tbaa !16
  %23 = getelementptr inbounds ptr, ptr %10, i64 %21
  tail call void @_ZL11string_initPPc(ptr noundef nonnull %23)
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load i64, ptr %6, align 8, !tbaa !15
  %26 = getelementptr ptr, ptr %24, i64 %25
  %27 = getelementptr i8, ptr %26, i64 -8
  tail call void @_ZL10string_setPPcPKc(ptr noundef %27, ptr noundef %1)
  %28 = load ptr, ptr %11, align 8, !tbaa !16
  %29 = load i64, ptr %6, align 8, !tbaa !15
  %30 = getelementptr ptr, ptr %28, i64 %29
  %31 = getelementptr i8, ptr %30, i64 -8
  tail call void @_ZL11string_initPPc(ptr noundef %31)
  %32 = load ptr, ptr %11, align 8, !tbaa !16
  %33 = load i64, ptr %6, align 8, !tbaa !15
  %34 = getelementptr ptr, ptr %32, i64 %33
  %35 = getelementptr i8, ptr %34, i64 -8
  tail call void @_ZL10string_setPPcPKc(ptr noundef %35, ptr noundef %2)
  br label %36

36:                                               ; preds = %20, %19
  %.0 = phi i32 [ 0, %20 ], [ 83, %19 ]
  ret i32 %.0
}

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL10string_setPPcPKc(ptr noundef, 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" }
attributes #1 = { 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, !12, i64 80}
!6 = !{!"_ZTS11LodePNGInfo", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !7, i64 56, !7, i64 60, !7, i64 64, !7, i64 68, !13, i64 72, !12, i64 80, !12, i64 88, !13, i64 96, !12, i64 104, !12, i64 112, !12, i64 120, !12, i64 128, !7, i64 136, !14, i64 140, !7, i64 164, !7, i64 168, !7, i64 172, !7, i64 176, !8, i64 184, !8, i64 208}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS16LodePNGColorMode", !11, i64 0, !7, i64 4, !12, i64 8, !13, i64 16, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36}
!11 = !{!"_ZTS16LodePNGColorType", !8, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!"_ZTS11LodePNGTime", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!15 = !{!6, !13, i64 72}
!16 = !{!6, !12, i64 88}


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