; LLVM IR from specinfo-ua/UAPKI :: library/uapkif/src/asn1 (xer_decoder)

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

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

; 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 i64 @xer_next_token(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca %struct.xer__cb_arg, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = load i32, ptr %14, align 4, !tbaa !11
  store i32 %15, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %16 = getelementptr inbounds %struct.xer__cb_arg, ptr %10, i32 0, i32 3
  store i32 1, ptr %16, align 8, !tbaa !13
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = load i64, ptr %8, align 8, !tbaa !9
  %19 = call i64 @pxml_parse(ptr noundef %11, ptr noundef %17, i64 noundef %18, ptr noundef @xer__token_cb, ptr noundef %10)
  store i64 %19, ptr %12, align 8, !tbaa !9
  %20 = load i64, ptr %12, align 8, !tbaa !9
  %21 = icmp slt i64 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %4
  store i64 -1, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %46

23:                                               ; preds = %4
  %24 = getelementptr inbounds %struct.xer__cb_arg, ptr %10, i32 0, i32 3
  %25 = load i32, ptr %24, align 8, !tbaa !13
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %23
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 0, ptr %28, align 4, !tbaa !11
  store i64 0, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %46

29:                                               ; preds = %23
  br label %30

30:                                               ; preds = %29
  %31 = getelementptr inbounds %struct.xer__cb_arg, ptr %10, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !15
  switch i32 %32, label %41 [
    i32 0, label %33
    i32 1, label %35
    i32 3, label %37
    i32 2, label %39
    i32 4, label %39
  ]

33:                                               ; preds = %30
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 2, ptr %34, align 4, !tbaa !11
  br label %41

35:                                               ; preds = %30
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 0, ptr %36, align 4, !tbaa !11
  store i64 0, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %46

37:                                               ; preds = %30
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 1, ptr %38, align 4, !tbaa !11
  br label %41

39:                                               ; preds = %30, %30
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 3, ptr %40, align 4, !tbaa !11
  br label %41

41:                                               ; preds = %39, %37, %33, %30
  %42 = load i32, ptr %11, align 4, !tbaa !11
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %42, ptr %43, align 4, !tbaa !11
  %44 = getelementptr inbounds %struct.xer__cb_arg, ptr %10, i32 0, i32 1
  %45 = load i64, ptr %44, align 8, !tbaa !16
  store i64 %45, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %46

46:                                               ; preds = %41, %35, %27, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %10) #3
  %47 = load i64, ptr %5, align 8
  ret i64 %47
}

declare i64 @pxml_parse(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 24}
!14 = !{!"xer__cb_arg", !12, i64 0, !10, i64 8, !6, i64 16, !12, i64 24}
!15 = !{!14, !12, i64 0}
!16 = !{!14, !10, i64 8}


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

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

; Function Attrs: mustprogress 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 i64 @xer_next_token(ptr nocapture noundef %0, ptr noundef %1, i64 noundef %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #1 {
  %5 = alloca %struct.xer__cb_arg, align 8
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  %7 = load i32, ptr %0, align 4, !tbaa !5
  store i32 %7, ptr %6, align 4, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %5, i64 24
  store i32 1, ptr %8, align 8, !tbaa !9
  %9 = call i64 @pxml_parse(ptr noundef nonnull %6, ptr noundef %1, i64 noundef %2, ptr noundef nonnull @xer__token_cb, ptr noundef nonnull %5) #3
  %10 = icmp slt i64 %9, 0
  br i1 %10, label %23, label %11

11:                                               ; preds = %4
  %12 = load i32, ptr %8, align 8, !tbaa !9
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %14, label %13

13:                                               ; preds = %11
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %23

14:                                               ; preds = %11
  %15 = load i32, ptr %5, align 8, !tbaa !13
  switch i32 %15, label %19 [
    i32 0, label %.sink.split
    i32 1, label %16
    i32 3, label %17
    i32 2, label %18
    i32 4, label %18
  ]

16:                                               ; preds = %14
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %23

17:                                               ; preds = %14
  br label %.sink.split

18:                                               ; preds = %14, %14
  br label %.sink.split

.sink.split:                                      ; preds = %14, %17, %18
  %.sink = phi i32 [ 3, %18 ], [ 1, %17 ], [ 2, %14 ]
  store i32 %.sink, ptr %3, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %.sink.split, %14
  %20 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %20, ptr %0, align 4, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %5, i64 8
  %22 = load i64, ptr %21, align 8, !tbaa !14
  br label %23

23:                                               ; preds = %4, %19, %16, %13
  %.0 = phi i64 [ 0, %13 ], [ %22, %19 ], [ 0, %16 ], [ -1, %4 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #3
  ret i64 %.0
}

declare i64 @pxml_parse(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 24}
!10 = !{!"xer__cb_arg", !6, i64 0, !11, i64 8, !12, i64 16, !6, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!10, !6, i64 0}
!14 = !{!10, !11, i64 8}


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