; LLVM IR from marcinbor85/microshell :: examples/demo_linux/fs/path (dev)

; 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.ush_node_object = type { ptr, i64, ptr, ptr, ptr, ptr }
%struct.ush_file_descriptor = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@g_rom_buffer = external hidden global [1024 x i8], align 16
@g_eeprom_buffer = external hidden global [32 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@g_dev = external hidden global %struct.ush_node_object, align 8
@g_dev_desc = external hidden constant [2 x %struct.ush_file_descriptor], align 16
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@g_dev_bus = external hidden global %struct.ush_node_object, align 8
@g_dev_bus_desc = external hidden constant [2 x %struct.ush_file_descriptor], align 16
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@g_dev_mem = external hidden global %struct.ush_node_object, align 8
@g_dev_mem_desc = external hidden constant [3 x %struct.ush_file_descriptor], align 16

; Function Attrs: nounwind uwtable
define dso_local void @dev_mount(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = call i64 @time(ptr noundef null) #4
  %6 = trunc i64 %5 to i32
  call void @srand(i32 noundef %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 0, ptr %3, align 8, !tbaa !9
  br label %7

7:                                                ; preds = %16, %1
  %8 = load i64, ptr %3, align 8, !tbaa !9
  %9 = icmp ult i64 %8, 1024
  br i1 %9, label %11, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %19

11:                                               ; preds = %7
  %12 = call i32 @rand() #4
  %13 = trunc i32 %12 to i8
  %14 = load i64, ptr %3, align 8, !tbaa !9
  %15 = getelementptr inbounds [1024 x i8], ptr @g_rom_buffer, i64 0, i64 %14
  store i8 %13, ptr %15, align 1, !tbaa !11
  br label %16

16:                                               ; preds = %11
  %17 = load i64, ptr %3, align 8, !tbaa !9
  %18 = add i64 %17, 1
  store i64 %18, ptr %3, align 8, !tbaa !9
  br label %7, !llvm.loop !12

19:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 0, ptr %4, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %27, %19
  %21 = load i64, ptr %4, align 8, !tbaa !9
  %22 = icmp ult i64 %21, 32
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %30

24:                                               ; preds = %20
  %25 = load i64, ptr %4, align 8, !tbaa !9
  %26 = getelementptr inbounds [32 x i8], ptr @g_eeprom_buffer, i64 0, i64 %25
  store i8 -1, ptr %26, align 1, !tbaa !11
  br label %27

27:                                               ; preds = %24
  %28 = load i64, ptr %4, align 8, !tbaa !9
  %29 = add i64 %28, 1
  store i64 %29, ptr %4, align 8, !tbaa !9
  br label %20, !llvm.loop !14

30:                                               ; preds = %23
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = call i32 @ush_node_mount(ptr noundef %31, ptr noundef @.str, ptr noundef @g_dev, ptr noundef @g_dev_desc, i64 noundef 2)
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = call i32 @ush_node_mount(ptr noundef %33, ptr noundef @.str.1, ptr noundef @g_dev_bus, ptr noundef @g_dev_bus_desc, i64 noundef 2)
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = call i32 @ush_node_mount(ptr noundef %35, ptr noundef @.str.2, ptr noundef @g_dev_mem, ptr noundef @g_dev_mem_desc, i64 noundef 3)
  ret void
}

; Function Attrs: nounwind
declare void @srand(i32 noundef) #1

; Function Attrs: nounwind
declare i64 @time(ptr noundef) #1

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

; Function Attrs: nounwind
declare i32 @rand() #1

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

declare i32 @ush_node_mount(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }

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


; 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.ush_node_object = type { ptr, i64, ptr, ptr, ptr, ptr }
%struct.ush_file_descriptor = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@g_rom_buffer = external hidden local_unnamed_addr global [1024 x i8], align 16
@g_eeprom_buffer = external hidden local_unnamed_addr global [32 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@g_dev = external hidden global %struct.ush_node_object, align 8
@g_dev_desc = external hidden constant [2 x %struct.ush_file_descriptor], align 16
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@g_dev_bus = external hidden global %struct.ush_node_object, align 8
@g_dev_bus_desc = external hidden constant [2 x %struct.ush_file_descriptor], align 16
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@g_dev_mem = external hidden global %struct.ush_node_object, align 8
@g_dev_mem_desc = external hidden constant [3 x %struct.ush_file_descriptor], align 16

; Function Attrs: nounwind uwtable
define dso_local void @dev_mount(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i64 @time(ptr noundef null) #4
  %3 = trunc i64 %2 to i32
  tail call void @srand(i32 noundef %3) #4
  br label %4

4:                                                ; preds = %1, %4
  %.089 = phi i64 [ 0, %1 ], [ %8, %4 ]
  %5 = tail call i32 @rand() #4
  %6 = trunc i32 %5 to i8
  %7 = getelementptr inbounds [1024 x i8], ptr @g_rom_buffer, i64 0, i64 %.089
  store i8 %6, ptr %7, align 1, !tbaa !5
  %8 = add nuw nsw i64 %.089, 1
  %exitcond.not = icmp eq i64 %8, 1024
  br i1 %exitcond.not, label %.preheader.preheader, label %4, !llvm.loop !8

.preheader.preheader:                             ; preds = %4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) @g_eeprom_buffer, i8 -1, i64 32, i1 false), !tbaa !5
  %9 = tail call i32 @ush_node_mount(ptr noundef %0, ptr noundef nonnull @.str, ptr noundef nonnull @g_dev, ptr noundef nonnull @g_dev_desc, i64 noundef 2) #4
  %10 = tail call i32 @ush_node_mount(ptr noundef %0, ptr noundef nonnull @.str.1, ptr noundef nonnull @g_dev_bus, ptr noundef nonnull @g_dev_bus_desc, i64 noundef 2) #4
  %11 = tail call i32 @ush_node_mount(ptr noundef %0, ptr noundef nonnull @.str.2, ptr noundef nonnull @g_dev_mem, ptr noundef nonnull @g_dev_mem_desc, i64 noundef 3) #4
  ret void
}

; Function Attrs: nounwind
declare void @srand(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i64 @time(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #1

declare i32 @ush_node_mount(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass