; LLVM IR from holzschu/ios_system :: shell_cmds/hexdump (display)

; 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.stat = type { i64, i64, i64, i32, i32, i32, i32, i64, i64, i64, i64, %struct.timespec, %struct.timespec, %struct.timespec, [3 x i64] }
%struct.timespec = type { i64, i64 }

@address = external hidden global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@skip = external global i64, align 8
@stdin = external 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: noreturn
declare void @err(i32 noundef, ptr noundef, ...) #1

; Function Attrs: inlinehint nounwind uwtable
declare i32 @getchar() #2

; Function Attrs: nounwind uwtable
define dso_local void @doskip(ptr noundef %0, i32 noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca %struct.stat, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.start.p0(i64 144, ptr %6) #6
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %37

10:                                               ; preds = %2
  %11 = load ptr, ptr @stdin, align 8, !tbaa !5
  %12 = call i32 @fileno(ptr noundef %11) #6
  %13 = call i32 @fstat(i32 noundef %12, ptr noundef %6) #6
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %17

15:                                               ; preds = %10
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef @.str, ptr noundef %16) #7
  unreachable

17:                                               ; preds = %10
  %18 = getelementptr inbounds %struct.stat, ptr %6, i32 0, i32 3
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = and i32 %19, 61440
  %21 = icmp eq i32 %20, 32768
  br i1 %21, label %22, label %36

22:                                               ; preds = %17
  %23 = load i64, ptr @skip, align 8, !tbaa !15
  %24 = getelementptr inbounds %struct.stat, ptr %6, i32 0, i32 8
  %25 = load i64, ptr %24, align 8, !tbaa !16
  %26 = icmp sge i64 %23, %25
  br i1 %26, label %27, label %36

27:                                               ; preds = %22
  %28 = getelementptr inbounds %struct.stat, ptr %6, i32 0, i32 8
  %29 = load i64, ptr %28, align 8, !tbaa !16
  %30 = load i64, ptr @address, align 8, !tbaa !15
  %31 = add nsw i64 %30, %29
  store i64 %31, ptr @address, align 8, !tbaa !15
  %32 = getelementptr inbounds %struct.stat, ptr %6, i32 0, i32 8
  %33 = load i64, ptr %32, align 8, !tbaa !16
  %34 = load i64, ptr @skip, align 8, !tbaa !15
  %35 = sub nsw i64 %34, %33
  store i64 %35, ptr @skip, align 8, !tbaa !15
  store i32 1, ptr %7, align 4
  br label %77

36:                                               ; preds = %22, %17
  br label %37

37:                                               ; preds = %36, %2
  %38 = getelementptr inbounds %struct.stat, ptr %6, i32 0, i32 3
  %39 = load i32, ptr %38, align 8, !tbaa !11
  %40 = and i32 %39, 61440
  %41 = icmp eq i32 %40, 32768
  br i1 %41, label %42, label %53

42:                                               ; preds = %37
  %43 = load ptr, ptr @stdin, align 8, !tbaa !5
  %44 = load i64, ptr @skip, align 8, !tbaa !15
  %45 = call i32 @fseeko(ptr noundef %43, i64 noundef %44, i32 noundef 0)
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %49

47:                                               ; preds = %42
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef @.str, ptr noundef %48) #7
  unreachable

49:                                               ; preds = %42
  %50 = load i64, ptr @skip, align 8, !tbaa !15
  %51 = load i64, ptr @address, align 8, !tbaa !15
  %52 = add nsw i64 %51, %50
  store i64 %52, ptr @address, align 8, !tbaa !15
  store i64 0, ptr @skip, align 8, !tbaa !15
  br label %76

53:                                               ; preds = %37
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %64, %53
  %55 = load i32, ptr %5, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = load i64, ptr @skip, align 8, !tbaa !15
  %58 = icmp slt i64 %56, %57
  br i1 %58, label %59, label %67

59:                                               ; preds = %54
  %60 = call i32 @getchar()
  %61 = icmp eq i32 %60, -1
  br i1 %61, label %62, label %63

62:                                               ; preds = %59
  br label %67

63:                                               ; preds = %59
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %5, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %5, align 4, !tbaa !9
  br label %54, !llvm.loop !17

67:                                               ; preds = %62, %54
  %68 = load i32, ptr %5, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = load i64, ptr @address, align 8, !tbaa !15
  %71 = add nsw i64 %70, %69
  store i64 %71, ptr @address, align 8, !tbaa !15
  %72 = load i32, ptr %5, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = load i64, ptr @skip, align 8, !tbaa !15
  %75 = sub nsw i64 %74, %73
  store i64 %75, ptr @skip, align 8, !tbaa !15
  br label %76

76:                                               ; preds = %67, %49
  store i32 0, ptr %7, align 4
  br label %77

77:                                               ; preds = %76, %27
  call void @llvm.lifetime.end.p0(i64 144, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  %78 = load i32, ptr %7, align 4
  switch i32 %78, label %80 [
    i32 0, label %79
    i32 1, label %79
  ]

79:                                               ; preds = %77, %77
  ret void

80:                                               ; preds = %77
  unreachable
}

; Function Attrs: nounwind
declare i32 @fstat(i32 noundef, ptr noundef) #4

; Function Attrs: nounwind
declare i32 @fileno(ptr noundef) #4

declare i32 @fseeko(ptr noundef, i64 noundef, i32 noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn "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 = { inlinehint 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 #3 = { 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 #4 = { 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 #5 = { "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 #6 = { nounwind }
attributes #7 = { noreturn }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"stat", !13, i64 0, !13, i64 8, !13, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !14, i64 72, !14, i64 88, !14, i64 104, !7, i64 120}
!13 = !{!"long", !7, i64 0}
!14 = !{!"timespec", !13, i64 0, !13, i64 8}
!15 = !{!13, !13, i64 0}
!16 = !{!12, !13, i64 48}
!17 = distinct !{!17, !18}
!18 = !{!"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"

%struct.stat = type { i64, i64, i64, i32, i32, i32, i32, i64, i64, i64, i64, %struct.timespec, %struct.timespec, %struct.timespec, [3 x i64] }
%struct.timespec = type { i64, i64 }

@address = external hidden local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@skip = external local_unnamed_addr global i64, align 8
@stdin = external local_unnamed_addr global ptr, align 8

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

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

; Function Attrs: noreturn
declare void @err(i32 noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: inlinehint nofree nounwind uwtable
declare noundef i32 @getchar() local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @doskip(ptr noundef %0, i32 noundef %1) local_unnamed_addr #3 {
  %3 = alloca %struct.stat, align 8
  call void @llvm.lifetime.start.p0(i64 144, ptr nonnull %3) #5
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %.preheader, label %4

4:                                                ; preds = %2
  %5 = load ptr, ptr @stdin, align 8, !tbaa !5
  %6 = tail call i32 @fileno(ptr noundef %5) #5
  %7 = call i32 @fstat(i32 noundef %6, ptr noundef nonnull %3) #5
  %.not7 = icmp eq i32 %7, 0
  br i1 %.not7, label %9, label %8

8:                                                ; preds = %4
  tail call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef nonnull @.str, ptr noundef %0) #6
  unreachable

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %3, i64 24
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = and i32 %11, 61440
  %13 = icmp eq i32 %12, 32768
  br i1 %13, label %14, label %22

14:                                               ; preds = %9
  %15 = load i64, ptr @skip, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %3, i64 48
  %17 = load i64, ptr %16, align 8, !tbaa !15
  %.not8 = icmp slt i64 %15, %17
  br i1 %.not8, label %22, label %18

18:                                               ; preds = %14
  %19 = load i64, ptr @address, align 8, !tbaa !14
  %20 = add nsw i64 %19, %17
  store i64 %20, ptr @address, align 8, !tbaa !14
  %21 = sub nsw i64 %15, %17
  br label %44

22:                                               ; preds = %9, %14
  %23 = and i32 %11, 61440
  %24 = icmp eq i32 %23, 32768
  br i1 %24, label %27, label %.preheader

.preheader:                                       ; preds = %2, %22
  %25 = load i64, ptr @skip, align 8, !tbaa !14
  %26 = icmp sgt i64 %25, 0
  br i1 %26, label %.lr.ph, label %._crit_edge

27:                                               ; preds = %22
  %28 = load ptr, ptr @stdin, align 8, !tbaa !5
  %29 = load i64, ptr @skip, align 8, !tbaa !14
  %30 = tail call i32 @fseeko(ptr noundef %28, i64 noundef %29, i32 noundef 0)
  %.not9 = icmp eq i32 %30, 0
  br i1 %.not9, label %32, label %31

31:                                               ; preds = %27
  tail call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef nonnull @.str, ptr noundef %0) #6
  unreachable

32:                                               ; preds = %27
  %33 = load i64, ptr @skip, align 8, !tbaa !14
  %34 = load i64, ptr @address, align 8, !tbaa !14
  %35 = add nsw i64 %34, %33
  store i64 %35, ptr @address, align 8, !tbaa !14
  br label %44

36:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %37 = icmp sgt i64 %.pre.pre, %indvars.iv.next
  br i1 %37, label %.lr.ph, label %._crit_edge, !llvm.loop !16

.lr.ph:                                           ; preds = %.preheader, %36
  %indvars.iv = phi i64 [ %indvars.iv.next, %36 ], [ 0, %.preheader ]
  %38 = tail call i32 @getchar()
  %39 = icmp eq i32 %38, -1
  %.pre.pre = load i64, ptr @skip, align 8, !tbaa !14
  br i1 %39, label %._crit_edge, label %36

._crit_edge:                                      ; preds = %36, %.lr.ph, %.preheader
  %40 = phi i64 [ %25, %.preheader ], [ %.pre.pre, %.lr.ph ], [ %.pre.pre, %36 ]
  %.lcssa = phi i64 [ 0, %.preheader ], [ %indvars.iv.next, %36 ], [ %indvars.iv, %.lr.ph ]
  %41 = load i64, ptr @address, align 8, !tbaa !14
  %42 = add nsw i64 %41, %.lcssa
  store i64 %42, ptr @address, align 8, !tbaa !14
  %43 = sub nsw i64 %40, %.lcssa
  br label %44

44:                                               ; preds = %32, %._crit_edge, %18
  %storemerge10 = phi i64 [ %21, %18 ], [ %43, %._crit_edge ], [ 0, %32 ]
  store i64 %storemerge10, ptr @skip, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 144, ptr nonnull %3) #5
  ret void
}

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @fseeko(ptr nocapture noundef, i64 noundef, i32 noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn "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 = { inlinehint 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 #3 = { 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { noreturn 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, !12, i64 24}
!10 = !{!"stat", !11, i64 0, !11, i64 8, !11, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !13, i64 72, !13, i64 88, !13, i64 104, !7, i64 120}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"timespec", !11, i64 0, !11, i64 8}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !11, i64 48}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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