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

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

@memory_buffer = external hidden global [128 x i8], align 16
@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @derive_key(ptr dead_on_unwind noalias writable sret(%struct.kdf_result_t) align 8 %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca %struct.timespec, align 8
  %5 = alloca %struct.timespec, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca [32 x i8], align 16
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  store ptr %1, ptr %3, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %0, i8 0, i64 48, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #8
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #8
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %2
  store i32 1, ptr %6, align 4
  br label %205

17:                                               ; preds = %2
  %18 = call i32 @clock_gettime(i32 noundef 1, ptr noundef %4) #8
  %19 = load ptr, ptr %3, 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 !9
  %22 = zext i16 %21 to i64
  %23 = call noalias ptr @malloc(i64 noundef %22) #9
  %24 = getelementptr inbounds %struct.kdf_result_t, ptr %0, i32 0, i32 0
  store ptr %23, ptr %24, align 8, !tbaa !13
  %25 = getelementptr inbounds %struct.kdf_result_t, ptr %0, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = icmp ne ptr %26, null
  br i1 %27, label %29, label %28

28:                                               ; preds = %17
  store i32 1, ptr %6, align 4
  br label %205

29:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #8
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %8) #8
  call void @llvm.memset.p0.i64(ptr align 16 %8, i8 0, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #8
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.kdf_config_t, ptr %30, i32 0, i32 5
  %32 = getelementptr inbounds [1024 x i8], ptr %31, i64 0, i64 0
  %33 = call i64 @strlen(ptr noundef %32) #10
  store i64 %33, ptr %9, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #8
  store i64 0, ptr %10, align 8, !tbaa !17
  br label %34

34:                                               ; preds = %68, %29
  %35 = load i64, ptr %10, align 8, !tbaa !17
  %36 = icmp ult i64 %35, 32
  br i1 %36, label %38, label %37

37:                                               ; preds = %34
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #8
  br label %71

38:                                               ; preds = %34
  %39 = load i64, ptr %10, align 8, !tbaa !17
  %40 = load i64, ptr %9, align 8, !tbaa !17
  %41 = icmp ult i64 %39, %40
  br i1 %41, label %42, label %49

42:                                               ; preds = %38
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.kdf_config_t, ptr %43, i32 0, i32 5
  %45 = load i64, ptr %10, align 8, !tbaa !17
  %46 = getelementptr inbounds [1024 x i8], ptr %44, i64 0, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !18
  %48 = sext i8 %47 to i32
  br label %50

49:                                               ; preds = %38
  br label %50

50:                                               ; preds = %49, %42
  %51 = phi i32 [ %48, %42 ], [ 0, %49 ]
  %52 = load i64, ptr %10, align 8, !tbaa !17
  %53 = icmp ult i64 %52, 16
  br i1 %53, label %54, label %61

54:                                               ; preds = %50
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.kdf_config_t, ptr %55, i32 0, i32 6
  %57 = load i64, ptr %10, align 8, !tbaa !17
  %58 = getelementptr inbounds [256 x i8], ptr %56, i64 0, i64 %57
  %59 = load i8, ptr %58, align 1, !tbaa !18
  %60 = sext i8 %59 to i32
  br label %62

61:                                               ; preds = %50
  br label %62

62:                                               ; preds = %61, %54
  %63 = phi i32 [ %60, %54 ], [ 0, %61 ]
  %64 = xor i32 %51, %63
  %65 = trunc i32 %64 to i8
  %66 = load i64, ptr %10, align 8, !tbaa !17
  %67 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 %66
  store i8 %65, ptr %67, align 1, !tbaa !18
  br label %68

68:                                               ; preds = %62
  %69 = load i64, ptr %10, align 8, !tbaa !17
  %70 = add i64 %69, 1
  store i64 %70, ptr %10, align 8, !tbaa !17
  br label %34, !llvm.loop !19

71:                                               ; preds = %37
  %72 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 0
  %73 = call i32 @qrng_init(ptr noundef %7, ptr noundef %72, i64 noundef 32)
  %74 = icmp ne i32 %73, 0
  br i1 %74, label %75, label %79

75:                                               ; preds = %71
  %76 = getelementptr inbounds %struct.kdf_result_t, ptr %0, i32 0, i32 0
  %77 = load ptr, ptr %76, align 8, !tbaa !13
  call void @free(ptr noundef %77) #8
  %78 = getelementptr inbounds %struct.kdf_result_t, ptr %0, i32 0, i32 0
  store ptr null, ptr %78, align 8, !tbaa !13
  store i32 1, ptr %6, align 4
  br label %204

79:                                               ; preds = %71
  %80 = getelementptr inbounds %struct.kdf_result_t, ptr %0, i32 0, i32 1
  %81 = getelementptr inbounds [16 x i8], ptr %80, i64 0, i64 0
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.kdf_config_t, ptr %82, i32 0, i32 6
  %84 = getelementptr inbounds [256 x i8], ptr %83, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %81, ptr align 4 %84, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #8
  store i32 0, ptr %11, align 4, !tbaa !21
  br label %85

85:                                               ; preds = %150, %79
  %86 = load i32, ptr %11, align 4, !tbaa !21
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.kdf_config_t, ptr %87, i32 0, i32 0
  %89 = load i32, ptr %88, align 4, !tbaa !22
  %90 = icmp ult i32 %86, %89
  br i1 %90, label %92, label %91

91:                                               ; preds = %85
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #8
  br label %153

92:                                               ; preds = %85
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #8
  store i64 0, ptr %12, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #8
  %93 = load ptr, ptr %3, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.kdf_config_t, ptr %93, i32 0, i32 5
  %95 = getelementptr inbounds [1024 x i8], ptr %94, i64 0, i64 0
  %96 = call i64 @strlen(ptr noundef %95) #10
  store i64 %96, ptr %13, align 8, !tbaa !17
  %97 = load i64, ptr %13, align 8, !tbaa !17
  %98 = icmp uge i64 %97, 128
  br i1 %98, label %99, label %100

99:                                               ; preds = %92
  store i64 127, ptr %13, align 8, !tbaa !17
  br label %100

100:                                              ; preds = %99, %92
  %101 = load i64, ptr %12, align 8, !tbaa !17
  %102 = getelementptr inbounds i8, ptr @memory_buffer, i64 %101
  %103 = load ptr, ptr %3, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.kdf_config_t, ptr %103, i32 0, i32 5
  %105 = getelementptr inbounds [1024 x i8], ptr %104, i64 0, i64 0
  %106 = load i64, ptr %13, align 8, !tbaa !17
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %102, ptr align 4 %105, i64 %106, i1 false)
  %107 = load i64, ptr %13, align 8, !tbaa !17
  %108 = load i64, ptr %12, align 8, !tbaa !17
  %109 = add i64 %108, %107
  store i64 %109, ptr %12, align 8, !tbaa !17
  %110 = load i64, ptr %12, align 8, !tbaa !17
  %111 = getelementptr inbounds i8, ptr @memory_buffer, i64 %110
  %112 = getelementptr inbounds %struct.kdf_result_t, ptr %0, i32 0, i32 1
  %113 = getelementptr inbounds [16 x i8], ptr %112, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %111, ptr align 8 %113, i64 16, i1 false)
  %114 = load i64, ptr %12, align 8, !tbaa !17
  %115 = add i64 %114, 16
  store i64 %115, ptr %12, align 8, !tbaa !17
  %116 = load i64, ptr %12, align 8, !tbaa !17
  %117 = getelementptr inbounds i8, ptr @memory_buffer, i64 %116
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %117, ptr align 4 %11, i64 4, i1 false)
  %118 = load i64, ptr %12, align 8, !tbaa !17
  %119 = add i64 %118, 4
  store i64 %119, ptr %12, align 8, !tbaa !17
  %120 = load i64, ptr %12, align 8, !tbaa !17
  %121 = load ptr, ptr %7, align 8, !tbaa !5
  %122 = load ptr, ptr %3, align 8, !tbaa !5
  %123 = getelementptr inbounds %struct.kdf_config_t, ptr %122, i32 0, i32 3
  %124 = load i8, ptr %123, align 2, !tbaa !23
  %125 = zext i8 %124 to i32
  call void @quantum_mix(ptr noundef @memory_buffer, i64 noundef %120, ptr noundef %121, i32 noundef %125)
  %126 = load ptr, ptr %3, align 8, !tbaa !5
  %127 = getelementptr inbounds %struct.kdf_config_t, ptr %126, i32 0, i32 9
  %128 = load i32, ptr %127, align 4, !tbaa !24
  %129 = icmp ne i32 %128, 0
  br i1 %129, label %130, label %149

130:                                              ; preds = %100
  %131 = load i32, ptr %11, align 4, !tbaa !21
  %132 = load ptr, ptr %3, align 8, !tbaa !5
  %133 = getelementptr inbounds %struct.kdf_config_t, ptr %132, i32 0, i32 0
  %134 = load i32, ptr %133, align 4, !tbaa !22
  %135 = udiv i32 %134, 100
  %136 = urem i32 %131, %135
  %137 = icmp eq i32 %136, 0
  br i1 %137, label %138, label %149

138:                                              ; preds = %130
  %139 = load ptr, ptr @stderr, align 8, !tbaa !5
  %140 = load i32, ptr %11, align 4, !tbaa !21
  %141 = load ptr, ptr %3, align 8, !tbaa !5
  %142 = getelementptr inbounds %struct.kdf_config_t, ptr %141, i32 0, i32 0
  %143 = load i32, ptr %142, align 4, !tbaa !22
  %144 = udiv i32 %143, 100
  %145 = udiv i32 %140, %144
  %146 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %139, ptr noundef @.str, i32 noundef %145) #8
  %147 = load ptr, ptr @stderr, align 8, !tbaa !5
  %148 = call i32 @fflush(ptr noundef %147)
  br label %149

149:                                              ; preds = %138, %130, %100
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #8
  br label %150

150:                                              ; preds = %149
  %151 = load i32, ptr %11, align 4, !tbaa !21
  %152 = add i32 %151, 1
  store i32 %152, ptr %11, align 4, !tbaa !21
  br label %85, !llvm.loop !25

153:                                              ; preds = %91
  %154 = load ptr, ptr %3, align 8, !tbaa !5
  %155 = getelementptr inbounds %struct.kdf_config_t, ptr %154, i32 0, i32 9
  %156 = load i32, ptr %155, align 4, !tbaa !24
  %157 = icmp ne i32 %156, 0
  br i1 %157, label %158, label %161

158:                                              ; preds = %153
  %159 = load ptr, ptr @stderr, align 8, !tbaa !5
  %160 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %159, ptr noundef @.str.1) #8
  br label %161

161:                                              ; preds = %158, %153
  %162 = getelementptr inbounds %struct.kdf_result_t, ptr %0, i32 0, i32 0
  %163 = load ptr, ptr %162, align 8, !tbaa !13
  %164 = load ptr, ptr %3, align 8, !tbaa !5
  %165 = getelementptr inbounds %struct.kdf_config_t, ptr %164, i32 0, i32 2
  %166 = load i16, ptr %165, align 4, !tbaa !9
  %167 = zext i16 %166 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %163, ptr align 16 @memory_buffer, i64 %167, i1 false)
  %168 = getelementptr inbounds %struct.kdf_result_t, ptr %0, i32 0, i32 0
  %169 = load ptr, ptr %168, align 8, !tbaa !13
  %170 = load ptr, ptr %3, align 8, !tbaa !5
  %171 = getelementptr inbounds %struct.kdf_config_t, ptr %170, i32 0, i32 2
  %172 = load i16, ptr %171, align 4, !tbaa !9
  %173 = zext i16 %172 to i64
  %174 = load ptr, ptr %7, align 8, !tbaa !5
  %175 = load ptr, ptr %3, align 8, !tbaa !5
  %176 = getelementptr inbounds %struct.kdf_config_t, ptr %175, i32 0, i32 3
  %177 = load i8, ptr %176, align 2, !tbaa !23
  %178 = zext i8 %177 to i32
  call void @quantum_mix(ptr noundef %169, i64 noundef %173, ptr noundef %174, i32 noundef %178)
  %179 = getelementptr inbounds %struct.kdf_result_t, ptr %0, i32 0, i32 0
  %180 = load ptr, ptr %179, align 8, !tbaa !13
  %181 = load ptr, ptr %3, align 8, !tbaa !5
  %182 = getelementptr inbounds %struct.kdf_config_t, ptr %181, i32 0, i32 2
  %183 = load i16, ptr %182, align 4, !tbaa !9
  %184 = zext i16 %183 to i64
  %185 = call double @estimate_entropy(ptr noundef %180, i64 noundef %184)
  %186 = getelementptr inbounds %struct.kdf_result_t, ptr %0, i32 0, i32 2
  store double %185, ptr %186, align 8, !tbaa !26
  %187 = call i32 @clock_gettime(i32 noundef 1, ptr noundef %5) #8
  %188 = getelementptr inbounds %struct.kdf_result_t, ptr %0, i32 0, i32 3
  store i64 128, ptr %188, align 8, !tbaa !27
  %189 = getelementptr inbounds %struct.timespec, ptr %5, i32 0, i32 0
  %190 = load i64, ptr %189, align 8, !tbaa !28
  %191 = getelementptr inbounds %struct.timespec, ptr %4, i32 0, i32 0
  %192 = load i64, ptr %191, align 8, !tbaa !28
  %193 = sub nsw i64 %190, %192
  %194 = mul nsw i64 %193, 1000
  %195 = getelementptr inbounds %struct.timespec, ptr %5, i32 0, i32 1
  %196 = load i64, ptr %195, align 8, !tbaa !30
  %197 = getelementptr inbounds %struct.timespec, ptr %4, i32 0, i32 1
  %198 = load i64, ptr %197, align 8, !tbaa !30
  %199 = sub nsw i64 %196, %198
  %200 = sdiv i64 %199, 1000000
  %201 = add nsw i64 %194, %200
  %202 = getelementptr inbounds %struct.kdf_result_t, ptr %0, i32 0, i32 4
  store i64 %201, ptr %202, align 8, !tbaa !31
  %203 = load ptr, ptr %7, align 8, !tbaa !5
  call void @qrng_free(ptr noundef %203)
  store i32 1, ptr %6, align 4
  br label %204

204:                                              ; preds = %161, %75
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #8
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #8
  br label %205

205:                                              ; preds = %204, %28, %16
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #8
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #8
  ret void
}

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

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

; Function Attrs: nounwind
declare i32 @clock_gettime(i32 noundef, ptr noundef) #3

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #5

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

declare i32 @qrng_init(ptr noundef, ptr noundef, i64 noundef) #6

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

; 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) #7

; Function Attrs: nounwind uwtable
declare hidden void @quantum_mix(ptr noundef, i64 noundef, ptr noundef, i32 noundef) #0

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

declare i32 @fflush(ptr noundef) #6

declare double @estimate_entropy(ptr noundef, i64 noundef) #6

declare void @qrng_free(ptr noundef) #6

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 nounwind willreturn memory(argmem: write) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = { 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 = { 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 #6 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #8 = { nounwind }
attributes #9 = { nounwind allocsize(0) }
attributes #10 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 8}
!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, !6, i64 0}
!14 = !{!"", !6, i64 0, !7, i64 8, !15, i64 24, !16, i64 32, !16, i64 40}
!15 = !{!"double", !7, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!16, !16, i64 0}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!11, !11, i64 0}
!22 = !{!10, !11, i64 0}
!23 = !{!10, !7, i64 10}
!24 = !{!10, !11, i64 1300}
!25 = distinct !{!25, !20}
!26 = !{!14, !15, i64 24}
!27 = !{!14, !16, i64 32}
!28 = !{!29, !16, i64 0}
!29 = !{!"timespec", !16, i64 0, !16, i64 8}
!30 = !{!29, !16, i64 8}
!31 = !{!14, !16, i64 40}


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

@memory_buffer = external hidden global [128 x i8], align 16
@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @derive_key(ptr dead_on_unwind noalias nocapture writable sret(%struct.kdf_result_t) align 8 %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca %struct.timespec, align 8
  %4 = alloca %struct.timespec, align 8
  %5 = alloca ptr, align 8
  %6 = alloca [32 x i8], align 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) %0, i8 0, i64 48, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #11
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #11
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %111, label %7

7:                                                ; preds = %2
  %8 = call i32 @clock_gettime(i32 noundef 1, ptr noundef nonnull %3) #11
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load i16, ptr %9, align 4, !tbaa !5
  %11 = zext i16 %10 to i64
  %12 = call noalias ptr @malloc(i64 noundef %11) #12
  store ptr %12, ptr %0, align 8, !tbaa !11
  %.not41 = icmp eq ptr %12, null
  br i1 %.not41, label %111, label %13

13:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #11
  store ptr null, ptr %5, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %6) #11
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %6, i8 0, i64 32, i1 false)
  %14 = getelementptr inbounds i8, ptr %1, i64 12
  %15 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %14) #13
  %16 = getelementptr inbounds i8, ptr %1, i64 1036
  br label %19

17:                                               ; preds = %45
  %18 = call i32 @qrng_init(ptr noundef nonnull %5, ptr noundef nonnull %6, i64 noundef 32) #11
  %.not42 = icmp eq i32 %18, 0
  br i1 %.not42, label %51, label %50

19:                                               ; preds = %45, %13
  %.045 = phi i64 [ 0, %13 ], [ %49, %45 ]
  %20 = icmp ult i64 %.045, %15
  br i1 %20, label %21, label %24

21:                                               ; preds = %19
  %22 = getelementptr inbounds [1024 x i8], ptr %14, i64 0, i64 %.045
  %23 = load i8, ptr %22, align 1, !tbaa !17
  br label %24

24:                                               ; preds = %19, %21
  %25 = phi i8 [ %23, %21 ], [ 0, %19 ]
  %26 = icmp ult i64 %.045, 16
  br i1 %26, label %27, label %30

27:                                               ; preds = %24
  %28 = getelementptr inbounds [256 x i8], ptr %16, i64 0, i64 %.045
  %29 = load i8, ptr %28, align 1, !tbaa !17
  br label %30

30:                                               ; preds = %24, %27
  %31 = phi i8 [ %29, %27 ], [ 0, %24 ]
  %32 = xor i8 %31, %25
  %33 = getelementptr inbounds [32 x i8], ptr %6, i64 0, i64 %.045
  store i8 %32, ptr %33, align 2, !tbaa !17
  %34 = or disjoint i64 %.045, 1
  %35 = icmp ult i64 %34, %15
  br i1 %35, label %36, label %39

36:                                               ; preds = %30
  %37 = getelementptr inbounds [1024 x i8], ptr %14, i64 0, i64 %34
  %38 = load i8, ptr %37, align 1, !tbaa !17
  br label %39

39:                                               ; preds = %36, %30
  %40 = phi i8 [ %38, %36 ], [ 0, %30 ]
  %41 = icmp ult i64 %.045, 16
  br i1 %41, label %42, label %45

42:                                               ; preds = %39
  %43 = getelementptr inbounds [256 x i8], ptr %16, i64 0, i64 %34
  %44 = load i8, ptr %43, align 1, !tbaa !17
  br label %45

45:                                               ; preds = %42, %39
  %46 = phi i8 [ %44, %42 ], [ 0, %39 ]
  %47 = xor i8 %46, %40
  %48 = getelementptr inbounds [32 x i8], ptr %6, i64 0, i64 %34
  store i8 %47, ptr %48, align 1, !tbaa !17
  %49 = add nuw nsw i64 %.045, 2
  %exitcond.not.1 = icmp eq i64 %49, 32
  br i1 %exitcond.not.1, label %17, label %19, !llvm.loop !18

50:                                               ; preds = %17
  call void @free(ptr noundef %12) #11
  store ptr null, ptr %0, align 8, !tbaa !11
  br label %110

51:                                               ; preds = %17
  %52 = getelementptr inbounds i8, ptr %0, i64 8
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %52, ptr noundef nonnull align 4 dereferenceable(16) %16, i64 16, i1 false)
  %53 = load i32, ptr %1, align 4, !tbaa !20
  %.not47 = icmp eq i32 %53, 0
  br i1 %.not47, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %51
  %54 = getelementptr inbounds i8, ptr %1, i64 10
  %55 = getelementptr inbounds i8, ptr %1, i64 1300
  br label %58

._crit_edge:                                      ; preds = %77, %51
  %56 = getelementptr inbounds i8, ptr %1, i64 1300
  %57 = load i32, ptr %56, align 4, !tbaa !21
  %.not43 = icmp eq i32 %57, 0
  br i1 %.not43, label %84, label %81

58:                                               ; preds = %.lr.ph, %77
  %.03946 = phi i32 [ 0, %.lr.ph ], [ %79, %77 ]
  %59 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %14) #13
  %spec.store.select = call i64 @llvm.umin.i64(i64 %59, i64 127)
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 @memory_buffer, ptr nonnull align 4 %14, i64 %spec.store.select, i1 false)
  %60 = getelementptr inbounds i8, ptr @memory_buffer, i64 %spec.store.select
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(16) %60, ptr noundef nonnull align 8 dereferenceable(16) %52, i64 16, i1 false)
  %61 = getelementptr inbounds i8, ptr %60, i64 16
  store i32 %.03946, ptr %61, align 1
  %62 = add nuw nsw i64 %spec.store.select, 20
  %63 = load ptr, ptr %5, align 8, !tbaa !16
  %64 = load i8, ptr %54, align 2, !tbaa !22
  %65 = zext i8 %64 to i32
  call void @quantum_mix(ptr noundef nonnull @memory_buffer, i64 noundef %62, ptr noundef %63, i32 noundef %65)
  %66 = load i32, ptr %55, align 4, !tbaa !21
  %.not44 = icmp eq i32 %66, 0
  %.pre48 = load i32, ptr %1, align 4, !tbaa !20
  br i1 %.not44, label %77, label %67

67:                                               ; preds = %58
  %68 = udiv i32 %.pre48, 100
  %69 = urem i32 %.03946, %68
  %70 = udiv i32 %.03946, %68
  %71 = icmp eq i32 %69, 0
  br i1 %71, label %72, label %77

72:                                               ; preds = %67
  %73 = load ptr, ptr @stderr, align 8, !tbaa !16
  %74 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %73, ptr noundef nonnull @.str, i32 noundef %70) #14
  %75 = load ptr, ptr @stderr, align 8, !tbaa !16
  %76 = call i32 @fflush(ptr noundef %75)
  %.pre = load i32, ptr %1, align 4, !tbaa !20
  br label %77

77:                                               ; preds = %72, %67, %58
  %78 = phi i32 [ %.pre, %72 ], [ %.pre48, %67 ], [ %.pre48, %58 ]
  %79 = add nuw i32 %.03946, 1
  %80 = icmp ult i32 %79, %78
  br i1 %80, label %58, label %._crit_edge, !llvm.loop !23

81:                                               ; preds = %._crit_edge
  %82 = load ptr, ptr @stderr, align 8, !tbaa !16
  %83 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %82, ptr noundef nonnull @.str.1) #14
  br label %84

84:                                               ; preds = %81, %._crit_edge
  %85 = load i16, ptr %9, align 4, !tbaa !5
  %86 = zext i16 %85 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %12, ptr nonnull align 16 @memory_buffer, i64 %86, i1 false)
  %87 = load ptr, ptr %5, align 8, !tbaa !16
  %88 = getelementptr inbounds i8, ptr %1, i64 10
  %89 = load i8, ptr %88, align 2, !tbaa !22
  %90 = zext i8 %89 to i32
  call void @quantum_mix(ptr noundef nonnull %12, i64 noundef %86, ptr noundef %87, i32 noundef %90)
  %91 = load i16, ptr %9, align 4, !tbaa !5
  %92 = zext i16 %91 to i64
  %93 = call double @estimate_entropy(ptr noundef nonnull %12, i64 noundef %92) #11
  %94 = getelementptr inbounds i8, ptr %0, i64 24
  store double %93, ptr %94, align 8, !tbaa !24
  %95 = call i32 @clock_gettime(i32 noundef 1, ptr noundef nonnull %4) #11
  %96 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 128, ptr %96, align 8, !tbaa !25
  %97 = load i64, ptr %4, align 8, !tbaa !26
  %98 = load i64, ptr %3, align 8, !tbaa !26
  %99 = sub nsw i64 %97, %98
  %100 = mul nsw i64 %99, 1000
  %101 = getelementptr inbounds i8, ptr %4, i64 8
  %102 = load i64, ptr %101, align 8, !tbaa !28
  %103 = getelementptr inbounds i8, ptr %3, i64 8
  %104 = load i64, ptr %103, align 8, !tbaa !28
  %105 = sub nsw i64 %102, %104
  %106 = sdiv i64 %105, 1000000
  %107 = add nsw i64 %106, %100
  %108 = getelementptr inbounds i8, ptr %0, i64 40
  store i64 %107, ptr %108, align 8, !tbaa !29
  %109 = load ptr, ptr %5, align 8, !tbaa !16
  call void @qrng_free(ptr noundef %109) #11
  br label %110

110:                                              ; preds = %84, %50
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #11
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #11
  br label %111

111:                                              ; preds = %7, %2, %110
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #11
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #11
  ret void
}

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

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

; Function Attrs: nounwind
declare i32 @clock_gettime(i32 noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #5

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

declare i32 @qrng_init(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #6

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

; Function Attrs: mustprogress 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) #8

; Function Attrs: nounwind uwtable
declare hidden void @quantum_mix(ptr noundef, i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

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

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

declare double @estimate_entropy(ptr noundef, i64 noundef) local_unnamed_addr #6

declare void @qrng_free(ptr noundef) local_unnamed_addr #6

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

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 nounwind willreturn memory(argmem: write) }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = { 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 #5 = { mustprogress nofree nounwind willreturn memory(argmem: 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 = { "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 = { 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 #8 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #9 = { 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 #10 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #11 = { nounwind }
attributes #12 = { nounwind allocsize(0) }
attributes #13 = { nounwind willreturn memory(read) }
attributes #14 = { cold 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, !10, i64 8}
!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 = !{!12, !13, i64 0}
!12 = !{!"", !13, i64 0, !8, i64 8, !14, i64 24, !15, i64 32, !15, i64 40}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!"double", !8, i64 0}
!15 = !{!"long", !8, i64 0}
!16 = !{!13, !13, i64 0}
!17 = !{!8, !8, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!6, !7, i64 0}
!21 = !{!6, !7, i64 1300}
!22 = !{!6, !8, i64 10}
!23 = distinct !{!23, !19}
!24 = !{!12, !14, i64 24}
!25 = !{!12, !15, i64 32}
!26 = !{!27, !15, i64 0}
!27 = !{!"timespec", !15, i64 0, !15, i64 8}
!28 = !{!27, !15, i64 8}
!29 = !{!12, !15, i64 40}


; Effective O3 passes: CorrelatedValuePropagationPass,DivRemPairsPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass