; LLVM IR from tenok-rtos/tenok :: user/shell (cat)

; 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 { i8, i32, i32, i32, i32 }

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [24 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @cat(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca [128 x i8], align 16
  %7 = alloca [128 x i8], align 16
  %8 = alloca [100 x i8], align 16
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca %struct.stat, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 128, ptr %6) #5
  call void @llvm.memset.p0.i64(ptr align 16 %6, i8 0, i64 128, i1 false)
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = getelementptr inbounds ptr, ptr %15, i64 1
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %17, i64 0
  %19 = load i8, ptr %18, align 1, !tbaa !11
  %20 = sext i8 %19 to i32
  %21 = icmp ne i32 %20, 47
  br i1 %21, label %22, label %31

22:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 128, ptr %7) #5
  call void @llvm.memset.p0.i64(ptr align 16 %7, i8 0, i64 128, i1 false)
  %23 = getelementptr inbounds [128 x i8], ptr %7, i64 0, i64 0
  %24 = call ptr @getcwd(ptr noundef %23, i64 noundef 128)
  %25 = getelementptr inbounds [128 x i8], ptr %6, i64 0, i64 0
  %26 = getelementptr inbounds [128 x i8], ptr %7, i64 0, i64 0
  %27 = load ptr, ptr %5, align 8, !tbaa !9
  %28 = getelementptr inbounds ptr, ptr %27, i64 1
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %25, i64 noundef 128, ptr noundef @.str, ptr noundef %26, ptr noundef %29) #5
  call void @llvm.lifetime.end.p0(i64 128, ptr %7) #5
  br label %38

31:                                               ; preds = %2
  %32 = getelementptr inbounds [128 x i8], ptr %6, i64 0, i64 0
  %33 = load ptr, ptr %5, align 8, !tbaa !9
  %34 = getelementptr inbounds ptr, ptr %33, i64 1
  %35 = load ptr, ptr %34, align 8, !tbaa !9
  %36 = call ptr @strncpy(ptr noundef %32, ptr noundef %35, i64 noundef 127) #5
  %37 = getelementptr inbounds [128 x i8], ptr %6, i64 0, i64 127
  store i8 0, ptr %37, align 1, !tbaa !11
  br label %38

38:                                               ; preds = %31, %22
  call void @llvm.lifetime.start.p0(i64 100, ptr %8) #5
  call void @llvm.memset.p0.i64(ptr align 16 %8, i8 0, i64 100, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %39 = getelementptr inbounds [128 x i8], ptr %6, i64 0, i64 0
  %40 = call ptr @_fopen(ptr noundef %39, ptr noundef @.str.1)
  store ptr %40, ptr %9, align 8, !tbaa !9
  %41 = load ptr, ptr %9, align 8, !tbaa !9
  %42 = icmp ne ptr %41, null
  br i1 %42, label %48, label %43

43:                                               ; preds = %38
  %44 = getelementptr inbounds [100 x i8], ptr %8, i64 0, i64 0
  %45 = getelementptr inbounds [128 x i8], ptr %6, i64 0, i64 0
  %46 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %44, i64 noundef 100, ptr noundef @.str.2, ptr noundef %45) #5
  %47 = getelementptr inbounds [100 x i8], ptr %8, i64 0, i64 0
  call void @shell_puts(ptr noundef %47)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %85

48:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 20, ptr %11) #5
  %49 = load ptr, ptr %9, align 8, !tbaa !9
  %50 = call i32 @_fileno(ptr noundef %49)
  %51 = call i32 @fstat(i32 noundef %50, ptr noundef %11)
  %52 = load ptr, ptr %9, align 8, !tbaa !9
  %53 = call i32 @_fseek(ptr noundef %52, i64 noundef 0, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %54 = getelementptr inbounds %struct.stat, ptr %11, i32 0, i32 3
  %55 = load i32, ptr %54, align 4, !tbaa !12
  %56 = udiv i32 %55, 100
  store i32 %56, ptr %12, align 4, !tbaa !5
  %57 = getelementptr inbounds %struct.stat, ptr %11, i32 0, i32 3
  %58 = load i32, ptr %57, align 4, !tbaa !12
  %59 = urem i32 %58, 100
  %60 = icmp ugt i32 %59, 0
  br i1 %60, label %61, label %64

61:                                               ; preds = %48
  %62 = load i32, ptr %12, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %12, align 4, !tbaa !5
  br label %64

64:                                               ; preds = %61, %48
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %65

65:                                               ; preds = %79, %64
  %66 = load i32, ptr %13, align 4, !tbaa !5
  %67 = load i32, ptr %12, align 4, !tbaa !5
  %68 = icmp slt i32 %66, %67
  br i1 %68, label %70, label %69

69:                                               ; preds = %65
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  br label %82

70:                                               ; preds = %65
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %71 = getelementptr inbounds [100 x i8], ptr %8, i64 0, i64 0
  %72 = load ptr, ptr %9, align 8, !tbaa !9
  %73 = call i64 @_fread(ptr noundef %71, i64 noundef 99, i64 noundef 1, ptr noundef %72)
  %74 = trunc i64 %73 to i32
  store i32 %74, ptr %14, align 4, !tbaa !5
  %75 = load i32, ptr %14, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [100 x i8], ptr %8, i64 0, i64 %76
  store i8 0, ptr %77, align 1, !tbaa !11
  %78 = getelementptr inbounds [100 x i8], ptr %8, i64 0, i64 0
  call void @shell_puts(ptr noundef %78)
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  br label %79

79:                                               ; preds = %70
  %80 = load i32, ptr %13, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %13, align 4, !tbaa !5
  br label %65, !llvm.loop !14

82:                                               ; preds = %69
  %83 = load ptr, ptr %9, align 8, !tbaa !9
  %84 = call i32 @_fclose(ptr noundef %83)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 20, ptr %11) #5
  br label %85

85:                                               ; preds = %82, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 100, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 128, ptr %6) #5
  %86 = load i32, ptr %3, align 4
  ret i32 %86
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare ptr @getcwd(ptr noundef, i64 noundef) #3

; Function Attrs: nounwind
declare i32 @snprintf(ptr noundef, i64 noundef, ptr noundef, ...) #4

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

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #4

declare ptr @_fopen(ptr noundef, ptr noundef) #3

declare void @shell_puts(ptr noundef) #3

declare i32 @fstat(i32 noundef, ptr noundef) #3

declare i32 @_fileno(ptr noundef) #3

declare i32 @_fseek(ptr noundef, i64 noundef, i32 noundef) #3

declare i64 @_fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #3

declare i32 @_fclose(ptr noundef) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 = { 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 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 12}
!13 = !{!"stat", !7, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16}
!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"

%struct.stat = type { i8, i32, i32, i32, i32 }

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [24 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @cat(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca [128 x i8], align 16
  %4 = alloca [128 x i8], align 16
  %5 = alloca [100 x i8], align 16
  %6 = alloca %struct.stat, align 4
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %3) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(128) %3, i8 0, i64 128, i1 false)
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = load i8, ptr %8, align 1, !tbaa !9
  %.not = icmp eq i8 %9, 47
  br i1 %.not, label %14, label %10

10:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %4) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(128) %4, i8 0, i64 128, i1 false)
  %11 = call ptr @getcwd(ptr noundef nonnull %4, i64 noundef 128) #6
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %3, i64 noundef 128, ptr noundef nonnull @.str, ptr noundef nonnull %4, ptr noundef %12) #6
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %4) #6
  br label %16

14:                                               ; preds = %2
  %15 = call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) %8, i64 noundef 127) #6
  br label %16

16:                                               ; preds = %14, %10
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %5) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(100) %5, i8 0, i64 100, i1 false)
  %17 = call ptr @_fopen(ptr noundef nonnull %3, ptr noundef nonnull @.str.1) #6
  %.not16 = icmp eq ptr %17, null
  br i1 %.not16, label %18, label %20

18:                                               ; preds = %16
  %19 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %5, i64 noundef 100, ptr noundef nonnull @.str.2, ptr noundef nonnull %3) #6
  call void @shell_puts(ptr noundef nonnull %5) #6
  br label %34

20:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %6) #6
  %21 = call i32 @_fileno(ptr noundef nonnull %17) #6
  %22 = call i32 @fstat(i32 noundef %21, ptr noundef nonnull %6)
  %23 = call i32 @_fseek(ptr noundef nonnull %17, i64 noundef 0, i32 noundef 0) #6
  %24 = getelementptr inbounds i8, ptr %6, i64 12
  %25 = load i32, ptr %24, align 4, !tbaa !10
  %26 = udiv i32 %25, 100
  %27 = urem i32 %25, 100
  %.not17 = icmp ne i32 %27, 0
  %28 = zext i1 %.not17 to i32
  %spec.select = add nuw nsw i32 %26, %28
  %.not19 = icmp eq i32 %spec.select, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %20
  %29 = call i32 @_fclose(ptr noundef nonnull %17) #6
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %6) #6
  br label %34

.lr.ph:                                           ; preds = %20, %.lr.ph
  %.01318 = phi i32 [ %33, %.lr.ph ], [ 0, %20 ]
  %30 = call i64 @_fread(ptr noundef nonnull %5, i64 noundef 99, i64 noundef 1, ptr noundef nonnull %17) #6
  %sext = shl i64 %30, 32
  %31 = ashr exact i64 %sext, 32
  %32 = getelementptr inbounds [100 x i8], ptr %5, i64 0, i64 %31
  store i8 0, ptr %32, align 1, !tbaa !9
  call void @shell_puts(ptr noundef nonnull %5) #6
  %33 = add nuw nsw i32 %.01318, 1
  %exitcond.not = icmp eq i32 %33, %spec.select
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

34:                                               ; preds = %._crit_edge, %18
  %.0 = phi i32 [ 0, %._crit_edge ], [ 1, %18 ]
  call void @llvm.lifetime.end.p0(i64 100, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %3) #6
  ret i32 %.0
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare ptr @getcwd(ptr noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @snprintf(ptr noalias nocapture noundef writeonly, i64 noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #4

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #5

declare ptr @_fopen(ptr noundef, ptr noundef) local_unnamed_addr #3

declare void @shell_puts(ptr noundef) local_unnamed_addr #3

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

declare i32 @_fileno(ptr noundef) local_unnamed_addr #3

declare i32 @_fseek(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #3

declare i64 @_fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #3

declare i32 @_fclose(ptr noundef) local_unnamed_addr #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 }

!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 = !{!11, !12, i64 12}
!11 = !{!"stat", !7, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass