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

; 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.stat = type { i64, i64, i64, i32, i32, i32, i32, i64, i64, i64, i64, %struct.timespec, %struct.timespec, %struct.timespec, [3 x i64] }
%struct.timespec = type { i64, i64 }

@.str.8 = external hidden unnamed_addr constant [41 x i8], align 1
@extension = external hidden constant [7 x i8], align 1
@aes_key = external hidden constant [16 x i8], align 16

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @zlib_encrypt(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, i32 noundef, i32 noundef) #1

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #1 {
  %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 %struct.stat, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i64, align 8
  %19 = alloca i64, align 8
  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) #5
  %20 = load ptr, ptr %5, align 8, !tbaa !9
  %21 = getelementptr inbounds ptr, ptr %20, i64 1
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  store ptr %22, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %23 = load ptr, ptr %5, align 8, !tbaa !9
  %24 = getelementptr inbounds ptr, ptr %23, i64 1
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  %26 = call i32 (ptr, i32, ...) @open(ptr noundef %25, i32 noundef 0)
  store i32 %26, ptr %7, align 4, !tbaa !5
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = icmp slt i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %102

30:                                               ; preds = %2
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 144, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = call i32 @fstat(i32 noundef %31, ptr noundef %9) #5
  store i32 %32, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %33 = getelementptr inbounds %struct.stat, ptr %9, i32 0, i32 8
  %34 = load i64, ptr %33, align 8, !tbaa !11
  store i64 %34, ptr %11, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %35 = load i64, ptr %11, align 8, !tbaa !15
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = call ptr @mmap(ptr noundef null, i64 noundef %35, i32 noundef 1, i32 noundef 2, i32 noundef %36, i64 noundef 0) #5
  store ptr %37, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %38 = load i64, ptr %11, align 8, !tbaa !15
  store i64 %38, ptr %13, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %39 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %39, ptr %14, align 8, !tbaa !9
  %40 = load ptr, ptr %6, align 8, !tbaa !9
  %41 = load i64, ptr %13, align 8, !tbaa !15
  %42 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, ptr noundef %40, i64 noundef %41)
  store i64 0, ptr %11, align 8, !tbaa !15
  br label %43

43:                                               ; preds = %51, %30
  %44 = load ptr, ptr %6, align 8, !tbaa !9
  %45 = load i64, ptr %11, align 8, !tbaa !15
  %46 = getelementptr inbounds i8, ptr %44, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !16
  %48 = sext i8 %47 to i32
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %54

50:                                               ; preds = %43
  br label %51

51:                                               ; preds = %50
  %52 = load i64, ptr %11, align 8, !tbaa !15
  %53 = add nsw i64 %52, 1
  store i64 %53, ptr %11, align 8, !tbaa !15
  br label %43, !llvm.loop !17

54:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %55 = load i64, ptr %11, align 8, !tbaa !15
  store i64 %55, ptr %15, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  %56 = load i64, ptr %11, align 8, !tbaa !15
  %57 = add i64 %56, 7
  store i64 %57, ptr %16, align 8, !tbaa !15
  %58 = load i64, ptr %16, align 8, !tbaa !15
  %59 = call ptr @llvm.stacksave.p0()
  store ptr %59, ptr %17, align 8
  %60 = alloca i8, i64 %58, align 16
  store i64 %58, ptr %18, align 8
  store i64 0, ptr %11, align 8, !tbaa !15
  br label %61

61:                                               ; preds = %75, %54
  %62 = load ptr, ptr %6, align 8, !tbaa !9
  %63 = load i64, ptr %11, align 8, !tbaa !15
  %64 = getelementptr inbounds i8, ptr %62, i64 %63
  %65 = load i8, ptr %64, align 1, !tbaa !16
  %66 = sext i8 %65 to i32
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %68, label %78

68:                                               ; preds = %61
  %69 = load ptr, ptr %6, align 8, !tbaa !9
  %70 = load i64, ptr %11, align 8, !tbaa !15
  %71 = getelementptr inbounds i8, ptr %69, i64 %70
  %72 = load i8, ptr %71, align 1, !tbaa !16
  %73 = load i64, ptr %11, align 8, !tbaa !15
  %74 = getelementptr inbounds i8, ptr %60, i64 %73
  store i8 %72, ptr %74, align 1, !tbaa !16
  br label %75

75:                                               ; preds = %68
  %76 = load i64, ptr %11, align 8, !tbaa !15
  %77 = add nsw i64 %76, 1
  store i64 %77, ptr %11, align 8, !tbaa !15
  br label %61, !llvm.loop !19

78:                                               ; preds = %61
  %79 = load i64, ptr %11, align 8, !tbaa !15
  br label %80

80:                                               ; preds = %92, %78
  %81 = load i64, ptr %11, align 8, !tbaa !15
  %82 = load i64, ptr %16, align 8, !tbaa !15
  %83 = icmp sle i64 %81, %82
  br i1 %83, label %84, label %95

84:                                               ; preds = %80
  %85 = load i64, ptr %11, align 8, !tbaa !15
  %86 = load i64, ptr %15, align 8, !tbaa !15
  %87 = sub nsw i64 %85, %86
  %88 = getelementptr inbounds [7 x i8], ptr @extension, i64 0, i64 %87
  %89 = load i8, ptr %88, align 1, !tbaa !16
  %90 = load i64, ptr %11, align 8, !tbaa !15
  %91 = getelementptr inbounds i8, ptr %60, i64 %90
  store i8 %89, ptr %91, align 1, !tbaa !16
  br label %92

92:                                               ; preds = %84
  %93 = load i64, ptr %11, align 8, !tbaa !15
  %94 = add nsw i64 %93, 1
  store i64 %94, ptr %11, align 8, !tbaa !15
  br label %80, !llvm.loop !20

95:                                               ; preds = %80
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #5
  %96 = load ptr, ptr %14, align 8, !tbaa !9
  %97 = load i64, ptr %13, align 8, !tbaa !15
  %98 = call i64 @zlib_encrypt(ptr noundef %60, ptr noundef %96, i64 noundef %97, ptr noundef @aes_key, i64 noundef 16, i32 noundef 0, i32 noundef -1)
  store i64 %98, ptr %19, align 8, !tbaa !15
  %99 = load i64, ptr %19, align 8, !tbaa !15
  %100 = trunc i64 %99 to i32
  store i32 %100, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #5
  %101 = load ptr, ptr %17, align 8
  call void @llvm.stackrestore.p0(ptr %101)
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 144, ptr %9) #5
  br label %102

102:                                              ; preds = %95, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %103 = load i32, ptr %3, align 4
  ret i32 %103
}

declare i32 @open(ptr noundef, i32 noundef, ...) #2

; Function Attrs: nounwind
declare i32 @fstat(i32 noundef, ptr noundef) #4

; Function Attrs: nounwind
declare ptr @mmap(ptr noundef, i64 noundef, i32 noundef, i32 noundef, i32 noundef, i64 noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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 = { nocallback nofree nosync nounwind willreturn }
attributes #4 = { 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 #5 = { 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 = !{!"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 = !{!12, !13, i64 48}
!12 = !{!"stat", !13, i64 0, !13, i64 8, !13, i64 16, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !14, i64 72, !14, i64 88, !14, i64 104, !7, i64 120}
!13 = !{!"long", !7, i64 0}
!14 = !{!"timespec", !13, i64 0, !13, i64 8}
!15 = !{!13, !13, i64 0}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = distinct !{!20, !18}


; 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.stat = type { i64, i64, i64, i32, i32, i32, i32, i64, i64, i64, i64, %struct.timespec, %struct.timespec, %struct.timespec, [3 x i64] }
%struct.timespec = type { i64, i64 }

@.str.8 = external hidden unnamed_addr constant [41 x i8], align 1
@extension = external hidden local_unnamed_addr constant [7 x i8], align 1
@aes_key = external hidden constant [16 x i8], align 16

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @zlib_encrypt(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = alloca %struct.stat, align 8
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = tail call i32 (ptr, i32, ...) @open(ptr noundef %5, i32 noundef 0) #7
  %7 = icmp slt i32 %6, 0
  br i1 %7, label %33, label %8

8:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 144, ptr nonnull %3) #7
  %9 = call i32 @fstat(i32 noundef %6, ptr noundef nonnull %3) #7
  %10 = getelementptr inbounds i8, ptr %3, i64 48
  %11 = load i64, ptr %10, align 8, !tbaa !9
  %12 = tail call ptr @mmap(ptr noundef null, i64 noundef %11, i32 noundef 1, i32 noundef 2, i32 noundef %6, i64 noundef 0) #7
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, ptr noundef %5, i64 noundef %11)
  br label %14

14:                                               ; preds = %14, %8
  %.033 = phi i64 [ 0, %8 ], [ %17, %14 ]
  %15 = getelementptr inbounds i8, ptr %5, i64 %.033
  %16 = load i8, ptr %15, align 1, !tbaa !14
  %.not = icmp eq i8 %16, 0
  %17 = add nuw nsw i64 %.033, 1
  br i1 %.not, label %18, label %14, !llvm.loop !15

18:                                               ; preds = %14
  %19 = add nuw i64 %.033, 7
  %20 = tail call ptr @llvm.stacksave.p0()
  %21 = alloca i8, i64 %19, align 16
  %22 = load i8, ptr %5, align 1, !tbaa !14
  %.not3537 = icmp eq i8 %22, 0
  br i1 %.not3537, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %18
  %.1.lcssa = phi i64 [ 0, %18 ], [ %28, %.lr.ph ]
  %.not3639 = icmp sgt i64 %.1.lcssa, %19
  br i1 %.not3639, label %._crit_edge, label %.lr.ph41.preheader

.lr.ph41.preheader:                               ; preds = %.preheader
  %scevgep = getelementptr i8, ptr %21, i64 %.1.lcssa
  %23 = sub nsw i64 0, %.033
  %scevgep43 = getelementptr i8, ptr @extension, i64 %23
  %scevgep44 = getelementptr i8, ptr %scevgep43, i64 %.1.lcssa
  %24 = add nuw i64 %.033, 8
  %25 = sub i64 %24, %.1.lcssa
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %scevgep, ptr align 1 %scevgep44, i64 %25, i1 false), !tbaa !14
  br label %._crit_edge

.lr.ph:                                           ; preds = %18, %.lr.ph
  %26 = phi i8 [ %30, %.lr.ph ], [ %22, %18 ]
  %.138 = phi i64 [ %28, %.lr.ph ], [ 0, %18 ]
  %27 = getelementptr inbounds i8, ptr %21, i64 %.138
  store i8 %26, ptr %27, align 1, !tbaa !14
  %28 = add nuw nsw i64 %.138, 1
  %29 = getelementptr inbounds i8, ptr %5, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !14
  %.not35 = icmp eq i8 %30, 0
  br i1 %.not35, label %.preheader, label %.lr.ph, !llvm.loop !17

._crit_edge:                                      ; preds = %.lr.ph41.preheader, %.preheader
  %31 = call i64 @zlib_encrypt(ptr noundef nonnull %21, ptr noundef %12, i64 noundef %11, ptr noundef nonnull @aes_key, i64 noundef 16, i32 noundef 0, i32 noundef -1)
  %32 = trunc i64 %31 to i32
  call void @llvm.stackrestore.p0(ptr %20)
  call void @llvm.lifetime.end.p0(i64 144, ptr nonnull %3) #7
  br label %33

33:                                               ; preds = %2, %._crit_edge
  %.0 = phi i32 [ %32, %._crit_edge ], [ -1, %2 ]
  ret i32 %.0
}

; Function Attrs: nofree
declare noundef i32 @open(ptr nocapture noundef readonly, i32 noundef, ...) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @fstat(i32 noundef, ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare ptr @mmap(ptr noundef, i64 noundef, i32 noundef, i32 noundef, i32 noundef, i64 noundef) local_unnamed_addr #5

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #6

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { nofree 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 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #4 = { nofree "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 = { 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 #6 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #7 = { 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 = !{!10, !11, i64 48}
!10 = !{!"stat", !11, i64 0, !11, i64 8, !11, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !13, i64 72, !13, i64 88, !13, i64 104, !7, i64 120}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"timespec", !11, i64 0, !11, i64 8}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass