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

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

@peekc = external dso_local global i32, align 4
@infp = external dso_local global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @ch() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %4 = load i32, ptr @peekc, align 4, !tbaa !5
  %5 = icmp ne i32 %4, 0
  br i1 %5, label %6, label %9

6:                                                ; preds = %0
  %7 = load i32, ptr @peekc, align 4, !tbaa !5
  store i32 %7, ptr %2, align 4, !tbaa !5
  store i32 0, ptr @peekc, align 4, !tbaa !5
  %8 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %8, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %37

9:                                                ; preds = %0
  br label %10

10:                                               ; preds = %27, %9
  %11 = load ptr, ptr @infp, align 8, !tbaa !9
  %12 = call i32 @getc(ptr noundef %11)
  store i32 %12, ptr %2, align 4, !tbaa !5
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = icmp eq i32 %13, 59
  br i1 %14, label %15, label %28

15:                                               ; preds = %10
  br label %16

16:                                               ; preds = %26, %15
  %17 = load ptr, ptr @infp, align 8, !tbaa !9
  %18 = call i32 @getc(ptr noundef %17)
  store i32 %18, ptr %2, align 4, !tbaa !5
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = icmp ne i32 %19, 10
  br i1 %20, label %21, label %27

21:                                               ; preds = %16
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = icmp eq i32 %22, -1
  br i1 %23, label %24, label %26

24:                                               ; preds = %21
  %25 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %25, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %37

26:                                               ; preds = %21
  br label %16, !llvm.loop !11

27:                                               ; preds = %16
  br label %10

28:                                               ; preds = %10
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = icmp eq i32 %29, 9
  br i1 %30, label %34, label %31

31:                                               ; preds = %28
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = icmp eq i32 %32, 10
  br i1 %33, label %34, label %35

34:                                               ; preds = %31, %28
  store i32 32, ptr %2, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %34, %31
  %36 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %36, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %37

37:                                               ; preds = %35, %24, %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  %38 = load i32, ptr %1, align 4
  ret i32 %38
}

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

declare i32 @getc(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@peekc = external dso_local local_unnamed_addr global i32, align 4
@infp = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nofree nounwind uwtable
define dso_local i32 @ch() local_unnamed_addr #0 {
  %1 = load i32, ptr @peekc, align 4, !tbaa !5
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %.preheader15, label %5

.preheader15:                                     ; preds = %0
  %2 = load ptr, ptr @infp, align 8, !tbaa !9
  %3 = tail call i32 @getc(ptr noundef %2)
  %4 = icmp eq i32 %3, 59
  br i1 %4, label %.preheader, label %._crit_edge

5:                                                ; preds = %0
  store i32 0, ptr @peekc, align 4, !tbaa !5
  br label %.loopexit14

.loopexit:                                        ; preds = %.preheader
  %6 = load ptr, ptr @infp, align 8, !tbaa !9
  %7 = tail call i32 @getc(ptr noundef %6)
  %8 = icmp eq i32 %7, 59
  br i1 %8, label %.preheader.backedge, label %._crit_edge

.preheader:                                       ; preds = %.preheader15, %.preheader.backedge
  %9 = load ptr, ptr @infp, align 8, !tbaa !9
  %10 = tail call i32 @getc(ptr noundef %9)
  switch i32 %10, label %.preheader.backedge [
    i32 10, label %.loopexit
    i32 -1, label %.loopexit14
  ]

.preheader.backedge:                              ; preds = %.preheader, %.loopexit
  br label %.preheader

._crit_edge:                                      ; preds = %.loopexit, %.preheader15
  %.lcssa = phi i32 [ %3, %.preheader15 ], [ %7, %.loopexit ]
  %11 = add i32 %.lcssa, -9
  %or.cond = icmp ult i32 %11, 2
  %spec.store.select = select i1 %or.cond, i32 32, i32 %.lcssa
  br label %.loopexit14

.loopexit14:                                      ; preds = %.preheader, %._crit_edge, %5
  %.0 = phi i32 [ %1, %5 ], [ %spec.store.select, %._crit_edge ], [ %10, %.preheader ]
  ret i32 %.0
}

; 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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}


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