; LLVM IR from aap/pdp6 :: fe6 (pdp6common)

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

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

8:                                                ; preds = %30, %1
  %9 = load i32, ptr %4, align 4, !tbaa !11
  %10 = icmp slt i32 %9, 6
  br i1 %10, label %11, label %33

11:                                               ; preds = %8
  br label %12

12:                                               ; preds = %22, %11
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = call i32 @getc(ptr noundef %13)
  store i32 %14, ptr %5, align 4, !tbaa !11
  %15 = load i32, ptr %5, align 4, !tbaa !11
  %16 = icmp eq i32 %15, -1
  br i1 %16, label %17, label %18

17:                                               ; preds = %12
  store i64 -1, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %35

18:                                               ; preds = %12
  %19 = load i32, ptr %5, align 4, !tbaa !11
  %20 = and i32 %19, 128
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %18
  br label %12

23:                                               ; preds = %18
  %24 = load i64, ptr %6, align 8, !tbaa !9
  %25 = shl i64 %24, 6
  %26 = load i32, ptr %5, align 4, !tbaa !11
  %27 = and i32 %26, 63
  %28 = sext i32 %27 to i64
  %29 = or i64 %25, %28
  store i64 %29, ptr %6, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %23
  %31 = load i32, ptr %4, align 4, !tbaa !11
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %4, align 4, !tbaa !11
  br label %8, !llvm.loop !13

33:                                               ; preds = %8
  %34 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %34, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %35

35:                                               ; preds = %33, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %36 = load i64, ptr %2, align 8
  ret i64 %36
}

declare i32 @getc(ptr noundef) #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 = !{!"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 = distinct !{!13, !14}
!14 = !{!"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"

; Function Attrs: nofree nounwind uwtable
define dso_local i64 @readw(ptr nocapture noundef %0) local_unnamed_addr #0 {
.preheader:
  br label %1

1:                                                ; preds = %.preheader, %4
  %2 = tail call i32 @getc(ptr noundef %0)
  %3 = icmp eq i32 %2, -1
  br i1 %3, label %.loopexit, label %4

4:                                                ; preds = %1
  %5 = and i32 %2, 128
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %1, label %.preheader.1

.preheader.1:                                     ; preds = %4, %9
  %7 = tail call i32 @getc(ptr noundef %0)
  %8 = icmp eq i32 %7, -1
  br i1 %8, label %.loopexit, label %9

9:                                                ; preds = %.preheader.1
  %10 = and i32 %7, 128
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %.preheader.1, label %.preheader.2

.preheader.2:                                     ; preds = %9
  %12 = shl i32 %2, 6
  %13 = and i32 %12, 4032
  %14 = and i32 %7, 63
  %15 = or disjoint i32 %13, %14
  br label %16

16:                                               ; preds = %19, %.preheader.2
  %17 = tail call i32 @getc(ptr noundef %0)
  %18 = icmp eq i32 %17, -1
  br i1 %18, label %.loopexit, label %19

19:                                               ; preds = %16
  %20 = and i32 %17, 128
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %16, label %.preheader.3

.preheader.3:                                     ; preds = %19, %24
  %22 = tail call i32 @getc(ptr noundef %0)
  %23 = icmp eq i32 %22, -1
  br i1 %23, label %.loopexit, label %24

24:                                               ; preds = %.preheader.3
  %25 = and i32 %22, 128
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %.preheader.3, label %.preheader.4

.preheader.4:                                     ; preds = %24
  %27 = shl nuw nsw i32 %15, 12
  %28 = shl i32 %17, 6
  %29 = and i32 %28, 4032
  %30 = or disjoint i32 %27, %29
  %31 = and i32 %22, 63
  %32 = or disjoint i32 %30, %31
  br label %33

33:                                               ; preds = %36, %.preheader.4
  %34 = tail call i32 @getc(ptr noundef %0)
  %35 = icmp eq i32 %34, -1
  br i1 %35, label %.loopexit, label %36

36:                                               ; preds = %33
  %37 = and i32 %34, 128
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %33, label %.preheader.5

.preheader.5:                                     ; preds = %36
  %39 = shl nuw nsw i32 %32, 6
  %40 = and i32 %34, 63
  %41 = or disjoint i32 %39, %40
  %42 = zext nneg i32 %41 to i64
  br label %43

43:                                               ; preds = %46, %.preheader.5
  %44 = tail call i32 @getc(ptr noundef %0)
  %45 = icmp eq i32 %44, -1
  br i1 %45, label %.loopexit, label %46

46:                                               ; preds = %43
  %47 = and i32 %44, 128
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %43, label %.loopexit.loopexit16

.loopexit.loopexit16:                             ; preds = %46
  %49 = shl nuw nsw i64 %42, 6
  %50 = and i32 %44, 63
  %51 = zext nneg i32 %50 to i64
  %52 = or disjoint i64 %49, %51
  br label %.loopexit

.loopexit:                                        ; preds = %1, %.preheader.1, %16, %.preheader.3, %33, %43, %.loopexit.loopexit16
  %.08 = phi i64 [ %52, %.loopexit.loopexit16 ], [ -1, %43 ], [ -1, %33 ], [ -1, %.preheader.3 ], [ -1, %16 ], [ -1, %.preheader.1 ], [ -1, %1 ]
  ret i64 %.08
}

; Function Attrs: nofree nounwind
declare noundef i32 @getc(ptr nocapture noundef) local_unnamed_addr #1

attributes #0 = { nofree 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 = { nofree nounwind "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)"}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass