; LLVM IR from aap/pdp6 :: tools (as6)

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

@radix = external dso_local global i32, align 4
@lp = external dso_local global ptr, align 8
@.str.45 = external hidden unnamed_addr constant [24 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @err(i32 noundef, ptr noundef, ...) #0

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
declare dso_local void @skipwhite() #0

; Function Attrs: nounwind uwtable
declare dso_local { i64, i32 } @expr(i32 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @radixOp() #0 {
  %1 = alloca i32, align 4
  %2 = alloca %struct.Value, align 8
  %3 = alloca i32, align 4
  %4 = alloca %struct.Value, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %2) #3
  call void @skipwhite()
  %5 = load ptr, ptr @lp, align 8, !tbaa !5
  %6 = load i8, ptr %5, align 1, !tbaa !9
  %7 = sext i8 %6 to i32
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %14, label %9

9:                                                ; preds = %0
  %10 = load ptr, ptr @lp, align 8, !tbaa !5
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = sext i8 %11 to i32
  %13 = icmp eq i32 %12, 59
  br i1 %13, label %14, label %15

14:                                               ; preds = %9, %0
  store i32 1, ptr %3, align 4
  br label %38

15:                                               ; preds = %9
  %16 = load i32, ptr @radix, align 4, !tbaa !10
  store i32 %16, ptr %1, align 4, !tbaa !10
  store i32 10, ptr @radix, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #3
  %17 = call { i64, i32 } @expr(i32 noundef 1, ptr noundef null)
  %18 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 0
  %19 = extractvalue { i64, i32 } %17, 0
  store i64 %19, ptr %18, align 8
  %20 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 1
  %21 = extractvalue { i64, i32 } %17, 1
  store i32 %21, ptr %20, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %2, ptr align 8 %4, i64 16, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #3
  %22 = load i32, ptr %1, align 4, !tbaa !10
  store i32 %22, ptr @radix, align 4, !tbaa !10
  %23 = getelementptr inbounds %struct.Value, ptr %2, i32 0, i32 0
  %24 = load i64, ptr %23, align 8, !tbaa !15
  %25 = icmp ult i64 %24, 2
  br i1 %25, label %30, label %26

26:                                               ; preds = %15
  %27 = getelementptr inbounds %struct.Value, ptr %2, i32 0, i32 0
  %28 = load i64, ptr %27, align 8, !tbaa !15
  %29 = icmp ugt i64 %28, 10
  br i1 %29, label %30, label %33

30:                                               ; preds = %26, %15
  %31 = getelementptr inbounds %struct.Value, ptr %2, i32 0, i32 0
  %32 = load i64, ptr %31, align 8, !tbaa !15
  call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef @.str.45, i64 noundef %32)
  br label %37

33:                                               ; preds = %26
  %34 = getelementptr inbounds %struct.Value, ptr %2, i32 0, i32 0
  %35 = load i64, ptr %34, align 8, !tbaa !15
  %36 = trunc i64 %35 to i32
  store i32 %36, ptr @radix, align 4, !tbaa !10
  br label %37

37:                                               ; preds = %33, %30
  store i32 0, ptr %3, align 4
  br label %38

38:                                               ; preds = %37, %14
  call void @llvm.lifetime.end.p0(i64 16, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  %39 = load i32, ptr %3, align 4
  switch i32 %39, label %41 [
    i32 0, label %40
    i32 1, label %40
  ]

40:                                               ; preds = %38, %38
  ret void

41:                                               ; preds = %38
  unreachable
}

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{i64 0, i64 8, !13, i64 8, i64 4, !10}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !14, i64 0}
!16 = !{!"Value", !14, i64 0, !11, 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"

@radix = external dso_local local_unnamed_addr global i32, align 4
@lp = external dso_local local_unnamed_addr global ptr, align 8
@.str.45 = external hidden unnamed_addr constant [24 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @err(i32 noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @skipwhite() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local { i64, i32 } @expr(i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @radixOp() local_unnamed_addr #0 {
  tail call void @skipwhite()
  %1 = load ptr, ptr @lp, align 8, !tbaa !5
  %2 = load i8, ptr %1, align 1, !tbaa !9
  switch i8 %2, label %3 [
    i8 0, label %11
    i8 59, label %11
  ]

3:                                                ; preds = %0
  %4 = load i32, ptr @radix, align 4, !tbaa !10
  store i32 10, ptr @radix, align 4, !tbaa !10
  %5 = tail call { i64, i32 } @expr(i32 noundef 1, ptr noundef null)
  %6 = extractvalue { i64, i32 } %5, 0
  store i32 %4, ptr @radix, align 4, !tbaa !10
  %7 = add i64 %6, -11
  %or.cond = icmp ult i64 %7, -9
  br i1 %or.cond, label %8, label %9

8:                                                ; preds = %3
  tail call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef nonnull @.str.45, i64 noundef %6)
  br label %11

9:                                                ; preds = %3
  %10 = trunc nuw nsw i64 %6 to i32
  store i32 %10, ptr @radix, align 4, !tbaa !10
  br label %11

11:                                               ; preds = %8, %9, %0, %0
  ret void
}

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" }

!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}


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