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

@lp = external dso_local global ptr, align 8

; 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 @character(i8 noundef signext %0, i32 noundef %1) #1 {
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i8, align 1
  store i8 %0, ptr %3, align 1, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  store i64 0, ptr %6, align 8, !tbaa !10
  %8 = load i32, ptr %4, align 4, !tbaa !8
  %9 = shl i32 1, %8
  %10 = sub nsw i32 %9, 1
  store i32 %10, ptr %5, align 4, !tbaa !8
  br label %11

11:                                               ; preds = %39, %38, %2
  %12 = load ptr, ptr @lp, align 8, !tbaa !12
  %13 = getelementptr inbounds i8, ptr %12, i32 1
  store ptr %13, ptr @lp, align 8, !tbaa !12
  %14 = load i8, ptr %12, align 1, !tbaa !5
  store i8 %14, ptr %7, align 1, !tbaa !5
  %15 = load i8, ptr %7, align 1, !tbaa !5
  %16 = sext i8 %15 to i32
  %17 = load i8, ptr %3, align 1, !tbaa !5
  %18 = sext i8 %17 to i32
  %19 = icmp ne i32 %16, %18
  br i1 %19, label %20, label %52

20:                                               ; preds = %11
  %21 = load i8, ptr %7, align 1, !tbaa !5
  %22 = sext i8 %21 to i32
  %23 = icmp eq i32 %22, 92
  br i1 %23, label %24, label %28

24:                                               ; preds = %20
  %25 = load ptr, ptr @lp, align 8, !tbaa !12
  %26 = getelementptr inbounds i8, ptr %25, i32 1
  store ptr %26, ptr @lp, align 8, !tbaa !12
  %27 = load i8, ptr %25, align 1, !tbaa !5
  store i8 %27, ptr %7, align 1, !tbaa !5
  br label %28

28:                                               ; preds = %24, %20
  %29 = load i32, ptr %4, align 4, !tbaa !8
  %30 = icmp eq i32 %29, 6
  br i1 %30, label %31, label %34

31:                                               ; preds = %28
  %32 = load i8, ptr %7, align 1, !tbaa !5
  %33 = call signext i8 @ascii2sixbit(i8 noundef signext %32)
  store i8 %33, ptr %7, align 1, !tbaa !5
  br label %34

34:                                               ; preds = %31, %28
  %35 = load i8, ptr %7, align 1, !tbaa !5
  %36 = sext i8 %35 to i32
  %37 = icmp slt i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %34
  br label %11, !llvm.loop !14

39:                                               ; preds = %34
  %40 = load i32, ptr %5, align 4, !tbaa !8
  %41 = load i8, ptr %7, align 1, !tbaa !5
  %42 = sext i8 %41 to i32
  %43 = and i32 %42, %40
  %44 = trunc i32 %43 to i8
  store i8 %44, ptr %7, align 1, !tbaa !5
  %45 = load i64, ptr %6, align 8, !tbaa !10
  %46 = load i32, ptr %4, align 4, !tbaa !8
  %47 = zext i32 %46 to i64
  %48 = shl i64 %45, %47
  %49 = load i8, ptr %7, align 1, !tbaa !5
  %50 = sext i8 %49 to i64
  %51 = or i64 %48, %50
  store i64 %51, ptr %6, align 8, !tbaa !10
  br label %11, !llvm.loop !14

52:                                               ; preds = %11
  %53 = load i32, ptr %4, align 4, !tbaa !8
  %54 = icmp eq i32 %53, 7
  br i1 %54, label %55, label %58

55:                                               ; preds = %52
  %56 = load i64, ptr %6, align 8, !tbaa !10
  %57 = and i64 %56, 34359738367
  store i64 %57, ptr %6, align 8, !tbaa !10
  br label %58

58:                                               ; preds = %55, %52
  %59 = load i64, ptr %6, align 8, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i64 %59
}

declare signext i8 @ascii2sixbit(i8 noundef signext) #2

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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !6, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !6, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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

@lp = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i64 @character(i8 noundef signext %0, i32 noundef %1) local_unnamed_addr #0 {
  %notmask = shl nsw i32 -1, %1
  %3 = icmp eq i32 %1, 6
  %4 = trunc i32 %notmask to i8
  %5 = xor i8 %4, -1
  %6 = zext nneg i32 %1 to i64
  br i1 %3, label %.outer.us, label %.split22

.outer.us:                                        ; preds = %2, %.split20.us.us
  %.015.ph.us = phi i64 [ %22, %.split20.us.us ], [ 0, %2 ]
  br label %7

7:                                                ; preds = %16, %.outer.us
  %8 = load ptr, ptr @lp, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 1
  store ptr %9, ptr @lp, align 8, !tbaa !5
  %10 = load i8, ptr %8, align 1, !tbaa !9
  %.not.us.us = icmp eq i8 %10, %0
  br i1 %.not.us.us, label %.split.us, label %11

11:                                               ; preds = %7
  %12 = icmp eq i8 %10, 92
  br i1 %12, label %13, label %16

13:                                               ; preds = %11
  %14 = getelementptr inbounds i8, ptr %8, i64 2
  store ptr %14, ptr @lp, align 8, !tbaa !5
  %15 = load i8, ptr %9, align 1, !tbaa !9
  br label %16

16:                                               ; preds = %13, %11
  %.0.us.us = phi i8 [ %15, %13 ], [ %10, %11 ]
  %17 = tail call signext i8 @ascii2sixbit(i8 noundef signext %.0.us.us) #2
  %18 = icmp slt i8 %17, 0
  br i1 %18, label %7, label %.split20.us.us, !llvm.loop !10

.split20.us.us:                                   ; preds = %16
  %19 = and i8 %17, 63
  %20 = shl i64 %.015.ph.us, %6
  %21 = zext nneg i8 %19 to i64
  %22 = or disjoint i64 %20, %21
  br label %.outer.us, !llvm.loop !10

.split22:                                         ; preds = %2
  %lp.promoted24 = load ptr, ptr @lp, align 8, !tbaa !5
  br label %.outer

.outer:                                           ; preds = %.split20, %.split22
  %lp.promoted25 = phi ptr [ %33, %.split20 ], [ %lp.promoted24, %.split22 ]
  %.015.ph = phi i64 [ %38, %.split20 ], [ 0, %.split22 ]
  br label %23

23:                                               ; preds = %.outer, %32
  %24 = phi ptr [ %lp.promoted25, %.outer ], [ %33, %32 ]
  %25 = getelementptr inbounds i8, ptr %24, i64 1
  store ptr %25, ptr @lp, align 8, !tbaa !5
  %26 = load i8, ptr %24, align 1, !tbaa !9
  %.not = icmp eq i8 %26, %0
  br i1 %.not, label %.split.us, label %27

27:                                               ; preds = %23
  %28 = icmp eq i8 %26, 92
  br i1 %28, label %29, label %32

29:                                               ; preds = %27
  %30 = getelementptr inbounds i8, ptr %24, i64 2
  store ptr %30, ptr @lp, align 8, !tbaa !5
  %31 = load i8, ptr %25, align 1, !tbaa !9
  br label %32

32:                                               ; preds = %29, %27
  %33 = phi ptr [ %30, %29 ], [ %25, %27 ]
  %.0 = phi i8 [ %31, %29 ], [ %26, %27 ]
  %34 = icmp slt i8 %.0, 0
  br i1 %34, label %23, label %.split20, !llvm.loop !10

.split20:                                         ; preds = %32
  %35 = and i8 %.0, %5
  %36 = shl i64 %.015.ph, %6
  %37 = zext nneg i8 %35 to i64
  %38 = or i64 %36, %37
  br label %.outer, !llvm.loop !10

.split.us:                                        ; preds = %23, %7
  %.us-phi = phi i64 [ %.015.ph.us, %7 ], [ %.015.ph, %23 ]
  %39 = icmp eq i32 %1, 7
  %40 = and i64 %.us-phi, 34359738367
  %spec.select = select i1 %39, i64 %40, i64 %.us-phi
  ret i64 %spec.select
}

declare signext i8 @ascii2sixbit(i8 noundef signext) 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, !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 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass