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

; 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 [18 x i8], align 1

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

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

13:                                               ; preds = %10
  store i32 2, ptr %9, align 4, !tbaa !10
  %14 = load i32, ptr %9, align 4, !tbaa !10
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 43, i32 noundef %14, ptr noundef null)
  br label %68

15:                                               ; preds = %10
  br label %16

16:                                               ; preds = %15
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %23, label %21

21:                                               ; preds = %18
  store i32 2, ptr %9, align 4, !tbaa !10
  %22 = load i32, ptr %9, align 4, !tbaa !10
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 44, i32 noundef %22, ptr noundef null)
  br label %68

23:                                               ; preds = %18
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  %26 = load i8, ptr %5, align 1, !tbaa !9
  %27 = zext i8 %26 to i64
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.ByteArray_st, ptr %28, i32 0, i32 1
  %30 = load i64, ptr %29, align 8, !tbaa !12
  %31 = load i8, ptr %5, align 1, !tbaa !9
  %32 = zext i8 %31 to i64
  %33 = urem i64 %30, %32
  %34 = sub i64 %27, %33
  %35 = trunc i64 %34 to i8
  store i8 %35, ptr %8, align 1, !tbaa !9
  br label %36

36:                                               ; preds = %25
  %37 = load i8, ptr %8, align 1, !tbaa !9
  %38 = zext i8 %37 to i64
  %39 = call ptr @ba_alloc_by_len(i64 noundef %38)
  store ptr %39, ptr %7, align 8, !tbaa !5
  %40 = icmp eq ptr null, %39
  br i1 %40, label %41, label %43

41:                                               ; preds = %36
  store i32 2, ptr %9, align 4, !tbaa !10
  %42 = load i32, ptr %9, align 4, !tbaa !10
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 48, i32 noundef %42)
  br label %68

43:                                               ; preds = %36
  br label %44

44:                                               ; preds = %43
  br label %45

45:                                               ; preds = %44
  br label %46

46:                                               ; preds = %45
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = load i8, ptr %8, align 1, !tbaa !9
  %49 = call i32 @ba_set(ptr noundef %47, i8 noundef zeroext %48)
  store i32 %49, ptr %9, align 4, !tbaa !10
  %50 = load i32, ptr %9, align 4, !tbaa !10
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %54

52:                                               ; preds = %46
  %53 = load i32, ptr %9, align 4, !tbaa !10
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 49, i32 noundef %53)
  br label %68

54:                                               ; preds = %46
  br label %55

55:                                               ; preds = %54
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = call ptr @ba_join(ptr noundef %58, ptr noundef %59)
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %60, ptr %61, align 8, !tbaa !5
  %62 = icmp eq ptr null, %60
  br i1 %62, label %63, label %65

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

65:                                               ; preds = %57
  br label %66

66:                                               ; preds = %65
  br label %67

67:                                               ; preds = %66
  br label %68

68:                                               ; preds = %67, %63, %52, %41, %21, %13
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  call void @ba_free(ptr noundef %69)
  %70 = load i32, ptr %9, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i32 %70
}

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

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

declare ptr @ba_alloc_by_len(i64 noundef) #2

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

declare i32 @ba_set(ptr noundef, i8 noundef zeroext) #2

declare ptr @ba_join(ptr noundef, ptr noundef) #2

declare void @ba_free(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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !14, i64 8}
!13 = !{!"ByteArray_st", !6, i64 0, !14, i64 8}
!14 = !{!"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 [18 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @make_pkcs7_padding(ptr noundef %0, i8 noundef zeroext %1, ptr noundef writeonly %2) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %4, label %5

4:                                                ; preds = %3
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 43, i32 noundef 2, ptr noundef null) #2
  br label %25

5:                                                ; preds = %3
  %.not24 = icmp eq ptr %2, null
  br i1 %.not24, label %6, label %7

6:                                                ; preds = %5
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 44, i32 noundef 2, ptr noundef null) #2
  br label %25

7:                                                ; preds = %5
  %8 = zext i8 %1 to i64
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = urem i64 %10, %8
  %12 = trunc nuw i64 %11 to i8
  %13 = sub i8 %1, %12
  %14 = zext i8 %13 to i64
  %15 = tail call ptr @ba_alloc_by_len(i64 noundef %14) #2
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %7
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 48, i32 noundef 2) #2
  br label %25

18:                                               ; preds = %7
  %19 = tail call i32 @ba_set(ptr noundef nonnull %15, i8 noundef zeroext %13) #2
  %.not25 = icmp eq i32 %19, 0
  br i1 %.not25, label %21, label %20

20:                                               ; preds = %18
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 49, i32 noundef %19) #2
  br label %25

21:                                               ; preds = %18
  %22 = tail call ptr @ba_join(ptr noundef nonnull %0, ptr noundef nonnull %15) #2
  store ptr %22, ptr %2, align 8, !tbaa !11
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 51, i32 noundef 2) #2
  br label %25

25:                                               ; preds = %21, %24, %20, %17, %6, %4
  %.018 = phi ptr [ null, %17 ], [ %15, %20 ], [ %15, %24 ], [ %15, %21 ], [ null, %6 ], [ null, %4 ]
  %.0 = phi i32 [ 2, %17 ], [ %19, %20 ], [ 2, %24 ], [ 0, %21 ], [ 2, %6 ], [ 2, %4 ]
  tail call void @ba_free(ptr noundef %.018) #2
  ret i32 %.0
}

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

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

declare i32 @ba_set(ptr noundef, i8 noundef zeroext) local_unnamed_addr #1

declare ptr @ba_join(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @ba_free(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, !10, i64 8}
!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