; LLVM IR from specinfo-ua/UAPKI :: library/uapkic/src (entropy)

; 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.ByteArray_st = type { ptr, i64 }

@.str = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @entropy_get(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store ptr null, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store ptr null, ptr %5, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %1
  %7 = call ptr @ba_alloc_by_len(i64 noundef 512)
  store ptr %7, ptr %5, align 8, !tbaa !5
  %8 = icmp eq ptr null, %7
  br i1 %8, label %9, label %11

9:                                                ; preds = %6
  store i32 2, ptr %3, align 4, !tbaa !9
  %10 = load i32, ptr %3, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 152, i32 noundef %10)
  br label %57

11:                                               ; preds = %6
  br label %12

12:                                               ; preds = %11
  br label %13

13:                                               ; preds = %12
  br label %14

14:                                               ; preds = %13
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ByteArray_st, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = call i32 @os_prng(ptr noundef %17, i64 noundef 256)
  store i32 %18, ptr %3, align 4, !tbaa !9
  %19 = load i32, ptr %3, align 4, !tbaa !9
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %23

21:                                               ; preds = %14
  %22 = load i32, ptr %3, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 155, i32 noundef %22)
  br label %57

23:                                               ; preds = %14
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  %26 = call i32 @jent_entropy_init()
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %33

28:                                               ; preds = %25
  br label %29

29:                                               ; preds = %28
  store i32 9, ptr %3, align 4, !tbaa !9
  %30 = load i32, ptr %3, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 158, i32 noundef %30, ptr noundef null)
  br label %57

31:                                               ; No predecessors!
  br label %32

32:                                               ; preds = %31
  br label %33

33:                                               ; preds = %32, %25
  br label %34

34:                                               ; preds = %33
  %35 = call ptr @jent_entropy_collector_alloc(i32 noundef 1, i32 noundef 0)
  store ptr %35, ptr %4, align 8, !tbaa !5
  %36 = icmp eq ptr null, %35
  br i1 %36, label %37, label %39

37:                                               ; preds = %34
  store i32 2, ptr %3, align 4, !tbaa !9
  %38 = load i32, ptr %3, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 160, i32 noundef %38)
  br label %57

39:                                               ; preds = %34
  br label %40

40:                                               ; preds = %39
  br label %41

41:                                               ; preds = %40
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ByteArray_st, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  %46 = getelementptr inbounds i8, ptr %45, i64 256
  %47 = call i32 @jent_read_entropy(ptr noundef %42, ptr noundef %46, i64 noundef 256)
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %54

49:                                               ; preds = %41
  br label %50

50:                                               ; preds = %49
  store i32 9, ptr %3, align 4, !tbaa !9
  %51 = load i32, ptr %3, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 162, i32 noundef %51, ptr noundef null)
  br label %57

52:                                               ; No predecessors!
  br label %53

53:                                               ; preds = %52
  br label %54

54:                                               ; preds = %53, %41
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %55, ptr %56, align 8, !tbaa !5
  store ptr null, ptr %5, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %54, %50, %37, %29, %21, %9
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  call void @jent_entropy_collector_free(ptr noundef %58)
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  call void @ba_free_private(ptr noundef %59)
  %60 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %60
}

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

declare ptr @ba_alloc_by_len(i64 noundef) #2

declare void @stacktrace_add(ptr noundef, i64 noundef, i32 noundef) #2

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

declare i32 @jent_entropy_init() #2

declare void @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) #2

declare ptr @jent_entropy_collector_alloc(i32 noundef, i32 noundef) #2

declare i32 @jent_read_entropy(ptr noundef, ptr noundef, i64 noundef) #2

declare void @jent_entropy_collector_free(ptr noundef) #2

declare void @ba_free_private(ptr 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 }

!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, !6, i64 0}
!12 = !{!"ByteArray_st", !6, i64 0, !13, i64 8}
!13 = !{!"long", !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"

@.str = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @entropy_get(ptr nocapture noundef writeonly %0) local_unnamed_addr #0 {
  %2 = tail call ptr @ba_alloc_by_len(i64 noundef 512) #2
  %3 = icmp eq ptr %2, null
  br i1 %3, label %4, label %5

4:                                                ; preds = %1
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 152, i32 noundef 2) #2
  br label %22

5:                                                ; preds = %1
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = tail call i32 @os_prng(ptr noundef %6, i64 noundef 256)
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %9, label %8

8:                                                ; preds = %5
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 155, i32 noundef %7) #2
  br label %22

9:                                                ; preds = %5
  %10 = tail call i32 @jent_entropy_init() #2
  %.not20 = icmp eq i32 %10, 0
  br i1 %.not20, label %12, label %11

11:                                               ; preds = %9
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 158, i32 noundef 9, ptr noundef null) #2
  br label %22

12:                                               ; preds = %9
  %13 = tail call ptr @jent_entropy_collector_alloc(i32 noundef 1, i32 noundef 0) #2
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 160, i32 noundef 2) #2
  br label %22

16:                                               ; preds = %12
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 256
  %19 = tail call i32 @jent_read_entropy(ptr noundef nonnull %13, ptr noundef nonnull %18, i64 noundef 256) #2
  %.not21 = icmp eq i32 %19, 0
  br i1 %.not21, label %21, label %20

20:                                               ; preds = %16
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 162, i32 noundef 9, ptr noundef null) #2
  br label %22

21:                                               ; preds = %16
  store ptr %2, ptr %0, align 8, !tbaa !11
  br label %22

22:                                               ; preds = %21, %20, %15, %11, %8, %4
  %.014 = phi i32 [ 2, %4 ], [ %7, %8 ], [ 9, %11 ], [ 2, %15 ], [ 9, %20 ], [ 0, %21 ]
  %.013 = phi ptr [ null, %4 ], [ null, %8 ], [ null, %11 ], [ null, %15 ], [ %13, %20 ], [ %13, %21 ]
  %.0 = phi ptr [ null, %4 ], [ %2, %8 ], [ %2, %11 ], [ %2, %15 ], [ %2, %20 ], [ null, %21 ]
  tail call void @jent_entropy_collector_free(ptr noundef %.013) #2
  tail call void @ba_free_private(ptr noundef %.0) #2
  ret i32 %.014
}

declare ptr @ba_alloc_by_len(i64 noundef) local_unnamed_addr #1

declare void @stacktrace_add(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

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

declare i32 @jent_entropy_init() local_unnamed_addr #1

declare void @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare ptr @jent_entropy_collector_alloc(i32 noundef, i32 noundef) local_unnamed_addr #1

declare i32 @jent_read_entropy(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare void @jent_entropy_collector_free(ptr noundef) local_unnamed_addr #1

declare void @ba_free_private(ptr noundef) local_unnamed_addr #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 = { "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 }

!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 0}
!6 = !{!"ByteArray_st", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!7, !7, i64 0}


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