; LLVM IR from Gottox/sqsh-tools :: examples (read_file_ll)

; 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.SqshConfig = type { i64, i64, ptr, i32, i32, i32, i64, i32, i32, [128 x i8] }

@.str = external hidden unnamed_addr constant [30 x i8], align 1
@sqsh_mapper_impl_mmap = external constant ptr, align 8
@.str.1 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [23 x i8], align 1
@stdout = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [24 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 i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca %struct.SqshConfig, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  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 @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = icmp ne i32 %14, 3
  br i1 %15, label %16, label %21

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

21:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 184, ptr %8) #4
  call void @llvm.memset.p0.i64(ptr align 8 %8, i8 0, i64 184, i1 false)
  %22 = getelementptr inbounds %struct.SqshConfig, ptr %8, i32 0, i32 0
  %23 = getelementptr inbounds %struct.SqshConfig, ptr %8, i32 0, i32 1
  %24 = getelementptr inbounds %struct.SqshConfig, ptr %8, i32 0, i32 2
  %25 = load ptr, ptr @sqsh_mapper_impl_mmap, align 8, !tbaa !9
  store ptr %25, ptr %24, align 8, !tbaa !11
  %26 = getelementptr inbounds %struct.SqshConfig, ptr %8, i32 0, i32 3
  %27 = getelementptr inbounds %struct.SqshConfig, ptr %8, i32 0, i32 4
  %28 = getelementptr inbounds %struct.SqshConfig, ptr %8, i32 0, i32 5
  %29 = getelementptr inbounds %struct.SqshConfig, ptr %8, i32 0, i32 6
  %30 = getelementptr inbounds %struct.SqshConfig, ptr %8, i32 0, i32 7
  %31 = getelementptr inbounds %struct.SqshConfig, ptr %8, i32 0, i32 8
  %32 = getelementptr inbounds %struct.SqshConfig, ptr %8, i32 0, i32 9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %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 @sqsh_archive_open(ptr noundef %35, ptr noundef %8, ptr noundef %6)
  store ptr %36, ptr %9, align 8, !tbaa !9
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %41

39:                                               ; preds = %21
  %40 = load i32, ptr %6, align 4, !tbaa !5
  call void @sqsh_perror(i32 noundef %40, ptr noundef @.str.1)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %85

41:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %42 = load ptr, ptr %9, align 8, !tbaa !9
  %43 = load ptr, ptr %5, align 8, !tbaa !9
  %44 = getelementptr inbounds ptr, ptr %43, i64 2
  %45 = load ptr, ptr %44, align 8, !tbaa !9
  %46 = call ptr @sqsh_open(ptr noundef %42, ptr noundef %45, ptr noundef %6)
  store ptr %46, ptr %10, align 8, !tbaa !9
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %51

49:                                               ; preds = %41
  %50 = load i32, ptr %6, align 4, !tbaa !5
  call void @sqsh_perror(i32 noundef %50, ptr noundef @.str.2)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %84

51:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %52 = load ptr, ptr %10, align 8, !tbaa !9
  %53 = call ptr @sqsh_file_iterator_new(ptr noundef %52, ptr noundef %6)
  store ptr %53, ptr %11, align 8, !tbaa !9
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %58

56:                                               ; preds = %51
  %57 = load i32, ptr %6, align 4, !tbaa !5
  call void @sqsh_perror(i32 noundef %57, ptr noundef @.str.3)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %83

58:                                               ; preds = %51
  br label %59

59:                                               ; preds = %62, %58
  %60 = load ptr, ptr %11, align 8, !tbaa !9
  %61 = call zeroext i1 @sqsh_file_iterator_next(ptr noundef %60, i64 noundef -1, ptr noundef %6)
  br i1 %61, label %62, label %71

62:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %63 = load ptr, ptr %11, align 8, !tbaa !9
  %64 = call ptr @sqsh_file_iterator_data(ptr noundef %63)
  store ptr %64, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %65 = load ptr, ptr %11, align 8, !tbaa !9
  %66 = call i64 @sqsh_file_iterator_size(ptr noundef %65)
  store i64 %66, ptr %13, align 8, !tbaa !14
  %67 = load ptr, ptr %12, align 8, !tbaa !9
  %68 = load i64, ptr %13, align 8, !tbaa !14
  %69 = load ptr, ptr @stdout, align 8, !tbaa !9
  %70 = call i64 @fwrite(ptr noundef %67, i64 noundef %68, i64 noundef 1, ptr noundef %69)
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %59, !llvm.loop !15

71:                                               ; preds = %59
  %72 = load i32, ptr %6, align 4, !tbaa !5
  %73 = icmp slt i32 %72, 0
  br i1 %73, label %74, label %76

74:                                               ; preds = %71
  %75 = load i32, ptr %6, align 4, !tbaa !5
  call void @sqsh_perror(i32 noundef %75, ptr noundef @.str.4)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %83

76:                                               ; preds = %71
  %77 = load ptr, ptr %11, align 8, !tbaa !9
  %78 = call i32 @sqsh_file_iterator_free(ptr noundef %77)
  %79 = load ptr, ptr %10, align 8, !tbaa !9
  %80 = call i32 @sqsh_close(ptr noundef %79)
  %81 = load ptr, ptr %9, align 8, !tbaa !9
  %82 = call i32 @sqsh_archive_close(ptr noundef %81)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %83

83:                                               ; preds = %76, %74, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %84

84:                                               ; preds = %83, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %85

85:                                               ; preds = %84, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 184, ptr %8) #4
  br label %86

86:                                               ; preds = %85, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %87 = load i32, ptr %3, align 4
  ret i32 %87
}

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

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

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

declare ptr @sqsh_archive_open(ptr noundef, ptr noundef, ptr noundef) #2

declare void @sqsh_perror(i32 noundef, ptr noundef) #2

declare ptr @sqsh_open(ptr noundef, ptr noundef, ptr noundef) #2

declare ptr @sqsh_file_iterator_new(ptr noundef, ptr noundef) #2

declare zeroext i1 @sqsh_file_iterator_next(ptr noundef, i64 noundef, ptr noundef) #2

declare ptr @sqsh_file_iterator_data(ptr noundef) #2

declare i64 @sqsh_file_iterator_size(ptr noundef) #2

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

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

declare i32 @sqsh_file_iterator_free(ptr noundef) #2

declare i32 @sqsh_close(ptr noundef) #2

declare i32 @sqsh_archive_close(ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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 = !{!12, !10, i64 16}
!12 = !{!"SqshConfig", !13, i64 0, !13, i64 8, !10, i64 16, !6, i64 24, !6, i64 28, !6, i64 32, !13, i64 40, !6, i64 48, !6, i64 52, !7, i64 56}
!13 = !{!"long", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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.SqshConfig = type { i64, i64, ptr, i32, i32, i32, i64, i32, i32, [128 x i8] }

@.str = external hidden unnamed_addr constant [30 x i8], align 1
@sqsh_mapper_impl_mmap = external local_unnamed_addr constant ptr, align 8
@.str.1 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [23 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [24 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = alloca %struct.SqshConfig, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #5
  store i32 0, ptr %3, align 4, !tbaa !5
  %.not = icmp eq i32 %0, 3
  br i1 %.not, label %8, label %5

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

8:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 184, ptr nonnull %4) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(184) %4, i8 0, i64 184, i1 false)
  %9 = getelementptr inbounds i8, ptr %4, i64 16
  %10 = load ptr, ptr @sqsh_mapper_impl_mmap, align 8, !tbaa !9
  store ptr %10, ptr %9, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %1, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = call ptr @sqsh_archive_open(ptr noundef %12, ptr noundef nonnull %4, ptr noundef nonnull %3) #5
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %.not18 = icmp eq i32 %14, 0
  br i1 %.not18, label %16, label %15

15:                                               ; preds = %8
  call void @sqsh_perror(i32 noundef %14, ptr noundef nonnull @.str.1) #5
  br label %39

16:                                               ; preds = %8
  %17 = getelementptr inbounds i8, ptr %1, i64 16
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = call ptr @sqsh_open(ptr noundef %13, ptr noundef %18, ptr noundef nonnull %3) #5
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %.not19 = icmp eq i32 %20, 0
  br i1 %.not19, label %22, label %21

21:                                               ; preds = %16
  call void @sqsh_perror(i32 noundef %20, ptr noundef nonnull @.str.2) #5
  br label %39

22:                                               ; preds = %16
  %23 = call ptr @sqsh_file_iterator_new(ptr noundef %19, ptr noundef nonnull %3) #5
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %.not20 = icmp eq i32 %24, 0
  br i1 %.not20, label %.preheader, label %26

.preheader:                                       ; preds = %22
  %25 = call zeroext i1 @sqsh_file_iterator_next(ptr noundef %23, i64 noundef -1, ptr noundef nonnull %3) #5
  br i1 %25, label %.lr.ph, label %._crit_edge

26:                                               ; preds = %22
  call void @sqsh_perror(i32 noundef %24, ptr noundef nonnull @.str.3) #5
  br label %39

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %27 = call ptr @sqsh_file_iterator_data(ptr noundef %23) #5
  %28 = call i64 @sqsh_file_iterator_size(ptr noundef %23) #5
  %29 = load ptr, ptr @stdout, align 8, !tbaa !9
  %30 = call i64 @fwrite(ptr noundef %27, i64 noundef %28, i64 noundef 1, ptr noundef %29)
  %31 = call zeroext i1 @sqsh_file_iterator_next(ptr noundef %23, i64 noundef -1, ptr noundef nonnull %3) #5
  br i1 %31, label %.lr.ph, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = icmp slt i32 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %._crit_edge
  call void @sqsh_perror(i32 noundef %32, ptr noundef nonnull @.str.4) #5
  br label %39

35:                                               ; preds = %._crit_edge
  %36 = call i32 @sqsh_file_iterator_free(ptr noundef %23) #5
  %37 = call i32 @sqsh_close(ptr noundef %19) #5
  %38 = call i32 @sqsh_archive_close(ptr noundef %13) #5
  br label %39

39:                                               ; preds = %21, %35, %34, %26, %15
  %.2 = phi i32 [ 1, %15 ], [ 1, %21 ], [ 1, %26 ], [ 1, %34 ], [ 0, %35 ]
  call void @llvm.lifetime.end.p0(i64 184, ptr nonnull %4) #5
  br label %40

40:                                               ; preds = %39, %5
  %.3 = phi i32 [ 1, %5 ], [ %.2, %39 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #5
  ret i32 %.3
}

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

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

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

declare ptr @sqsh_archive_open(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

declare void @sqsh_perror(i32 noundef, ptr noundef) local_unnamed_addr #4

declare ptr @sqsh_open(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

declare ptr @sqsh_file_iterator_new(ptr noundef, ptr noundef) local_unnamed_addr #4

declare zeroext i1 @sqsh_file_iterator_next(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #4

declare ptr @sqsh_file_iterator_data(ptr noundef) local_unnamed_addr #4

declare i64 @sqsh_file_iterator_size(ptr noundef) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #2

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

declare i32 @sqsh_file_iterator_free(ptr noundef) local_unnamed_addr #4

declare i32 @sqsh_close(ptr noundef) local_unnamed_addr #4

declare i32 @sqsh_archive_close(ptr noundef) local_unnamed_addr #4

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 = { 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 nounwind willreturn memory(argmem: write) }
attributes #4 = { "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 = !{!12, !10, i64 16}
!12 = !{!"SqshConfig", !13, i64 0, !13, i64 8, !10, i64 16, !6, i64 24, !6, i64 28, !6, i64 32, !13, i64 40, !6, i64 48, !6, i64 52, !7, i64 56}
!13 = !{!"long", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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