; LLVM IR from kala13x/libxutils :: examples (files)

; 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.XFile = type { i64, i32, i64, i64, i8, i8, i32, i32 }
%struct.XDir = type { ptr, ptr, ptr, ptr, i8, i8 }

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca %struct.XFile, align 8
  %7 = alloca %struct.XFile, align 8
  %8 = alloca i32, align 4
  %9 = alloca [2048 x i8], align 16
  %10 = alloca i32, align 4
  %11 = alloca %struct.XDir, align 8
  %12 = alloca [256 x i8], align 16
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @XLog_Init(ptr noundef @.str, i16 noundef zeroext 255, i8 noundef zeroext 0)
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = icmp slt i32 %13, 3
  br i1 %14, label %15, label %24

15:                                               ; preds = %2
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  %17 = getelementptr inbounds ptr, ptr %16, i64 0
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, ptr noundef %18)
  %20 = load ptr, ptr %5, align 8, !tbaa !9
  %21 = getelementptr inbounds ptr, ptr %20, i64 0
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %22)
  store i32 0, ptr %3, align 4
  br label %64

24:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 48, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 48, ptr %7) #4
  %25 = load ptr, ptr %5, align 8, !tbaa !9
  %26 = getelementptr inbounds ptr, ptr %25, i64 1
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = call i32 @XFile_Open(ptr noundef %6, ptr noundef %27, ptr noundef null, ptr noundef null)
  %29 = load ptr, ptr %5, align 8, !tbaa !9
  %30 = getelementptr inbounds ptr, ptr %29, i64 2
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = call i32 @XFile_Open(ptr noundef %7, ptr noundef %31, ptr noundef @.str.3, ptr noundef null)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %33 = call i32 @XFile_Copy(ptr noundef %6, ptr noundef %7)
  store i32 %33, ptr %8, align 4, !tbaa !5
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = icmp slt i32 %34, 0
  br i1 %35, label %36, label %39

36:                                               ; preds = %24
  %37 = call ptr @__errno_location() #5
  %38 = load i32, ptr %37, align 4, !tbaa !5
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef @.str.4, i32 noundef %38)
  br label %39

39:                                               ; preds = %36, %24
  call void @XFile_Close(ptr noundef %6)
  call void @XFile_Close(ptr noundef %7)
  %40 = load ptr, ptr %5, align 8, !tbaa !9
  %41 = getelementptr inbounds ptr, ptr %40, i64 1
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  %43 = call i32 @XFile_Open(ptr noundef %6, ptr noundef %42, ptr noundef null, ptr noundef null)
  %44 = call i32 @XFile_GetLineCount(ptr noundef %6)
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 16, i8 noundef zeroext 1, ptr noundef @.str.5, i32 noundef %44)
  %45 = call i64 @XFile_Seek(ptr noundef %6, i64 noundef 0, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 2048, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 2, ptr %10, align 4, !tbaa !5
  %46 = getelementptr inbounds [2048 x i8], ptr %9, i64 0, i64 0
  %47 = load i32, ptr %10, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = call i32 @XFile_ReadLine(ptr noundef %6, ptr noundef %46, i64 noundef 2048, i64 noundef %48)
  %50 = icmp sgt i32 %49, 0
  br i1 %50, label %51, label %54

51:                                               ; preds = %39
  %52 = load i32, ptr %10, align 4, !tbaa !5
  %53 = getelementptr inbounds [2048 x i8], ptr %9, i64 0, i64 0
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 16, i8 noundef zeroext 1, ptr noundef @.str.6, i32 noundef %52, ptr noundef %53)
  br label %54

54:                                               ; preds = %51, %39
  call void @XFile_Close(ptr noundef %6)
  call void @llvm.lifetime.start.p0(i64 40, ptr %11) #4
  %55 = call i32 @XDir_Open(ptr noundef %11, ptr noundef @.str.7)
  call void @llvm.lifetime.start.p0(i64 256, ptr %12) #4
  br label %56

56:                                               ; preds = %60, %54
  %57 = getelementptr inbounds [256 x i8], ptr %12, i64 0, i64 0
  %58 = call i32 @XDir_Read(ptr noundef %11, ptr noundef %57, i64 noundef 256)
  %59 = icmp sgt i32 %58, 0
  br i1 %59, label %60, label %63

60:                                               ; preds = %56
  %61 = getelementptr inbounds [256 x i8], ptr %12, i64 0, i64 0
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 4, i8 noundef zeroext 1, ptr noundef @.str.8, ptr noundef %61)
  %62 = getelementptr inbounds [256 x i8], ptr %12, i64 0, i64 0
  store i8 0, ptr %62, align 16, !tbaa !11
  br label %56, !llvm.loop !12

63:                                               ; preds = %56
  call void @XDir_Close(ptr noundef %11)
  store i32 0, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 256, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 2048, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 48, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 48, ptr %6) #4
  br label %64

64:                                               ; preds = %63, %15
  %65 = load i32, ptr %3, align 4
  ret i32 %65
}

declare void @XLog_Init(ptr noundef, i16 noundef zeroext, i8 noundef zeroext) #1

declare i32 @printf(ptr noundef, ...) #1

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

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

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

declare void @XLog_Display(i32 noundef, i8 noundef zeroext, ptr noundef, ...) #1

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #3

declare void @XFile_Close(ptr noundef) #1

declare i32 @XFile_GetLineCount(ptr noundef) #1

declare i64 @XFile_Seek(ptr noundef, i64 noundef, i32 noundef) #1

declare i32 @XFile_ReadLine(ptr noundef, ptr noundef, i64 noundef, i64 noundef) #1

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

declare i32 @XDir_Read(ptr noundef, ptr noundef, i64 noundef) #1

declare void @XDir_Close(ptr noundef) #1

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

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 = { "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 = { nounwind willreturn memory(none) "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 }
attributes #5 = { nounwind willreturn memory(none) }

!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 = distinct !{!12, !13}
!13 = !{!"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.XFile = type { i64, i32, i64, i64, i8, i8, i32, i32 }
%struct.XDir = type { ptr, ptr, ptr, ptr, i8, i8 }

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca %struct.XFile, align 8
  %4 = alloca %struct.XFile, align 8
  %5 = alloca [2048 x i8], align 16
  %6 = alloca %struct.XDir, align 8
  %7 = alloca [256 x i8], align 16
  tail call void @XLog_Init(ptr noundef nonnull @.str, i16 noundef zeroext 255, i8 noundef zeroext 0) #5
  %8 = icmp slt i32 %0, 3
  br i1 %8, label %9, label %14

9:                                                ; preds = %2
  %10 = load ptr, ptr %1, align 8, !tbaa !5
  %11 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef %10)
  %12 = load ptr, ptr %1, align 8, !tbaa !5
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef %12)
  br label %40

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %4) #5
  %15 = getelementptr inbounds i8, ptr %1, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = call i32 @XFile_Open(ptr noundef nonnull %3, ptr noundef %16, ptr noundef null, ptr noundef null) #5
  %18 = getelementptr inbounds i8, ptr %1, i64 16
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = call i32 @XFile_Open(ptr noundef nonnull %4, ptr noundef %19, ptr noundef nonnull @.str.3, ptr noundef null) #5
  %21 = call i32 @XFile_Copy(ptr noundef nonnull %3, ptr noundef nonnull %4) #5
  %22 = icmp slt i32 %21, 0
  br i1 %22, label %23, label %26

23:                                               ; preds = %14
  %24 = tail call ptr @__errno_location() #6
  %25 = load i32, ptr %24, align 4, !tbaa !9
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 64, i8 noundef zeroext 1, ptr noundef nonnull @.str.4, i32 noundef %25) #5
  br label %26

26:                                               ; preds = %23, %14
  call void @XFile_Close(ptr noundef nonnull %3) #5
  call void @XFile_Close(ptr noundef nonnull %4) #5
  %27 = load ptr, ptr %15, align 8, !tbaa !5
  %28 = call i32 @XFile_Open(ptr noundef nonnull %3, ptr noundef %27, ptr noundef null, ptr noundef null) #5
  %29 = call i32 @XFile_GetLineCount(ptr noundef nonnull %3) #5
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 16, i8 noundef zeroext 1, ptr noundef nonnull @.str.5, i32 noundef %29) #5
  %30 = call i64 @XFile_Seek(ptr noundef nonnull %3, i64 noundef 0, i32 noundef 0) #5
  call void @llvm.lifetime.start.p0(i64 2048, ptr nonnull %5) #5
  %31 = call i32 @XFile_ReadLine(ptr noundef nonnull %3, ptr noundef nonnull %5, i64 noundef 2048, i64 noundef 2) #5
  %32 = icmp sgt i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %26
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 16, i8 noundef zeroext 1, ptr noundef nonnull @.str.6, i32 noundef 2, ptr noundef nonnull %5) #5
  br label %34

34:                                               ; preds = %33, %26
  call void @XFile_Close(ptr noundef nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %6) #5
  %35 = call i32 @XDir_Open(ptr noundef nonnull %6, ptr noundef nonnull @.str.7) #5
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %7) #5
  %36 = call i32 @XDir_Read(ptr noundef nonnull %6, ptr noundef nonnull %7, i64 noundef 256) #5
  %37 = icmp sgt i32 %36, 0
  br i1 %37, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %34, %.lr.ph
  call void (i32, i8, ptr, ...) @XLog_Display(i32 noundef 4, i8 noundef zeroext 1, ptr noundef nonnull @.str.8, ptr noundef nonnull %7) #5
  store i8 0, ptr %7, align 16, !tbaa !11
  %38 = call i32 @XDir_Read(ptr noundef nonnull %6, ptr noundef nonnull %7, i64 noundef 256) #5
  %39 = icmp sgt i32 %38, 0
  br i1 %39, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %34
  call void @XDir_Close(ptr noundef nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 2048, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %3) #5
  br label %40

40:                                               ; preds = %._crit_edge, %9
  ret i32 0
}

declare void @XLog_Init(ptr noundef, i16 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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

declare i32 @XFile_Open(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @XFile_Copy(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @XLog_Display(i32 noundef, i8 noundef zeroext, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #4

declare void @XFile_Close(ptr noundef) local_unnamed_addr #1

declare i32 @XFile_GetLineCount(ptr noundef) local_unnamed_addr #1

declare i64 @XFile_Seek(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

declare i32 @XFile_ReadLine(ptr noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

declare i32 @XDir_Open(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @XDir_Read(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare void @XDir_Close(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { "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 = { 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 #3 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { nounwind willreturn memory(none) }

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


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