; LLVM IR from Gottox/sqsh-tools :: test/tools (read-chunk)

; 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"

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [36 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [25 x i8], align 1
@stdout = external global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [7 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 ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, 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) #5
  store i32 0, ptr %6, align 4, !tbaa !5
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = icmp ne i32 %13, 5
  br i1 %14, label %15, label %21

15:                                               ; preds = %2
  %16 = load ptr, ptr @stderr, align 8, !tbaa !9
  %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, ptr, ...) @fprintf(ptr noundef %16, ptr noundef @.str, ptr noundef %19) #5
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %91

21:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %22 = load ptr, ptr %5, align 8, !tbaa !9
  %23 = getelementptr inbounds ptr, ptr %22, i64 1
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = call ptr @sqsh_archive_open(ptr noundef %24, ptr noundef null, ptr noundef %6)
  store ptr %25, ptr %8, align 8, !tbaa !9
  %26 = load ptr, ptr %8, align 8, !tbaa !9
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %30

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

30:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %31 = load ptr, ptr %8, align 8, !tbaa !9
  %32 = load ptr, ptr %5, align 8, !tbaa !9
  %33 = getelementptr inbounds ptr, ptr %32, i64 2
  %34 = load ptr, ptr %33, align 8, !tbaa !9
  %35 = call ptr @sqsh_open(ptr noundef %31, ptr noundef %34, ptr noundef %6)
  store ptr %35, ptr %9, align 8, !tbaa !9
  %36 = load ptr, ptr %9, align 8, !tbaa !9
  %37 = icmp eq ptr %36, null
  br i1 %37, label %38, label %40

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

40:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %41 = load ptr, ptr %9, align 8, !tbaa !9
  %42 = call ptr @sqsh_file_reader_new(ptr noundef %41, ptr noundef %6)
  store ptr %42, ptr %10, align 8, !tbaa !9
  %43 = load ptr, ptr %10, align 8, !tbaa !9
  %44 = icmp eq ptr %43, null
  br i1 %44, label %45, label %47

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

47:                                               ; preds = %40
  %48 = load ptr, ptr %10, align 8, !tbaa !9
  %49 = load ptr, ptr %5, align 8, !tbaa !9
  %50 = getelementptr inbounds ptr, ptr %49, i64 3
  %51 = load ptr, ptr %50, align 8, !tbaa !9
  %52 = call i32 @atoi(ptr noundef %51) #6
  %53 = sext i32 %52 to i64
  %54 = load ptr, ptr %5, align 8, !tbaa !9
  %55 = getelementptr inbounds ptr, ptr %54, i64 4
  %56 = load ptr, ptr %55, align 8, !tbaa !9
  %57 = call i32 @atoi(ptr noundef %56) #6
  %58 = sext i32 %57 to i64
  %59 = call i32 @sqsh_file_reader_advance2(ptr noundef %48, i64 noundef %53, i64 noundef %58)
  store i32 %59, ptr %6, align 4, !tbaa !5
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = icmp slt i32 %60, 0
  br i1 %61, label %62, label %64

62:                                               ; preds = %47
  %63 = load i32, ptr %6, align 4, !tbaa !5
  call void @sqsh_perror(i32 noundef %63, ptr noundef @.str.4)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %88

64:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %65 = load ptr, ptr %10, align 8, !tbaa !9
  %66 = call i64 @sqsh_file_reader_size(ptr noundef %65)
  store i64 %66, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %67 = load ptr, ptr %10, align 8, !tbaa !9
  %68 = call ptr @sqsh_file_reader_data(ptr noundef %67)
  store ptr %68, ptr %12, align 8, !tbaa !9
  %69 = load ptr, ptr %12, align 8, !tbaa !9
  %70 = load i64, ptr %11, align 8, !tbaa !11
  %71 = load ptr, ptr @stdout, align 8, !tbaa !9
  %72 = call i64 @fwrite(ptr noundef %69, i64 noundef 1, i64 noundef %70, ptr noundef %71)
  %73 = trunc i64 %72 to i32
  store i32 %73, ptr %6, align 4, !tbaa !5
  %74 = load i32, ptr %6, align 4, !tbaa !5
  %75 = load i64, ptr %11, align 8, !tbaa !11
  %76 = trunc i64 %75 to i32
  %77 = icmp ne i32 %74, %76
  br i1 %77, label %78, label %80

78:                                               ; preds = %64
  %79 = load i32, ptr %6, align 4, !tbaa !5
  call void @sqsh_perror(i32 noundef %79, ptr noundef @.str.5)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %87

80:                                               ; preds = %64
  %81 = load ptr, ptr %10, align 8, !tbaa !9
  %82 = call i32 @sqsh_file_reader_free(ptr noundef %81)
  %83 = load ptr, ptr %9, align 8, !tbaa !9
  %84 = call i32 @sqsh_close(ptr noundef %83)
  %85 = load ptr, ptr %8, align 8, !tbaa !9
  %86 = call i32 @sqsh_archive_close(ptr noundef %85)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %87

87:                                               ; preds = %80, %78
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %88

88:                                               ; preds = %87, %62, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %89

89:                                               ; preds = %88, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %90

90:                                               ; preds = %89, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %91

91:                                               ; preds = %90, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %92 = load i32, ptr %3, align 4
  ret i32 %92
}

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

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

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

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

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

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

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr noundef nonnull) #4

declare i64 @sqsh_file_reader_size(ptr noundef) #3

declare ptr @sqsh_file_reader_data(ptr noundef) #3

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

declare i32 @sqsh_file_reader_free(ptr noundef) #3

declare i32 @sqsh_close(ptr noundef) #3

declare i32 @sqsh_archive_close(ptr noundef) #3

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

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

!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, !12, i64 0}
!12 = !{!"long", !7, i64 0}


; 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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [36 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [25 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [7 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
  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, 5
  br i1 %.not, label %8, label %4

4:                                                ; preds = %2
  %5 = load ptr, ptr @stderr, align 8, !tbaa !9
  %6 = load ptr, ptr %1, align 8, !tbaa !9
  %7 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str, ptr noundef %6) #6
  br label %51

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = call ptr @sqsh_archive_open(ptr noundef %10, ptr noundef null, ptr noundef nonnull %3) #5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %15

13:                                               ; preds = %8
  %14 = load i32, ptr %3, align 4, !tbaa !5
  call void @sqsh_perror(i32 noundef %14, ptr noundef nonnull @.str.1) #5
  br label %51

15:                                               ; preds = %8
  %16 = getelementptr inbounds i8, ptr %1, i64 16
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = call ptr @sqsh_open(ptr noundef nonnull %11, ptr noundef %17, ptr noundef nonnull %3) #5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %22

20:                                               ; preds = %15
  %21 = load i32, ptr %3, align 4, !tbaa !5
  call void @sqsh_perror(i32 noundef %21, ptr noundef nonnull @.str.2) #5
  br label %51

22:                                               ; preds = %15
  %23 = call ptr @sqsh_file_reader_new(ptr noundef nonnull %18, ptr noundef nonnull %3) #5
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %27

25:                                               ; preds = %22
  %26 = load i32, ptr %3, align 4, !tbaa !5
  call void @sqsh_perror(i32 noundef %26, ptr noundef nonnull @.str.3) #5
  br label %51

27:                                               ; preds = %22
  %28 = getelementptr inbounds i8, ptr %1, i64 24
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = call i32 @atoi(ptr nocapture noundef %29) #7
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i8, ptr %1, i64 32
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  %34 = call i32 @atoi(ptr nocapture noundef %33) #7
  %35 = sext i32 %34 to i64
  %36 = call i32 @sqsh_file_reader_advance2(ptr noundef nonnull %23, i64 noundef %31, i64 noundef %35) #5
  store i32 %36, ptr %3, align 4, !tbaa !5
  %37 = icmp slt i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %27
  call void @sqsh_perror(i32 noundef %36, ptr noundef nonnull @.str.4) #5
  br label %51

39:                                               ; preds = %27
  %40 = call i64 @sqsh_file_reader_size(ptr noundef nonnull %23) #5
  %41 = call ptr @sqsh_file_reader_data(ptr noundef nonnull %23) #5
  %42 = load ptr, ptr @stdout, align 8, !tbaa !9
  %43 = call i64 @fwrite(ptr noundef %41, i64 noundef 1, i64 noundef %40, ptr noundef %42)
  %44 = trunc i64 %43 to i32
  store i32 %44, ptr %3, align 4, !tbaa !5
  %45 = trunc i64 %40 to i32
  %.not25 = icmp eq i32 %44, %45
  br i1 %.not25, label %47, label %46

46:                                               ; preds = %39
  call void @sqsh_perror(i32 noundef %44, ptr noundef nonnull @.str.5) #5
  br label %51

47:                                               ; preds = %39
  %48 = call i32 @sqsh_file_reader_free(ptr noundef nonnull %23) #5
  %49 = call i32 @sqsh_close(ptr noundef nonnull %18) #5
  %50 = call i32 @sqsh_archive_close(ptr noundef nonnull %11) #5
  br label %51

51:                                               ; preds = %13, %25, %38, %47, %46, %20, %4
  %.4 = phi i32 [ 1, %4 ], [ 1, %13 ], [ 1, %20 ], [ 1, %25 ], [ 1, %38 ], [ 1, %46 ], [ 0, %47 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #5
  ret i32 %.4
}

; 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 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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

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

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

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

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

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr nocapture noundef nonnull) local_unnamed_addr #4

declare i64 @sqsh_file_reader_size(ptr noundef) local_unnamed_addr #3

declare ptr @sqsh_file_reader_data(ptr noundef) local_unnamed_addr #3

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

declare i32 @sqsh_file_reader_free(ptr noundef) local_unnamed_addr #3

declare i32 @sqsh_close(ptr noundef) local_unnamed_addr #3

declare i32 @sqsh_archive_close(ptr noundef) local_unnamed_addr #3

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

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 = { "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 = { inlinehint mustprogress nofree nounwind willreturn memory(read) 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 #5 = { nounwind }
attributes #6 = { cold nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass