; LLVM IR from tsotchke/quantum_rng :: examples/crypto (key_derivation_utils)

; 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.kdf_config_t = type { i32, i32, i16, i8, i8, [1024 x i8], [256 x i8], i32, i32, i32, [1024 x i8], i32 }
%struct.kdf_result_t = type { ptr, [16 x i8], double, i64, i64 }

@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [18 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @print_results(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %11

8:                                                ; preds = %2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %12, label %11

11:                                               ; preds = %8, %2
  br label %76

12:                                               ; preds = %8
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.kdf_config_t, ptr %13, i32 0, i32 8
  %15 = load i32, ptr %14, align 4, !tbaa !9
  switch i32 %15, label %76 [
    i32 1, label %16
    i32 3, label %39
    i32 4, label %42
    i32 2, label %45
    i32 0, label %45
  ]

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 0, ptr %5, align 8, !tbaa !13
  br label %17

17:                                               ; preds = %34, %16
  %18 = load i64, ptr %5, align 8, !tbaa !13
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.kdf_config_t, ptr %19, i32 0, i32 2
  %21 = load i16, ptr %20, align 4, !tbaa !15
  %22 = zext i16 %21 to i64
  %23 = icmp ult i64 %18, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %37

25:                                               ; preds = %17
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.kdf_result_t, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !16
  %29 = load i64, ptr %5, align 8, !tbaa !13
  %30 = getelementptr inbounds i8, ptr %28, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !19
  %32 = zext i8 %31 to i32
  %33 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %32)
  br label %34

34:                                               ; preds = %25
  %35 = load i64, ptr %5, align 8, !tbaa !13
  %36 = add i64 %35, 1
  store i64 %36, ptr %5, align 8, !tbaa !13
  br label %17, !llvm.loop !20

37:                                               ; preds = %24
  %38 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %76

39:                                               ; preds = %12
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  call void @output_results_json(ptr noundef %40, ptr noundef %41)
  br label %76

42:                                               ; preds = %12
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  call void @output_results_hex(ptr noundef %43, ptr noundef %44)
  br label %76

45:                                               ; preds = %12, %12
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.kdf_result_t, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !16
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.kdf_config_t, ptr %51, i32 0, i32 2
  %53 = load i16, ptr %52, align 4, !tbaa !15
  %54 = zext i16 %53 to i64
  call void @print_hex(ptr noundef @.str.5, ptr noundef %50, i64 noundef %54)
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.kdf_result_t, ptr %55, i32 0, i32 1
  %57 = getelementptr inbounds [16 x i8], ptr %56, i64 0, i64 0
  call void @print_hex(ptr noundef @.str.6, ptr noundef %57, i64 noundef 16)
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.kdf_result_t, ptr %58, i32 0, i32 2
  %60 = load double, ptr %59, align 8, !tbaa !22
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, double noundef %60)
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.kdf_result_t, ptr %62, i32 0, i32 3
  %64 = load i64, ptr %63, align 8, !tbaa !23
  %65 = udiv i64 %64, 1048576
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, i64 noundef %65)
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.kdf_result_t, ptr %67, i32 0, i32 4
  %69 = load i64, ptr %68, align 8, !tbaa !24
  %70 = call i32 (ptr, ...) @printf(ptr noundef @.str.9, i64 noundef %69)
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.kdf_config_t, ptr %71, i32 0, i32 4
  %73 = load i8, ptr %72, align 1, !tbaa !25
  %74 = zext i8 %73 to i32
  %75 = call i32 (ptr, ...) @printf(ptr noundef @.str.10, i32 noundef %74)
  br label %76

76:                                               ; preds = %45, %42, %39, %37, %12, %11
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @output_results_json(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @output_results_hex(ptr noundef, ptr noundef) #1

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 = { 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 1296}
!10 = !{!"", !11, i64 0, !11, i64 4, !12, i64 8, !7, i64 10, !7, i64 11, !7, i64 12, !7, i64 1036, !11, i64 1292, !11, i64 1296, !11, i64 1300, !7, i64 1304, !11, i64 2328}
!11 = !{!"int", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!10, !12, i64 8}
!16 = !{!17, !6, i64 0}
!17 = !{!"", !6, i64 0, !7, i64 8, !18, i64 24, !14, i64 32, !14, i64 40}
!18 = !{!"double", !7, i64 0}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!17, !18, i64 24}
!23 = !{!17, !14, i64 32}
!24 = !{!17, !14, i64 40}
!25 = !{!10, !7, i64 11}


; 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 [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [18 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @print_results(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp ne ptr %0, null
  %4 = icmp ne ptr %1, null
  %or.cond = and i1 %3, %4
  br i1 %or.cond, label %5, label %44

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 1296
  %7 = load i32, ptr %6, align 4, !tbaa !5
  switch i32 %7, label %44 [
    i32 1, label %.preheader
    i32 3, label %20
    i32 4, label %21
    i32 2, label %22
    i32 0, label %22
  ]

.preheader:                                       ; preds = %5
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = load i16, ptr %8, align 4, !tbaa !11
  %.not = icmp eq i16 %9, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %44

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.021 = phi i64 [ %16, %.lr.ph ], [ 0, %.preheader ]
  %11 = load ptr, ptr %0, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %11, i64 %.021
  %13 = load i8, ptr %12, align 1, !tbaa !17
  %14 = zext i8 %13 to i32
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %14)
  %16 = add nuw nsw i64 %.021, 1
  %17 = load i16, ptr %8, align 4, !tbaa !11
  %18 = zext i16 %17 to i64
  %19 = icmp ult i64 %16, %18
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !18

20:                                               ; preds = %5
  tail call void @output_results_json(ptr noundef nonnull %0, ptr noundef nonnull %1)
  br label %44

21:                                               ; preds = %5
  tail call void @output_results_hex(ptr noundef nonnull %0, ptr noundef nonnull %1)
  br label %44

22:                                               ; preds = %5, %5
  %23 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %25 = load ptr, ptr %0, align 8, !tbaa !12
  %26 = getelementptr inbounds i8, ptr %1, i64 8
  %27 = load i16, ptr %26, align 4, !tbaa !11
  %28 = zext i16 %27 to i64
  tail call void @print_hex(ptr noundef nonnull @.str.5, ptr noundef %25, i64 noundef %28)
  %29 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @print_hex(ptr noundef nonnull @.str.6, ptr noundef nonnull %29, i64 noundef 16)
  %30 = getelementptr inbounds i8, ptr %0, i64 24
  %31 = load double, ptr %30, align 8, !tbaa !20
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, double noundef %31)
  %33 = getelementptr inbounds i8, ptr %0, i64 32
  %34 = load i64, ptr %33, align 8, !tbaa !21
  %35 = lshr i64 %34, 20
  %36 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, i64 noundef %35)
  %37 = getelementptr inbounds i8, ptr %0, i64 40
  %38 = load i64, ptr %37, align 8, !tbaa !22
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9, i64 noundef %38)
  %40 = getelementptr inbounds i8, ptr %1, i64 11
  %41 = load i8, ptr %40, align 1, !tbaa !23
  %42 = zext i8 %41 to i32
  %43 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10, i32 noundef %42)
  br label %44

44:                                               ; preds = %2, %22, %21, %20, %._crit_edge, %5
  ret void
}

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

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

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 = { 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" }

!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 1296}
!6 = !{!"", !7, i64 0, !7, i64 4, !10, i64 8, !8, i64 10, !8, i64 11, !8, i64 12, !8, i64 1036, !7, i64 1292, !7, i64 1296, !7, i64 1300, !8, i64 1304, !7, i64 2328}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!13, !14, i64 0}
!13 = !{!"", !14, i64 0, !8, i64 8, !15, i64 24, !16, i64 32, !16, i64 40}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!"double", !8, i64 0}
!16 = !{!"long", !8, i64 0}
!17 = !{!8, !8, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!13, !15, i64 24}
!21 = !{!13, !16, i64 32}
!22 = !{!13, !16, i64 40}
!23 = !{!6, !8, i64 11}


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