; LLVM IR from a-earthperson/Android-NDK-FileCrypto-AES-CBC :: encrypt (do_zlib_encrypt)

; 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.z_stream_s = type { ptr, i32, i64, ptr, i32, i64, ptr, ptr, ptr, ptr, ptr, i32, i64, i64 }
%struct.params = type { i64, i64, i64, i32, i64, i64, ptr }

@.str = external hidden unnamed_addr constant [6 x i8], align 1
@RAW_in = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @do_zlib_encrypt(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca %struct.z_stream_s, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %6, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.params, ptr %7, i32 0, i32 2
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %10 = icmp sgt i64 1048576, %9
  br i1 %10, label %11, label %15

11:                                               ; preds = %1
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.params, ptr %12, i32 0, i32 2
  %14 = load i64, ptr %13, align 8, !tbaa !9
  br label %16

15:                                               ; preds = %1
  br label %16

16:                                               ; preds = %15, %11
  %17 = phi i64 [ %14, %11 ], [ 1048576, %15 ]
  store i64 %17, ptr %4, align 8, !tbaa !13
  %18 = load i64, ptr %4, align 8, !tbaa !13
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.params, ptr %19, i32 0, i32 5
  store i64 %18, ptr %20, align 8, !tbaa !14
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.params, ptr %21, i32 0, i32 4
  store i64 0, ptr %22, align 8, !tbaa !15
  %23 = load i64, ptr %4, align 8, !tbaa !13
  %24 = mul i64 %23, 1
  %25 = call noalias ptr @malloc(i64 noundef %24) #7
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.params, ptr %26, i32 0, i32 6
  store ptr %25, ptr %27, align 8, !tbaa !16
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.params, ptr %28, i32 0, i32 6
  %30 = load ptr, ptr %29, align 8, !tbaa !16
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %33

32:                                               ; preds = %16
  call void @exit(i32 noundef 1) #8
  unreachable

33:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 112, ptr %5) #6
  %34 = getelementptr inbounds %struct.z_stream_s, ptr %5, i32 0, i32 8
  store ptr null, ptr %34, align 8, !tbaa !17
  %35 = getelementptr inbounds %struct.z_stream_s, ptr %5, i32 0, i32 9
  store ptr null, ptr %35, align 8, !tbaa !19
  %36 = getelementptr inbounds %struct.z_stream_s, ptr %5, i32 0, i32 10
  store ptr null, ptr %36, align 8, !tbaa !20
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.params, ptr %37, i32 0, i32 3
  %39 = load i32, ptr %38, align 8, !tbaa !21
  %40 = call i32 @deflateInit2_(ptr noundef %5, i32 noundef %39, i32 noundef 8, i32 noundef 31, i32 noundef 8, i32 noundef 0, ptr noundef @.str, i32 noundef 112)
  %41 = icmp slt i32 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %33
  call void @exit(i32 noundef 1) #8
  unreachable

43:                                               ; preds = %33
  %44 = load ptr, ptr @RAW_in, align 8, !tbaa !5
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.params, ptr %45, i32 0, i32 1
  %47 = load i64, ptr %46, align 8, !tbaa !22
  %48 = getelementptr inbounds i8, ptr %44, i64 %47
  %49 = getelementptr inbounds %struct.z_stream_s, ptr %5, i32 0, i32 0
  store ptr %48, ptr %49, align 8, !tbaa !23
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.params, ptr %50, i32 0, i32 2
  %52 = load i64, ptr %51, align 8, !tbaa !9
  %53 = trunc i64 %52 to i32
  %54 = getelementptr inbounds %struct.z_stream_s, ptr %5, i32 0, i32 1
  store i32 %53, ptr %54, align 8, !tbaa !24
  %55 = getelementptr inbounds %struct.z_stream_s, ptr %5, i32 0, i32 4
  store i32 0, ptr %55, align 8, !tbaa !25
  br label %56

56:                                               ; preds = %71, %43
  %57 = getelementptr inbounds %struct.z_stream_s, ptr %5, i32 0, i32 4
  %58 = load i32, ptr %57, align 8, !tbaa !25
  %59 = icmp eq i32 %58, 0
  br i1 %59, label %60, label %83

60:                                               ; preds = %56
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.params, ptr %61, i32 0, i32 6
  %63 = load ptr, ptr %62, align 8, !tbaa !16
  %64 = getelementptr inbounds %struct.z_stream_s, ptr %5, i32 0, i32 3
  store ptr %63, ptr %64, align 8, !tbaa !26
  %65 = load i64, ptr %4, align 8, !tbaa !13
  %66 = trunc i64 %65 to i32
  %67 = getelementptr inbounds %struct.z_stream_s, ptr %5, i32 0, i32 4
  store i32 %66, ptr %67, align 8, !tbaa !25
  %68 = call i32 @deflate(ptr noundef %5, i32 noundef 4)
  %69 = icmp slt i32 %68, 0
  br i1 %69, label %70, label %71

70:                                               ; preds = %60
  br label %83

71:                                               ; preds = %60
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.params, ptr %72, i32 0, i32 2
  %74 = load i64, ptr %73, align 8, !tbaa !9
  %75 = getelementptr inbounds %struct.z_stream_s, ptr %5, i32 0, i32 4
  %76 = load i32, ptr %75, align 8, !tbaa !25
  %77 = zext i32 %76 to i64
  %78 = sub nsw i64 %74, %77
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.params, ptr %79, i32 0, i32 4
  %81 = load i64, ptr %80, align 8, !tbaa !15
  %82 = add nsw i64 %81, %78
  store i64 %82, ptr %80, align 8, !tbaa !15
  br label %56, !llvm.loop !27

83:                                               ; preds = %70, %56
  %84 = call i32 @deflateEnd(ptr noundef %5)
  call void @pthread_exit(ptr noundef null) #9
  unreachable
}

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

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #3

declare i32 @deflateInit2_(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef) #4

declare i32 @deflate(ptr noundef, i32 noundef) #4

declare i32 @deflateEnd(ptr noundef) #4

; Function Attrs: noreturn
declare void @pthread_exit(ptr noundef) #5

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 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 = { noreturn 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 #4 = { "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 #5 = { noreturn "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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }
attributes #8 = { noreturn nounwind }
attributes #9 = { noreturn }

!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 = !{!10, !11, i64 16}
!10 = !{!"", !11, i64 0, !11, i64 8, !11, i64 16, !12, i64 24, !11, i64 32, !11, i64 40, !6, i64 48}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 40}
!15 = !{!10, !11, i64 32}
!16 = !{!10, !6, i64 48}
!17 = !{!18, !6, i64 64}
!18 = !{!"z_stream_s", !6, i64 0, !12, i64 8, !11, i64 16, !6, i64 24, !12, i64 32, !11, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !12, i64 88, !11, i64 96, !11, i64 104}
!19 = !{!18, !6, i64 72}
!20 = !{!18, !6, i64 80}
!21 = !{!10, !12, i64 24}
!22 = !{!10, !11, i64 8}
!23 = !{!18, !6, i64 0}
!24 = !{!18, !12, i64 8}
!25 = !{!18, !12, i64 32}
!26 = !{!18, !6, i64 24}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}


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

%struct.z_stream_s = type { ptr, i32, i64, ptr, i32, i64, ptr, ptr, ptr, ptr, ptr, i32, i64, i64 }

@.str = external hidden unnamed_addr constant [6 x i8], align 1
@RAW_in = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: noreturn nounwind uwtable
define dso_local noalias noundef nonnull ptr @do_zlib_encrypt(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = alloca %struct.z_stream_s, align 8
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %spec.select = tail call i64 @llvm.smin.i64(i64 %4, i64 1048576)
  %5 = getelementptr inbounds i8, ptr %0, i64 40
  store i64 %spec.select, ptr %5, align 8, !tbaa !12
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 0, ptr %6, align 8, !tbaa !13
  %7 = tail call noalias ptr @malloc(i64 noundef %spec.select) #8
  %8 = getelementptr inbounds i8, ptr %0, i64 48
  store ptr %7, ptr %8, align 8, !tbaa !14
  %9 = icmp eq ptr %7, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %1
  tail call void @exit(i32 noundef 1) #9
  unreachable

11:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 112, ptr nonnull %2) #10
  %12 = getelementptr inbounds i8, ptr %2, i64 64
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %12, i8 0, i64 24, i1 false)
  %14 = load i32, ptr %13, align 8, !tbaa !15
  %15 = call i32 @deflateInit2_(ptr noundef nonnull %2, i32 noundef %14, i32 noundef 8, i32 noundef 31, i32 noundef 8, i32 noundef 0, ptr noundef nonnull @.str, i32 noundef 112) #10
  %16 = icmp slt i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %11
  call void @exit(i32 noundef 1) #9
  unreachable

18:                                               ; preds = %11
  %19 = load ptr, ptr @RAW_in, align 8, !tbaa !16
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  %21 = load i64, ptr %20, align 8, !tbaa !17
  %22 = getelementptr inbounds i8, ptr %19, i64 %21
  store ptr %22, ptr %2, align 8, !tbaa !18
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = trunc i64 %23 to i32
  %25 = getelementptr inbounds i8, ptr %2, i64 8
  store i32 %24, ptr %25, align 8, !tbaa !20
  %26 = getelementptr inbounds i8, ptr %2, i64 32
  %27 = getelementptr inbounds i8, ptr %2, i64 24
  %28 = trunc i64 %spec.select to i32
  br label %29

29:                                               ; preds = %18, %33
  %30 = load ptr, ptr %8, align 8, !tbaa !14
  store ptr %30, ptr %27, align 8, !tbaa !21
  store i32 %28, ptr %26, align 8, !tbaa !22
  %31 = call i32 @deflate(ptr noundef nonnull %2, i32 noundef 4) #10
  %32 = icmp slt i32 %31, 0
  br i1 %32, label %41, label %33

33:                                               ; preds = %29
  %34 = load i64, ptr %3, align 8, !tbaa !5
  %35 = load i32, ptr %26, align 8, !tbaa !22
  %36 = zext i32 %35 to i64
  %37 = sub i64 %34, %36
  %38 = load i64, ptr %6, align 8, !tbaa !13
  %39 = add nsw i64 %37, %38
  store i64 %39, ptr %6, align 8, !tbaa !13
  %40 = icmp eq i32 %35, 0
  br i1 %40, label %29, label %41, !llvm.loop !23

41:                                               ; preds = %29, %33
  %42 = call i32 @deflateEnd(ptr noundef nonnull %2) #10
  call void @pthread_exit(ptr noundef null) #9
  unreachable
}

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

; 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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #3

declare i32 @deflateInit2_(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #4

declare i32 @deflate(ptr noundef, i32 noundef) local_unnamed_addr #4

declare i32 @deflateEnd(ptr noundef) local_unnamed_addr #4

; Function Attrs: noreturn
declare void @pthread_exit(ptr noundef) local_unnamed_addr #5

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, i64) #6

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #7

attributes #0 = { noreturn 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { noreturn 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 #4 = { "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 #5 = { noreturn "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 #6 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #7 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #8 = { nounwind allocsize(0) }
attributes #9 = { noreturn nounwind }
attributes #10 = { 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, !7, i64 16}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !7, i64 32, !7, i64 40, !11, i64 48}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !7, i64 40}
!13 = !{!6, !7, i64 32}
!14 = !{!6, !11, i64 48}
!15 = !{!6, !10, i64 24}
!16 = !{!11, !11, i64 0}
!17 = !{!6, !7, i64 8}
!18 = !{!19, !11, i64 0}
!19 = !{!"z_stream_s", !11, i64 0, !10, i64 8, !7, i64 16, !11, i64 24, !10, i64 32, !7, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !10, i64 88, !7, i64 96, !7, i64 104}
!20 = !{!19, !10, i64 8}
!21 = !{!19, !11, i64 24}
!22 = !{!19, !10, i64 32}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass