; LLVM IR from cornell-zhang/rosetta :: optical-flow/imageLib/ImageIO.ll (Z10skip_spaceP8_IO_FILE)

; 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

declare i32 @getc(ptr noundef) #1

declare i32 @ungetc(i32 noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z10skip_spaceP8_IO_FILE(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  br label %4

4:                                                ; preds = %24, %1
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = call i32 @getc(ptr noundef %5)
  %7 = trunc i32 %6 to i8
  store i8 %7, ptr %3, align 1, !tbaa !9
  br label %8

8:                                                ; preds = %4
  %9 = load i8, ptr %3, align 1, !tbaa !9
  %10 = sext i8 %9 to i32
  %11 = icmp eq i32 %10, 10
  br i1 %11, label %24, label %12

12:                                               ; preds = %8
  %13 = load i8, ptr %3, align 1, !tbaa !9
  %14 = sext i8 %13 to i32
  %15 = icmp eq i32 %14, 32
  br i1 %15, label %24, label %16

16:                                               ; preds = %12
  %17 = load i8, ptr %3, align 1, !tbaa !9
  %18 = sext i8 %17 to i32
  %19 = icmp eq i32 %18, 9
  br i1 %19, label %24, label %20

20:                                               ; preds = %16
  %21 = load i8, ptr %3, align 1, !tbaa !9
  %22 = sext i8 %21 to i32
  %23 = icmp eq i32 %22, 13
  br label %24

24:                                               ; preds = %20, %16, %12, %8
  %25 = phi i1 [ true, %16 ], [ true, %12 ], [ true, %8 ], [ %23, %20 ]
  br i1 %25, label %4, label %26, !llvm.loop !10

26:                                               ; preds = %24
  %27 = load i8, ptr %3, align 1, !tbaa !9
  %28 = sext i8 %27 to i32
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = call i32 @ungetc(i32 noundef %28, ptr noundef %29)
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress 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 #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++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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
declare noundef i32 @getc(ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @ungetc(i32 noundef, ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_Z10skip_spaceP8_IO_FILE(ptr nocapture noundef %0) local_unnamed_addr #1 {
  br label %.critedge

.critedge:                                        ; preds = %.critedge.backedge, %1
  %2 = tail call i32 @getc(ptr noundef %0)
  %3 = and i32 %2, 251
  %4 = icmp eq i32 %3, 9
  br i1 %4, label %.critedge.backedge, label %switch.early.test

.critedge.backedge:                               ; preds = %.critedge, %switch.early.test, %switch.early.test
  br label %.critedge

switch.early.test:                                ; preds = %.critedge
  %sext = shl i32 %2, 24
  switch i32 %sext, label %5 [
    i32 536870912, label %.critedge.backedge
    i32 167772160, label %.critedge.backedge
  ]

5:                                                ; preds = %switch.early.test
  %6 = ashr exact i32 %sext, 24
  %7 = tail call i32 @ungetc(i32 noundef %6, ptr noundef %0)
  ret void
}

attributes #0 = { 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" }
attributes #1 = { mustprogress 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" }

!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: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass