; LLVM IR from PacktPublishing/Demystifying-Cryptography-with-OpenSSL-3 :: Chapter02 (encrypt-with-extended-error-checking)

; 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.9 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [51 x i8], align 1

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @encrypt(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca i32, align 4
  %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
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca i64, align 8
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  store ptr null, ptr %11, align 8, !tbaa !5
  %22 = call ptr @llvm.stacksave.p0()
  store ptr %22, ptr %12, align 8
  %23 = alloca i8, i64 12, align 16
  %24 = alloca i8, i64 16, align 16
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  store i64 65536, ptr %13, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  store i64 16, ptr %14, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #6
  %25 = call noalias ptr @malloc(i64 noundef 65536) #7
  store ptr %25, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #6
  %26 = call noalias ptr @malloc(i64 noundef 65552) #7
  store ptr %26, ptr %16, align 8, !tbaa !5
  %27 = load ptr, ptr %15, align 8, !tbaa !5
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %32

29:                                               ; preds = %4
  %30 = load ptr, ptr %16, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %39, label %32

32:                                               ; preds = %29, %4
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %38

35:                                               ; preds = %32
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %36, ptr noundef @.str.9) #6
  br label %38

38:                                               ; preds = %35, %32
  br label %183

39:                                               ; preds = %29
  %40 = call i32 @RAND_bytes(ptr noundef %23, i32 noundef 12)
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = call i64 @fwrite(ptr noundef %23, i64 noundef 1, i64 noundef 12, ptr noundef %41)
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = call i32 @ferror(ptr noundef %43) #6
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %53

46:                                               ; preds = %39
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %52

49:                                               ; preds = %46
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %50, ptr noundef @.str.10) #6
  br label %52

52:                                               ; preds = %49, %46
  br label %183

53:                                               ; preds = %39
  %54 = call ptr @EVP_CIPHER_CTX_new()
  store ptr %54, ptr %11, align 8, !tbaa !5
  %55 = load ptr, ptr %11, align 8, !tbaa !5
  %56 = call ptr @EVP_aes_256_gcm()
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = call i32 @EVP_EncryptInit(ptr noundef %55, ptr noundef %56, ptr noundef %57, ptr noundef %23)
  store i32 %58, ptr %17, align 4, !tbaa !9
  %59 = load ptr, ptr %11, align 8, !tbaa !5
  %60 = icmp ne ptr %59, null
  br i1 %60, label %61, label %64

61:                                               ; preds = %53
  %62 = load i32, ptr %17, align 4, !tbaa !9
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %71, label %64

64:                                               ; preds = %61, %53
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = icmp ne ptr %65, null
  br i1 %66, label %67, label %70

67:                                               ; preds = %64
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %68, ptr noundef @.str.11) #6
  br label %70

70:                                               ; preds = %67, %64
  br label %183

71:                                               ; preds = %61
  br label %72

72:                                               ; preds = %127, %71
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = call i32 @feof(ptr noundef %73) #6
  %75 = icmp ne i32 %74, 0
  %76 = xor i1 %75, true
  br i1 %76, label %77, label %128

77:                                               ; preds = %72
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #6
  %78 = load ptr, ptr %15, align 8, !tbaa !5
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = call i64 @fread(ptr noundef %78, i64 noundef 1, i64 noundef 65536, ptr noundef %79)
  store i64 %80, ptr %18, align 8, !tbaa !11
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = call i32 @ferror(ptr noundef %81) #6
  %83 = icmp ne i32 %82, 0
  br i1 %83, label %84, label %91

84:                                               ; preds = %77
  %85 = load ptr, ptr %9, align 8, !tbaa !5
  %86 = icmp ne ptr %85, null
  br i1 %86, label %87, label %90

87:                                               ; preds = %84
  %88 = load ptr, ptr %9, align 8, !tbaa !5
  %89 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %88, ptr noundef @.str.12) #6
  br label %90

90:                                               ; preds = %87, %84
  store i32 2, ptr %20, align 4
  br label %125

91:                                               ; preds = %77
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #6
  store i32 0, ptr %19, align 4, !tbaa !9
  %92 = load ptr, ptr %11, align 8, !tbaa !5
  %93 = load ptr, ptr %16, align 8, !tbaa !5
  %94 = load ptr, ptr %15, align 8, !tbaa !5
  %95 = load i64, ptr %18, align 8, !tbaa !11
  %96 = trunc i64 %95 to i32
  %97 = call i32 @EVP_EncryptUpdate(ptr noundef %92, ptr noundef %93, ptr noundef %19, ptr noundef %94, i32 noundef %96)
  store i32 %97, ptr %17, align 4, !tbaa !9
  %98 = load i32, ptr %17, align 4, !tbaa !9
  %99 = icmp ne i32 %98, 0
  br i1 %99, label %107, label %100

100:                                              ; preds = %91
  %101 = load ptr, ptr %9, align 8, !tbaa !5
  %102 = icmp ne ptr %101, null
  br i1 %102, label %103, label %106

103:                                              ; preds = %100
  %104 = load ptr, ptr %9, align 8, !tbaa !5
  %105 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %104, ptr noundef @.str.13) #6
  br label %106

106:                                              ; preds = %103, %100
  store i32 2, ptr %20, align 4
  br label %124

107:                                              ; preds = %91
  %108 = load ptr, ptr %16, align 8, !tbaa !5
  %109 = load i32, ptr %19, align 4, !tbaa !9
  %110 = sext i32 %109 to i64
  %111 = load ptr, ptr %7, align 8, !tbaa !5
  %112 = call i64 @fwrite(ptr noundef %108, i64 noundef 1, i64 noundef %110, ptr noundef %111)
  %113 = load ptr, ptr %7, align 8, !tbaa !5
  %114 = call i32 @ferror(ptr noundef %113) #6
  %115 = icmp ne i32 %114, 0
  br i1 %115, label %116, label %123

116:                                              ; preds = %107
  %117 = load ptr, ptr %9, align 8, !tbaa !5
  %118 = icmp ne ptr %117, null
  br i1 %118, label %119, label %122

119:                                              ; preds = %116
  %120 = load ptr, ptr %9, align 8, !tbaa !5
  %121 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %120, ptr noundef @.str.14) #6
  br label %122

122:                                              ; preds = %119, %116
  store i32 2, ptr %20, align 4
  br label %124

123:                                              ; preds = %107
  store i32 0, ptr %20, align 4
  br label %124

124:                                              ; preds = %123, %122, %106
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #6
  br label %125

125:                                              ; preds = %124, %90
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #6
  %126 = load i32, ptr %20, align 4
  switch i32 %126, label %189 [
    i32 0, label %127
    i32 2, label %183
  ]

127:                                              ; preds = %125
  br label %72, !llvm.loop !13

128:                                              ; preds = %72
  store i32 0, ptr %21, align 4, !tbaa !9
  %129 = load ptr, ptr %11, align 8, !tbaa !5
  %130 = load ptr, ptr %16, align 8, !tbaa !5
  %131 = call i32 @EVP_EncryptFinal(ptr noundef %129, ptr noundef %130, ptr noundef %21)
  store i32 %131, ptr %17, align 4, !tbaa !9
  %132 = load i32, ptr %17, align 4, !tbaa !9
  %133 = icmp ne i32 %132, 0
  br i1 %133, label %141, label %134

134:                                              ; preds = %128
  %135 = load ptr, ptr %9, align 8, !tbaa !5
  %136 = icmp ne ptr %135, null
  br i1 %136, label %137, label %140

137:                                              ; preds = %134
  %138 = load ptr, ptr %9, align 8, !tbaa !5
  %139 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %138, ptr noundef @.str.15) #6
  br label %140

140:                                              ; preds = %137, %134
  br label %183

141:                                              ; preds = %128
  %142 = load ptr, ptr %16, align 8, !tbaa !5
  %143 = load i32, ptr %21, align 4, !tbaa !9
  %144 = sext i32 %143 to i64
  %145 = load ptr, ptr %7, align 8, !tbaa !5
  %146 = call i64 @fwrite(ptr noundef %142, i64 noundef 1, i64 noundef %144, ptr noundef %145)
  %147 = load ptr, ptr %7, align 8, !tbaa !5
  %148 = call i32 @ferror(ptr noundef %147) #6
  %149 = icmp ne i32 %148, 0
  br i1 %149, label %150, label %157

150:                                              ; preds = %141
  %151 = load ptr, ptr %9, align 8, !tbaa !5
  %152 = icmp ne ptr %151, null
  br i1 %152, label %153, label %156

153:                                              ; preds = %150
  %154 = load ptr, ptr %9, align 8, !tbaa !5
  %155 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %154, ptr noundef @.str.14) #6
  br label %156

156:                                              ; preds = %153, %150
  br label %183

157:                                              ; preds = %141
  %158 = load ptr, ptr %11, align 8, !tbaa !5
  %159 = call i32 @EVP_CIPHER_CTX_ctrl(ptr noundef %158, i32 noundef 16, i32 noundef 16, ptr noundef %24)
  store i32 %159, ptr %17, align 4, !tbaa !9
  %160 = load i32, ptr %17, align 4, !tbaa !9
  %161 = icmp ne i32 %160, 0
  br i1 %161, label %169, label %162

162:                                              ; preds = %157
  %163 = load ptr, ptr %9, align 8, !tbaa !5
  %164 = icmp ne ptr %163, null
  br i1 %164, label %165, label %168

165:                                              ; preds = %162
  %166 = load ptr, ptr %9, align 8, !tbaa !5
  %167 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %166, ptr noundef @.str.16) #6
  br label %168

168:                                              ; preds = %165, %162
  br label %183

169:                                              ; preds = %157
  %170 = load ptr, ptr %7, align 8, !tbaa !5
  %171 = call i64 @fwrite(ptr noundef %24, i64 noundef 1, i64 noundef 16, ptr noundef %170)
  %172 = load ptr, ptr %7, align 8, !tbaa !5
  %173 = call i32 @ferror(ptr noundef %172) #6
  %174 = icmp ne i32 %173, 0
  br i1 %174, label %175, label %182

175:                                              ; preds = %169
  %176 = load ptr, ptr %9, align 8, !tbaa !5
  %177 = icmp ne ptr %176, null
  br i1 %177, label %178, label %181

178:                                              ; preds = %175
  %179 = load ptr, ptr %9, align 8, !tbaa !5
  %180 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %179, ptr noundef @.str.17) #6
  br label %181

181:                                              ; preds = %178, %175
  br label %183

182:                                              ; preds = %169
  br label %184

183:                                              ; preds = %181, %168, %156, %140, %125, %70, %52, %38
  store i32 1, ptr %10, align 4, !tbaa !9
  br label %184

184:                                              ; preds = %183, %182
  %185 = load ptr, ptr %11, align 8, !tbaa !5
  call void @EVP_CIPHER_CTX_free(ptr noundef %185)
  %186 = load ptr, ptr %16, align 8, !tbaa !5
  call void @free(ptr noundef %186) #6
  %187 = load ptr, ptr %15, align 8, !tbaa !5
  call void @free(ptr noundef %187) #6
  %188 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %188, ptr %5, align 4
  store i32 1, ptr %20, align 4
  br label %189

189:                                              ; preds = %184, %125
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  %190 = load ptr, ptr %12, align 8
  call void @llvm.stackrestore.p0(ptr %190)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  %191 = load i32, ptr %5, align 4
  ret i32 %191
}

; 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 ptr @llvm.stacksave.p0() #3

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

declare i32 @RAND_bytes(ptr noundef, i32 noundef) #5

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #5

; Function Attrs: nounwind
declare i32 @ferror(ptr noundef) #1

declare ptr @EVP_CIPHER_CTX_new() #5

declare i32 @EVP_EncryptInit(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #5

declare ptr @EVP_aes_256_gcm() #5

; Function Attrs: nounwind
declare i32 @feof(ptr noundef) #1

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #5

declare i32 @EVP_EncryptUpdate(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) #5

declare i32 @EVP_EncryptFinal(ptr noundef, ptr noundef, ptr noundef) #5

declare i32 @EVP_CIPHER_CTX_ctrl(ptr noundef, i32 noundef, i32 noundef, ptr noundef) #5

declare void @EVP_CIPHER_CTX_free(ptr noundef) #5

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { nocallback nofree nosync nounwind willreturn }
attributes #4 = { 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 #5 = { "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) }

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

@.str.9 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [51 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @encrypt(ptr nocapture noundef %0, ptr nocapture noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca [12 x i8], align 16
  %8 = alloca [16 x i8], align 16
  %9 = tail call noalias dereferenceable_or_null(65536) ptr @malloc(i64 noundef 65536) #7
  %10 = tail call noalias dereferenceable_or_null(65552) ptr @malloc(i64 noundef 65552) #7
  %11 = icmp ne ptr %9, null
  %12 = icmp ne ptr %10, null
  %or.cond = and i1 %11, %12
  br i1 %or.cond, label %16, label %13

13:                                               ; preds = %4
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %.thread, label %14

14:                                               ; preds = %13
  %15 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %3, ptr noundef nonnull @.str.9) #8
  br label %.thread

16:                                               ; preds = %4
  %17 = call i32 @RAND_bytes(ptr noundef nonnull %7, i32 noundef 12) #8
  %18 = call i64 @fwrite(ptr noundef nonnull %7, i64 noundef 1, i64 noundef 12, ptr noundef %1)
  %19 = call i32 @ferror(ptr noundef %1) #8
  %.not67 = icmp eq i32 %19, 0
  br i1 %.not67, label %23, label %20

20:                                               ; preds = %16
  %.not84 = icmp eq ptr %3, null
  br i1 %.not84, label %.thread, label %21

21:                                               ; preds = %20
  %22 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %3, ptr noundef nonnull @.str.10) #8
  br label %.thread

23:                                               ; preds = %16
  %24 = call ptr @EVP_CIPHER_CTX_new() #8
  %25 = call ptr @EVP_aes_256_gcm() #8
  %26 = call i32 @EVP_EncryptInit(ptr noundef %24, ptr noundef %25, ptr noundef %2, ptr noundef nonnull %7) #8
  %27 = icmp ne ptr %24, null
  %28 = icmp ne i32 %26, 0
  %or.cond3 = select i1 %27, i1 %28, i1 false
  br i1 %or.cond3, label %.preheader, label %30

.preheader:                                       ; preds = %23
  %29 = call i32 @feof(ptr noundef %0) #8
  %.not6989 = icmp eq i32 %29, 0
  br i1 %.not6989, label %.lr.ph, label %._crit_edge

30:                                               ; preds = %23
  %.not68 = icmp eq ptr %3, null
  br i1 %.not68, label %.thread, label %31

31:                                               ; preds = %30
  %32 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %3, ptr noundef nonnull @.str.11) #8
  br label %.thread

.lr.ph:                                           ; preds = %.preheader, %49
  %33 = call i64 @fread(ptr noundef nonnull %9, i64 noundef 1, i64 noundef 65536, ptr noundef %0)
  %34 = call i32 @ferror(ptr noundef %0) #8
  %.not78 = icmp eq i32 %34, 0
  br i1 %.not78, label %38, label %35

35:                                               ; preds = %.lr.ph
  %.not83 = icmp eq ptr %3, null
  br i1 %.not83, label %.thread, label %36

36:                                               ; preds = %35
  %37 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %3, ptr noundef nonnull @.str.12) #8
  br label %.thread

38:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #8
  store i32 0, ptr %5, align 4, !tbaa !5
  %39 = trunc i64 %33 to i32
  %40 = call i32 @EVP_EncryptUpdate(ptr noundef nonnull %24, ptr noundef nonnull %10, ptr noundef nonnull %5, ptr noundef nonnull %9, i32 noundef %39) #8
  %.not79 = icmp eq i32 %40, 0
  br i1 %.not79, label %41, label %42

41:                                               ; preds = %38
  %.not80 = icmp eq ptr %3, null
  br i1 %.not80, label %.thread87, label %.thread87.sink.split

42:                                               ; preds = %38
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = call i64 @fwrite(ptr noundef nonnull %10, i64 noundef 1, i64 noundef %44, ptr noundef %1)
  %46 = call i32 @ferror(ptr noundef %1) #8
  %.not81 = icmp eq i32 %46, 0
  br i1 %.not81, label %49, label %47

47:                                               ; preds = %42
  %.not82 = icmp eq ptr %3, null
  br i1 %.not82, label %.thread87, label %.thread87.sink.split

.thread87.sink.split:                             ; preds = %47, %41
  %.str.13.sink = phi ptr [ @.str.13, %41 ], [ @.str.14, %47 ]
  %48 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %3, ptr noundef nonnull %.str.13.sink) #8
  br label %.thread87

.thread87:                                        ; preds = %.thread87.sink.split, %41, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #8
  br label %.thread

49:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #8
  %50 = call i32 @feof(ptr noundef %0) #8
  %.not69 = icmp eq i32 %50, 0
  br i1 %.not69, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %49, %.preheader
  store i32 0, ptr %6, align 4, !tbaa !5
  %51 = call i32 @EVP_EncryptFinal(ptr noundef nonnull %24, ptr noundef nonnull %10, ptr noundef nonnull %6) #8
  %.not70 = icmp eq i32 %51, 0
  br i1 %.not70, label %52, label %55

52:                                               ; preds = %._crit_edge
  %.not71 = icmp eq ptr %3, null
  br i1 %.not71, label %.thread, label %53

53:                                               ; preds = %52
  %54 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %3, ptr noundef nonnull @.str.15) #8
  br label %.thread

55:                                               ; preds = %._crit_edge
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = call i64 @fwrite(ptr noundef nonnull %10, i64 noundef 1, i64 noundef %57, ptr noundef %1)
  %59 = call i32 @ferror(ptr noundef %1) #8
  %.not72 = icmp eq i32 %59, 0
  br i1 %.not72, label %63, label %60

60:                                               ; preds = %55
  %.not77 = icmp eq ptr %3, null
  br i1 %.not77, label %.thread, label %61

61:                                               ; preds = %60
  %62 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %3, ptr noundef nonnull @.str.14) #8
  br label %.thread

63:                                               ; preds = %55
  %64 = call i32 @EVP_CIPHER_CTX_ctrl(ptr noundef nonnull %24, i32 noundef 16, i32 noundef 16, ptr noundef nonnull %8) #8
  %.not73 = icmp eq i32 %64, 0
  br i1 %.not73, label %65, label %68

65:                                               ; preds = %63
  %.not74 = icmp eq ptr %3, null
  br i1 %.not74, label %.thread, label %66

66:                                               ; preds = %65
  %67 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %3, ptr noundef nonnull @.str.16) #8
  br label %.thread

68:                                               ; preds = %63
  %69 = call i64 @fwrite(ptr noundef nonnull %8, i64 noundef 1, i64 noundef 16, ptr noundef %1)
  %70 = call i32 @ferror(ptr noundef %1) #8
  %.not75 = icmp eq i32 %70, 0
  br i1 %.not75, label %.thread, label %71

71:                                               ; preds = %68
  %.not76 = icmp eq ptr %3, null
  br i1 %.not76, label %.thread, label %72

72:                                               ; preds = %71
  %73 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %3, ptr noundef nonnull @.str.17) #8
  br label %.thread

.thread:                                          ; preds = %35, %36, %68, %71, %72, %65, %66, %60, %61, %52, %53, %30, %31, %20, %21, %13, %14, %.thread87
  %.162 = phi ptr [ %24, %68 ], [ null, %21 ], [ null, %20 ], [ %24, %61 ], [ %24, %60 ], [ %24, %72 ], [ %24, %71 ], [ %24, %66 ], [ %24, %65 ], [ %24, %53 ], [ %24, %52 ], [ %24, %31 ], [ %24, %30 ], [ null, %14 ], [ null, %13 ], [ %24, %.thread87 ], [ %24, %36 ], [ %24, %35 ]
  %.060 = phi i32 [ 0, %68 ], [ 1, %21 ], [ 1, %20 ], [ 1, %61 ], [ 1, %60 ], [ 1, %72 ], [ 1, %71 ], [ 1, %66 ], [ 1, %65 ], [ 1, %53 ], [ 1, %52 ], [ 1, %31 ], [ 1, %30 ], [ 1, %14 ], [ 1, %13 ], [ 1, %.thread87 ], [ 1, %36 ], [ 1, %35 ]
  call void @EVP_CIPHER_CTX_free(ptr noundef %.162) #8
  call void @free(ptr noundef %10) #8
  call void @free(ptr noundef %9) #8
  ret i32 %.060
}

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

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

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind memory(read)
declare noundef i32 @ferror(ptr nocapture noundef) local_unnamed_addr #5

declare ptr @EVP_CIPHER_CTX_new() local_unnamed_addr #4

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

declare ptr @EVP_aes_256_gcm() local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @feof(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #1

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

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

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

declare void @EVP_CIPHER_CTX_free(ptr noundef) local_unnamed_addr #4

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { 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 #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 = { nofree nounwind memory(read) "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 = { 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 #7 = { nounwind allocsize(0) }
attributes #8 = { 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"}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass