; LLVM IR from simbody/simbody :: Simbody/Visualizer/simbody-visualizer (lodepng)

; 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.LodePNG_UnknownChunks = type { [3 x ptr], [3 x i64] }

; 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 dso_local void @_Z29LodePNG_UnknownChunks_cleanupP21LodePNG_UnknownChunks(ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z26LodePNG_UnknownChunks_copyP21LodePNG_UnknownChunksPKS_(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_Z29LodePNG_UnknownChunks_cleanupP21LodePNG_UnknownChunks(ptr noundef %9)
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %88, %2
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = icmp ult i32 %11, 3
  br i1 %12, label %13, label %91

13:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.LodePNG_UnknownChunks, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds [3 x i64], ptr %15, i64 0, i64 %17
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.LodePNG_UnknownChunks, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds [3 x i64], ptr %21, i64 0, i64 %23
  store i64 %19, ptr %24, align 8, !tbaa !11
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.LodePNG_UnknownChunks, ptr %25, i32 0, i32 1
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds [3 x i64], ptr %26, i64 0, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !11
  %31 = call noalias ptr @malloc(i64 noundef %30) #4
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.LodePNG_UnknownChunks, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds [3 x ptr], ptr %33, i64 0, i64 %35
  store ptr %31, ptr %36, align 8, !tbaa !5
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.LodePNG_UnknownChunks, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds [3 x ptr], ptr %38, i64 0, i64 %40
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %53, label %44

44:                                               ; preds = %13
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.LodePNG_UnknownChunks, ptr %45, i32 0, i32 1
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds [3 x i64], ptr %46, i64 0, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !11
  %51 = icmp ne i64 %50, 0
  br i1 %51, label %52, label %53

52:                                               ; preds = %44
  store i32 9932, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %85

53:                                               ; preds = %44, %13
  store i64 0, ptr %7, align 8, !tbaa !11
  br label %54

54:                                               ; preds = %81, %53
  %55 = load i64, ptr %7, align 8, !tbaa !11
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.LodePNG_UnknownChunks, ptr %56, i32 0, i32 1
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds [3 x i64], ptr %57, i64 0, i64 %59
  %61 = load i64, ptr %60, align 8, !tbaa !11
  %62 = icmp ult i64 %55, %61
  br i1 %62, label %63, label %84

63:                                               ; preds = %54
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.LodePNG_UnknownChunks, ptr %64, i32 0, i32 0
  %66 = load i32, ptr %6, align 4, !tbaa !9
  %67 = zext i32 %66 to i64
  %68 = getelementptr inbounds [3 x ptr], ptr %65, i64 0, i64 %67
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  %70 = load i64, ptr %7, align 8, !tbaa !11
  %71 = getelementptr inbounds i8, ptr %69, i64 %70
  %72 = load i8, ptr %71, align 1, !tbaa !13
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.LodePNG_UnknownChunks, ptr %73, i32 0, i32 0
  %75 = load i32, ptr %6, align 4, !tbaa !9
  %76 = zext i32 %75 to i64
  %77 = getelementptr inbounds [3 x ptr], ptr %74, i64 0, i64 %76
  %78 = load ptr, ptr %77, align 8, !tbaa !5
  %79 = load i64, ptr %7, align 8, !tbaa !11
  %80 = getelementptr inbounds i8, ptr %78, i64 %79
  store i8 %72, ptr %80, align 1, !tbaa !13
  br label %81

81:                                               ; preds = %63
  %82 = load i64, ptr %7, align 8, !tbaa !11
  %83 = add i64 %82, 1
  store i64 %83, ptr %7, align 8, !tbaa !11
  br label %54, !llvm.loop !14

84:                                               ; preds = %54
  store i32 0, ptr %8, align 4
  br label %85

85:                                               ; preds = %84, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %86 = load i32, ptr %8, align 4
  switch i32 %86, label %92 [
    i32 0, label %87
  ]

87:                                               ; preds = %85
  br label %88

88:                                               ; preds = %87
  %89 = load i32, ptr %6, align 4, !tbaa !9
  %90 = add i32 %89, 1
  store i32 %90, ptr %6, align 4, !tbaa !9
  br label %10, !llvm.loop !16

91:                                               ; preds = %10
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %92

92:                                               ; preds = %91, %85
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %93 = load i32, ptr %3, align 4
  ret i32 %93
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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 = { nounwind allocsize(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 }
attributes #4 = { nounwind allocsize(0) }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z26LodePNG_UnknownChunks_copyP21LodePNG_UnknownChunksPKS_(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  tail call void @_Z29LodePNG_UnknownChunks_cleanupP21LodePNG_UnknownChunks(ptr noundef %0)
  %3 = getelementptr inbounds i8, ptr %1, i64 24
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %5, ptr %4, align 8, !tbaa !5
  %6 = tail call noalias ptr @malloc(i64 noundef %5) #2
  store ptr %6, ptr %0, align 8, !tbaa !9
  %.not = icmp ne ptr %6, null
  %.not29 = icmp eq i64 %5, 0
  %or.cond = or i1 %.not, %.not29
  br i1 %or.cond, label %.preheader, label %.critedge

.preheader:                                       ; preds = %2
  br i1 %.not29, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.02630 = phi i64 [ %12, %.lr.ph ], [ 0, %.preheader ]
  %7 = load ptr, ptr %1, align 8, !tbaa !9
  %8 = getelementptr inbounds i8, ptr %7, i64 %.02630
  %9 = load i8, ptr %8, align 1, !tbaa !11
  %10 = load ptr, ptr %0, align 8, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %10, i64 %.02630
  store i8 %9, ptr %11, align 1, !tbaa !11
  %12 = add nuw i64 %.02630, 1
  %13 = load i64, ptr %3, align 8, !tbaa !5
  %14 = icmp ult i64 %12, %13
  br i1 %14, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %15 = getelementptr inbounds i8, ptr %1, i64 32
  %16 = load i64, ptr %15, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 %16, ptr %17, align 8, !tbaa !5
  %18 = tail call noalias ptr @malloc(i64 noundef %16) #2
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %18, ptr %19, align 8, !tbaa !9
  %.not.1 = icmp ne ptr %18, null
  %.not29.1 = icmp eq i64 %16, 0
  %or.cond.1 = or i1 %.not.1, %.not29.1
  br i1 %or.cond.1, label %.preheader.1, label %.critedge

.preheader.1:                                     ; preds = %._crit_edge
  br i1 %.not29.1, label %._crit_edge.1, label %.lr.ph.1

.lr.ph.1:                                         ; preds = %.preheader.1
  %20 = getelementptr inbounds i8, ptr %1, i64 8
  br label %21

21:                                               ; preds = %21, %.lr.ph.1
  %.02630.1 = phi i64 [ 0, %.lr.ph.1 ], [ %27, %21 ]
  %22 = load ptr, ptr %20, align 8, !tbaa !9
  %23 = getelementptr inbounds i8, ptr %22, i64 %.02630.1
  %24 = load i8, ptr %23, align 1, !tbaa !11
  %25 = load ptr, ptr %19, align 8, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %25, i64 %.02630.1
  store i8 %24, ptr %26, align 1, !tbaa !11
  %27 = add nuw i64 %.02630.1, 1
  %28 = load i64, ptr %15, align 8, !tbaa !5
  %29 = icmp ult i64 %27, %28
  br i1 %29, label %21, label %._crit_edge.1, !llvm.loop !12

._crit_edge.1:                                    ; preds = %21, %.preheader.1
  %30 = getelementptr inbounds i8, ptr %1, i64 40
  %31 = load i64, ptr %30, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %0, i64 40
  store i64 %31, ptr %32, align 8, !tbaa !5
  %33 = tail call noalias ptr @malloc(i64 noundef %31) #2
  %34 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %33, ptr %34, align 8, !tbaa !9
  %.not.2 = icmp ne ptr %33, null
  %.not29.2 = icmp eq i64 %31, 0
  %or.cond.2 = or i1 %.not.2, %.not29.2
  %35 = xor i1 %.not.2, true
  %brmerge = or i1 %.not29.2, %35
  %.mux = select i1 %or.cond.2, i32 0, i32 9932
  br i1 %brmerge, label %.critedge, label %.lr.ph.2

.lr.ph.2:                                         ; preds = %._crit_edge.1
  %36 = getelementptr inbounds i8, ptr %1, i64 16
  br label %37

37:                                               ; preds = %37, %.lr.ph.2
  %.02630.2 = phi i64 [ 0, %.lr.ph.2 ], [ %43, %37 ]
  %38 = load ptr, ptr %36, align 8, !tbaa !9
  %39 = getelementptr inbounds i8, ptr %38, i64 %.02630.2
  %40 = load i8, ptr %39, align 1, !tbaa !11
  %41 = load ptr, ptr %34, align 8, !tbaa !9
  %42 = getelementptr inbounds i8, ptr %41, i64 %.02630.2
  store i8 %40, ptr %42, align 1, !tbaa !11
  %43 = add nuw i64 %.02630.2, 1
  %44 = load i64, ptr %30, align 8, !tbaa !5
  %45 = icmp ult i64 %43, %44
  br i1 %45, label %37, label %.critedge, !llvm.loop !12

.critedge:                                        ; preds = %37, %._crit_edge.1, %._crit_edge, %2
  %.2 = phi i32 [ 9932, %2 ], [ 9932, %._crit_edge ], [ %.mux, %._crit_edge.1 ], [ 0, %37 ]
  ret i32 %.2
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nounwind allocsize(0) }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass