; LLVM IR from GitZHCODE/zspace_core :: cpp/depends/lodePNG/examples (example_encode)

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

@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @encodeOneStep(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = icmp sgt i32 %12, 1
  br i1 %13, label %14, label %18

14:                                               ; preds = %2
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = getelementptr inbounds ptr, ptr %15, i64 1
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  br label %19

18:                                               ; preds = %2
  br label %19

19:                                               ; preds = %18, %14
  %20 = phi ptr [ %17, %14 ], [ @.str.1, %18 ]
  store ptr %20, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 512, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 512, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = load i32, ptr %8, align 4, !tbaa !5
  %23 = mul i32 %21, %22
  %24 = mul i32 %23, 4
  %25 = zext i32 %24 to i64
  %26 = call noalias ptr @malloc(i64 noundef %25) #5
  store ptr %26, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %101, %19
  %28 = load i32, ptr %11, align 4, !tbaa !5
  %29 = load i32, ptr %8, align 4, !tbaa !5
  %30 = icmp ult i32 %28, %29
  br i1 %30, label %31, label %104

31:                                               ; preds = %27
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %97, %31
  %33 = load i32, ptr %10, align 4, !tbaa !5
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = icmp ult i32 %33, %34
  br i1 %35, label %36, label %100

36:                                               ; preds = %32
  %37 = load i32, ptr %10, align 4, !tbaa !5
  %38 = load i32, ptr %11, align 4, !tbaa !5
  %39 = and i32 %37, %38
  %40 = icmp ne i32 %39, 0
  %41 = xor i1 %40, true
  %42 = zext i1 %41 to i32
  %43 = mul nsw i32 255, %42
  %44 = trunc i32 %43 to i8
  %45 = load ptr, ptr %9, align 8, !tbaa !9
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = mul i32 4, %46
  %48 = load i32, ptr %11, align 4, !tbaa !5
  %49 = mul i32 %47, %48
  %50 = load i32, ptr %10, align 4, !tbaa !5
  %51 = mul i32 4, %50
  %52 = add i32 %49, %51
  %53 = add i32 %52, 0
  %54 = zext i32 %53 to i64
  %55 = getelementptr inbounds i8, ptr %45, i64 %54
  store i8 %44, ptr %55, align 1, !tbaa !11
  %56 = load i32, ptr %10, align 4, !tbaa !5
  %57 = load i32, ptr %11, align 4, !tbaa !5
  %58 = xor i32 %56, %57
  %59 = trunc i32 %58 to i8
  %60 = load ptr, ptr %9, align 8, !tbaa !9
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = mul i32 4, %61
  %63 = load i32, ptr %11, align 4, !tbaa !5
  %64 = mul i32 %62, %63
  %65 = load i32, ptr %10, align 4, !tbaa !5
  %66 = mul i32 4, %65
  %67 = add i32 %64, %66
  %68 = add i32 %67, 1
  %69 = zext i32 %68 to i64
  %70 = getelementptr inbounds i8, ptr %60, i64 %69
  store i8 %59, ptr %70, align 1, !tbaa !11
  %71 = load i32, ptr %10, align 4, !tbaa !5
  %72 = load i32, ptr %11, align 4, !tbaa !5
  %73 = or i32 %71, %72
  %74 = trunc i32 %73 to i8
  %75 = load ptr, ptr %9, align 8, !tbaa !9
  %76 = load i32, ptr %7, align 4, !tbaa !5
  %77 = mul i32 4, %76
  %78 = load i32, ptr %11, align 4, !tbaa !5
  %79 = mul i32 %77, %78
  %80 = load i32, ptr %10, align 4, !tbaa !5
  %81 = mul i32 4, %80
  %82 = add i32 %79, %81
  %83 = add i32 %82, 2
  %84 = zext i32 %83 to i64
  %85 = getelementptr inbounds i8, ptr %75, i64 %84
  store i8 %74, ptr %85, align 1, !tbaa !11
  %86 = load ptr, ptr %9, align 8, !tbaa !9
  %87 = load i32, ptr %7, align 4, !tbaa !5
  %88 = mul i32 4, %87
  %89 = load i32, ptr %11, align 4, !tbaa !5
  %90 = mul i32 %88, %89
  %91 = load i32, ptr %10, align 4, !tbaa !5
  %92 = mul i32 4, %91
  %93 = add i32 %90, %92
  %94 = add i32 %93, 3
  %95 = zext i32 %94 to i64
  %96 = getelementptr inbounds i8, ptr %86, i64 %95
  store i8 -1, ptr %96, align 1, !tbaa !11
  br label %97

97:                                               ; preds = %36
  %98 = load i32, ptr %10, align 4, !tbaa !5
  %99 = add i32 %98, 1
  store i32 %99, ptr %10, align 4, !tbaa !5
  br label %32, !llvm.loop !12

100:                                              ; preds = %32
  br label %101

101:                                              ; preds = %100
  %102 = load i32, ptr %11, align 4, !tbaa !5
  %103 = add i32 %102, 1
  store i32 %103, ptr %11, align 4, !tbaa !5
  br label %27, !llvm.loop !14

104:                                              ; preds = %27
  %105 = load ptr, ptr %6, align 8, !tbaa !9
  %106 = load ptr, ptr %9, align 8, !tbaa !9
  %107 = load i32, ptr %7, align 4, !tbaa !5
  %108 = load i32, ptr %8, align 4, !tbaa !5
  call void @encodeOneStep(ptr noundef %105, ptr noundef %106, i32 noundef %107, i32 noundef %108)
  %109 = load ptr, ptr %9, align 8, !tbaa !9
  call void @free(ptr noundef %109) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  ret i32 0
}

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind "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 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 #4 = { nounwind }
attributes #5 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/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"}
!14 = distinct !{!14, !13}


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

@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @encodeOneStep(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %0, 1
  br i1 %3, label %4, label %7

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %2, %4
  %8 = phi ptr [ %6, %4 ], [ @.str.1, %2 ]
  %9 = tail call noalias dereferenceable_or_null(1048576) ptr @malloc(i64 noundef 1048576) #3
  br label %.preheader

.preheader:                                       ; preds = %7, %29
  %indvars.iv40 = phi i64 [ 0, %7 ], [ %indvars.iv.next41, %29 ]
  %10 = shl nuw nsw i64 %indvars.iv40, 11
  %11 = trunc nuw nsw i64 %indvars.iv40 to i32
  br label %12

12:                                               ; preds = %.preheader, %12
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next, %12 ]
  %13 = trunc nuw nsw i64 %indvars.iv to i32
  %14 = and i32 %13, %11
  %.not = icmp eq i32 %14, 0
  %15 = sext i1 %.not to i8
  %16 = shl nuw nsw i64 %indvars.iv, 2
  %17 = add nuw nsw i64 %16, %10
  %18 = getelementptr inbounds i8, ptr %9, i64 %17
  store i8 %15, ptr %18, align 1, !tbaa !9
  %19 = xor i32 %13, %11
  %20 = trunc i32 %19 to i8
  %21 = or disjoint i64 %17, 1
  %22 = getelementptr inbounds i8, ptr %9, i64 %21
  store i8 %20, ptr %22, align 1, !tbaa !9
  %23 = or i32 %13, %11
  %24 = trunc i32 %23 to i8
  %25 = or disjoint i64 %17, 2
  %26 = getelementptr inbounds i8, ptr %9, i64 %25
  store i8 %24, ptr %26, align 1, !tbaa !9
  %27 = or disjoint i64 %17, 3
  %28 = getelementptr inbounds i8, ptr %9, i64 %27
  store i8 -1, ptr %28, align 1, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 512
  br i1 %exitcond.not, label %29, label %12, !llvm.loop !10

29:                                               ; preds = %12
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %exitcond43.not = icmp eq i64 %indvars.iv.next41, 512
  br i1 %exitcond43.not, label %30, label %.preheader, !llvm.loop !12

30:                                               ; preds = %29
  tail call void @encodeOneStep(ptr noundef %8, ptr noundef nonnull %9, i32 noundef 512, i32 noundef 512)
  tail call void @free(ptr noundef nonnull %9) #4
  ret i32 0
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

attributes #0 = { 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 nounwind willreturn allockind("free") memory(argmem: readwrite, 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 = { 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 #3 = { nounwind allocsize(0) }
attributes #4 = { 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/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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