; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

declare ptr @ba_alloc_by_len(i64 noundef) #1

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

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

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

declare void @ba_free(ptr noundef) #1

; 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
define dso_local i32 @make_iso_7816_4_padding(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2) #2 {
  %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 83, i32 noundef %14, ptr noundef null)
  br label %71

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 84, i32 noundef %22, ptr noundef null)
  br label %71

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 88, i32 noundef %42)
  br label %71

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 = call i32 @ba_set(ptr noundef %47, i8 noundef zeroext 0)
  store i32 %48, ptr %9, align 4, !tbaa !10
  %49 = load i32, ptr %9, align 4, !tbaa !10
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %53

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

53:                                               ; preds = %46
  br label %54

54:                                               ; preds = %53
  br label %55

55:                                               ; preds = %54
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.ByteArray_st, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !15
  %59 = getelementptr inbounds i8, ptr %58, i64 0
  store i8 -128, ptr %59, align 1, !tbaa !9
  br label %60

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

66:                                               ; preds = %60
  store i32 2, ptr %9, align 4, !tbaa !10
  %67 = load i32, ptr %9, align 4, !tbaa !10
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 92, i32 noundef %67)
  br label %71

68:                                               ; preds = %60
  br label %69

69:                                               ; preds = %68
  br label %70

70:                                               ; preds = %69
  br label %71

71:                                               ; preds = %70, %66, %51, %41, %21, %13
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  call void @ba_free(ptr noundef %72)
  %73 = 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 %73
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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}
!15 = !{!13, !6, 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

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

declare ptr @ba_alloc_by_len(i64 noundef) local_unnamed_addr #0

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

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

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

declare void @ba_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @make_iso_7816_4_padding(ptr noundef %0, i8 noundef zeroext %1, ptr noundef writeonly %2) local_unnamed_addr #1 {
  %.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 83, i32 noundef 2, ptr noundef null) #2
  br label %26

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 84, i32 noundef 2, ptr noundef null) #2
  br label %26

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 88, i32 noundef 2) #2
  br label %26

18:                                               ; preds = %7
  %19 = tail call i32 @ba_set(ptr noundef nonnull %15, i8 noundef zeroext 0) #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 89, i32 noundef %19) #2
  br label %26

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

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

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

attributes #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 = { 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 = { 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 = !{!6, !7, i64 0}
!12 = !{!8, !8, i64 0}
!13 = !{!7, !7, i64 0}


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