; LLVM IR from facebookresearch/habitat-sim :: src/deps/basis-universal/encoder/lodepng.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, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, 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 @_ZL12lodepng_freePv(ptr noundef) #1

; 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 @_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 @_ZL15lodepng_reallocPvm(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 @_ZL15lodepng_reallocPvm(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 @_ZL12lodepng_freePv(ptr noundef %35)
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  call void @_ZL12lodepng_freePv(ptr noundef %36)
  store i32 83, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %68

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 %6, align 8, !tbaa !5
  %49 = call noundef ptr @_ZL12alloc_stringPKc(ptr noundef %48)
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.LodePNGInfo, ptr %50, i32 0, i32 9
  %52 = load ptr, ptr %51, align 8, !tbaa !9
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.LodePNGInfo, ptr %53, i32 0, i32 8
  %55 = load i64, ptr %54, align 8, !tbaa !16
  %56 = sub i64 %55, 1
  %57 = getelementptr inbounds ptr, ptr %52, i64 %56
  store ptr %49, ptr %57, align 8, !tbaa !5
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = call noundef ptr @_ZL12alloc_stringPKc(ptr noundef %58)
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.LodePNGInfo, ptr %60, i32 0, i32 10
  %62 = load ptr, ptr %61, align 8, !tbaa !17
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.LodePNGInfo, ptr %63, i32 0, i32 8
  %65 = load i64, ptr %64, align 8, !tbaa !16
  %66 = sub i64 %65, 1
  %67 = getelementptr inbounds ptr, ptr %62, i64 %66
  store ptr %59, ptr %67, align 8, !tbaa !5
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %68

68:                                               ; 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
  %69 = load i32, ptr %4, align 4
  ret i32 %69
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZL12alloc_stringPKc(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, !11, i64 180, !11, i64 184, !11, i64 188, !11, i64 192, !11, i64 196, !11, i64 200, !11, i64 204, !11, i64 208, !11, i64 212, !11, i64 216, !11, i64 220, !11, i64 224, !11, i64 228, !11, i64 232, !6, i64 240, !6, i64 248, !11, i64 256, !7, i64 264, !7, i64 288}
!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 @_ZL12lodepng_freePv(ptr noundef) local_unnamed_addr #0

; 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 @_Z16lodepng_add_textP11LodePNGInfoPKcS2_(ptr nocapture noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %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 @_ZL15lodepng_reallocPvm(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 @_ZL15lodepng_reallocPvm(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 @_ZL12lodepng_freePv(ptr noundef %10)
  tail call void @_ZL12lodepng_freePv(ptr noundef %16)
  br label %33

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 = tail call noundef ptr @_ZL12alloc_stringPKc(ptr noundef %1)
  %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
  store ptr %23, ptr %27, align 8, !tbaa !17
  %28 = tail call noundef ptr @_ZL12alloc_stringPKc(ptr noundef %2)
  %29 = load ptr, ptr %11, align 8, !tbaa !16
  %30 = load i64, ptr %6, align 8, !tbaa !15
  %31 = getelementptr ptr, ptr %29, i64 %30
  %32 = getelementptr i8, ptr %31, i64 -8
  store ptr %28, ptr %32, align 8, !tbaa !17
  br label %33

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZL12alloc_stringPKc(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, !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, !7, i64 180, !7, i64 184, !7, i64 188, !7, i64 192, !7, i64 196, !7, i64 200, !7, i64 204, !7, i64 208, !7, i64 212, !7, i64 216, !7, i64 220, !7, i64 224, !7, i64 228, !7, i64 232, !12, i64 240, !12, i64 248, !7, i64 256, !8, i64 264, !8, i64 288}
!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}
!17 = !{!12, !12, i64 0}


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