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

; 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.Sha3Ctx_st = type { [25 x i64], [200 x i8], i64, i64, i64, i64, i64, i32 }

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

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

5:                                                ; preds = %1
  %6 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 448) #5
  store ptr %6, ptr %4, align 8, !tbaa !9
  %7 = icmp eq ptr null, %6
  br i1 %7, label %8, label %10

8:                                                ; preds = %5
  store i32 1, ptr %3, align 4, !tbaa !5
  %9 = load i32, ptr %3, align 4, !tbaa !5
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 148, i32 noundef %9, ptr noundef null)
  br label %41

10:                                               ; preds = %5
  br label %11

11:                                               ; preds = %10
  br label %12

12:                                               ; preds = %11
  %13 = load i32, ptr %2, align 4, !tbaa !5
  switch i32 %13, label %32 [
    i32 0, label %14
    i32 1, label %17
    i32 2, label %20
    i32 3, label %23
    i32 4, label %26
    i32 5, label %29
  ]

14:                                               ; preds = %12
  %15 = load ptr, ptr %4, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.Sha3Ctx_st, ptr %15, i32 0, i32 5
  store i64 7, ptr %16, align 8, !tbaa !11
  br label %37

17:                                               ; preds = %12
  %18 = load ptr, ptr %4, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.Sha3Ctx_st, ptr %18, i32 0, i32 5
  store i64 8, ptr %19, align 8, !tbaa !11
  br label %37

20:                                               ; preds = %12
  %21 = load ptr, ptr %4, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.Sha3Ctx_st, ptr %21, i32 0, i32 5
  store i64 12, ptr %22, align 8, !tbaa !11
  br label %37

23:                                               ; preds = %12
  %24 = load ptr, ptr %4, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.Sha3Ctx_st, ptr %24, i32 0, i32 5
  store i64 16, ptr %25, align 8, !tbaa !11
  br label %37

26:                                               ; preds = %12
  %27 = load ptr, ptr %4, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.Sha3Ctx_st, ptr %27, i32 0, i32 5
  store i64 4, ptr %28, align 8, !tbaa !11
  br label %37

29:                                               ; preds = %12
  %30 = load ptr, ptr %4, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.Sha3Ctx_st, ptr %30, i32 0, i32 5
  store i64 8, ptr %31, align 8, !tbaa !11
  br label %37

32:                                               ; preds = %12
  br label %33

33:                                               ; preds = %32
  store i32 2, ptr %3, align 4, !tbaa !5
  %34 = load i32, ptr %3, align 4, !tbaa !5
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 170, i32 noundef %34, ptr noundef null)
  br label %41

35:                                               ; No predecessors!
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36, %29, %26, %23, %20, %17, %14
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = load ptr, ptr %4, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.Sha3Ctx_st, ptr %39, i32 0, i32 7
  store i32 %38, ptr %40, align 8, !tbaa !14
  br label %41

41:                                               ; preds = %37, %33, %8
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %46

44:                                               ; preds = %41
  %45 = load ptr, ptr %4, align 8, !tbaa !9
  call void @sha3_free(ptr noundef %45)
  store ptr null, ptr %4, align 8, !tbaa !9
  br label %46

46:                                               ; preds = %44, %41
  %47 = load ptr, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret ptr %47
}

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

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #2

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

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

; 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 = { nounwind allocsize(0,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 #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 = { nounwind }
attributes #5 = { nounwind allocsize(0,1) }

!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}
!11 = !{!12, !13, i64 424}
!12 = !{!"Sha3Ctx_st", !7, i64 0, !7, i64 200, !13, i64 400, !13, i64 408, !13, i64 416, !13, i64 424, !13, i64 432, !6, i64 440}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 440}


; 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 [14 x i8], align 1
@switch.table.sha3_alloc = private unnamed_addr constant [6 x i64] [i64 7, i64 8, i64 12, i64 16, i64 4, i64 8], align 8

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @sha3_alloc(i32 noundef %0) local_unnamed_addr #0 {
  %2 = tail call noalias dereferenceable_or_null(448) ptr @calloc(i64 noundef 1, i64 noundef 448) #3
  %3 = icmp eq ptr %2, null
  br i1 %3, label %4, label %5

4:                                                ; preds = %1
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 148, i32 noundef 1, ptr noundef null) #4
  br label %.critedge

5:                                                ; preds = %1
  %6 = icmp ult i32 %0, 6
  br i1 %6, label %switch.lookup, label %7

7:                                                ; preds = %5
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 170, i32 noundef 2, ptr noundef null) #4
  br label %.critedge

switch.lookup:                                    ; preds = %5
  %8 = zext nneg i32 %0 to i64
  %switch.gep = getelementptr inbounds [6 x i64], ptr @switch.table.sha3_alloc, i64 0, i64 %8
  %switch.load = load i64, ptr %switch.gep, align 8
  %9 = getelementptr inbounds i8, ptr %2, i64 424
  store i64 %switch.load, ptr %9, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %2, i64 440
  store i32 %0, ptr %10, align 8, !tbaa !11
  br label %11

.critedge:                                        ; preds = %7, %4
  tail call void @sha3_free(ptr noundef %2)
  br label %11

11:                                               ; preds = %switch.lookup, %.critedge
  %.0 = phi ptr [ null, %.critedge ], [ %2, %switch.lookup ]
  ret ptr %.0
}

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @sha3_free(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 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) 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 #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 allocsize(0,1) }
attributes #4 = { 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, !9, i64 424}
!6 = !{!"Sha3Ctx_st", !7, i64 0, !7, i64 200, !9, i64 400, !9, i64 408, !9, i64 416, !9, i64 424, !9, i64 432, !10, i64 440}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!6, !10, i64 440}


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