; LLVM IR from rweather/lightweight-crypto :: test/unit (test-saturnin)

; 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.saturnin_key_schedule_t = type { [16 x i32] }

@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1
@stdout = external global ptr, align 8
@saturnin_test_key = external hidden constant [32 x i8], align 16
@saturnin_test_plaintext = external hidden constant [32 x i8], align 16
@saturnin_test_ciphertext = external hidden constant [32 x i8], align 16
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@test_exit_result = external global i32, align 4
@.str.3 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @test_saturnin() #0 {
  %1 = alloca %struct.saturnin_key_schedule_t, align 4
  %2 = alloca [32 x i8], align 16
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 64, ptr %1) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 1, ptr %3, align 4, !tbaa !5
  %4 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %5 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  %6 = load ptr, ptr @stdout, align 8, !tbaa !9
  %7 = call i32 @fflush(ptr noundef %6)
  call void @saturnin_setup_key(ptr noundef %1, ptr noundef @saturnin_test_key)
  %8 = getelementptr inbounds [32 x i8], ptr %2, i64 0, i64 0
  call void @saturnin_encrypt_block(ptr noundef %1, ptr noundef %8, ptr noundef @saturnin_test_plaintext, i32 noundef 20)
  %9 = getelementptr inbounds [32 x i8], ptr %2, i64 0, i64 0
  %10 = call i32 @memcmp(ptr noundef %9, ptr noundef @saturnin_test_ciphertext, i64 noundef 32) #5
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %14

12:                                               ; preds = %0
  %13 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  store i32 1, ptr @test_exit_result, align 4, !tbaa !5
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %12, %0
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %25

17:                                               ; preds = %14
  %18 = getelementptr inbounds [32 x i8], ptr %2, i64 0, i64 0
  call void @saturnin_decrypt_block(ptr noundef %1, ptr noundef %18, ptr noundef @saturnin_test_ciphertext, i32 noundef 20)
  %19 = getelementptr inbounds [32 x i8], ptr %2, i64 0, i64 0
  %20 = call i32 @memcmp(ptr noundef %19, ptr noundef @saturnin_test_plaintext, i64 noundef 32) #5
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %17
  %23 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store i32 1, ptr @test_exit_result, align 4, !tbaa !5
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %22, %17
  br label %25

25:                                               ; preds = %24, %14
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %30

28:                                               ; preds = %25
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  br label %30

30:                                               ; preds = %28, %25
  %31 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr %1) #4
  ret void
}

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

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

declare i32 @fflush(ptr noundef) #2

declare void @saturnin_setup_key(ptr noundef, ptr noundef) #2

declare void @saturnin_encrypt_block(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #3

declare void @saturnin_decrypt_block(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #2

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

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 = { "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 willreturn 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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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}


; 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.saturnin_key_schedule_t = type { [16 x i32] }

@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@saturnin_test_key = external hidden constant [32 x i8], align 16
@saturnin_test_plaintext = external hidden constant [32 x i8], align 16
@saturnin_test_ciphertext = external hidden constant [32 x i8], align 16
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@test_exit_result = external local_unnamed_addr global i32, align 4
@.str.3 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @test_saturnin() local_unnamed_addr #0 {
  %1 = alloca %struct.saturnin_key_schedule_t, align 4
  %2 = alloca [32 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #5
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  %5 = load ptr, ptr @stdout, align 8, !tbaa !5
  %6 = tail call i32 @fflush(ptr noundef %5)
  call void @saturnin_setup_key(ptr noundef nonnull %1, ptr noundef nonnull @saturnin_test_key) #5
  call void @saturnin_encrypt_block(ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull @saturnin_test_plaintext, i32 noundef 20) #5
  %bcmp = call i32 @bcmp(ptr noundef nonnull dereferenceable(32) %2, ptr noundef nonnull dereferenceable(32) @saturnin_test_ciphertext, i64 32)
  %.not.not = icmp eq i32 %bcmp, 0
  br i1 %.not.not, label %.critedge, label %7

7:                                                ; preds = %0
  %8 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  store i32 1, ptr @test_exit_result, align 4, !tbaa !9
  br label %.critedge6

.critedge:                                        ; preds = %0
  call void @saturnin_decrypt_block(ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull @saturnin_test_ciphertext, i32 noundef 20) #5
  %bcmp3 = call i32 @bcmp(ptr noundef nonnull dereferenceable(32) %2, ptr noundef nonnull dereferenceable(32) @saturnin_test_plaintext, i64 32)
  %.not = icmp eq i32 %bcmp3, 0
  br i1 %.not, label %11, label %9

9:                                                ; preds = %.critedge
  %10 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  store i32 1, ptr @test_exit_result, align 4, !tbaa !9
  br label %.critedge6

11:                                               ; preds = %.critedge
  %12 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  br label %.critedge6

.critedge6:                                       ; preds = %7, %9, %11
  %13 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %1) #5
  ret void
}

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

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

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

declare void @saturnin_setup_key(ptr noundef, ptr noundef) local_unnamed_addr #3

declare void @saturnin_encrypt_block(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

declare void @saturnin_decrypt_block(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

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

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #4

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = { nofree nounwind willreturn memory(argmem: read) }
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 = !{!"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}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass