; LLVM IR from Gottox/sqsh-tools :: tools/src (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.option = type { ptr, i32, ptr, i32 }

@opts = external hidden constant [5 x i8], align 1
@long_opts = external hidden constant [4 x %struct.option], align 16
@optarg = external global ptr, align 8
@.str = external hidden unnamed_addr constant [23 x i8], align 1
@optind = external global i32, align 4

; 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 i64, align 8
  %11 = alloca i32, align 4
  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
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store ptr null, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 0, ptr %10, align 8, !tbaa !11
  br label %12

12:                                               ; preds = %29, %2
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = load ptr, ptr %5, align 8, !tbaa !9
  %15 = call i32 @getopt_long(i32 noundef %13, ptr noundef %14, ptr noundef @opts, ptr noundef @long_opts, ptr noundef null) #4
  store i32 %15, ptr %7, align 4, !tbaa !5
  %16 = icmp ne i32 %15, -1
  br i1 %16, label %17, label %30

17:                                               ; preds = %12
  %18 = load i32, ptr %7, align 4, !tbaa !5
  switch i32 %18, label %24 [
    i32 111, label %19
    i32 118, label %22
  ]

19:                                               ; preds = %17
  %20 = load ptr, ptr @optarg, align 8, !tbaa !9
  %21 = call i64 @strtoull(ptr noundef %20, ptr noundef null, i32 noundef 0) #4
  store i64 %21, ptr %10, align 8, !tbaa !11
  br label %29

22:                                               ; preds = %17
  %23 = call i32 @puts(ptr noundef @.str)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %81

24:                                               ; preds = %17
  %25 = load ptr, ptr %5, align 8, !tbaa !9
  %26 = getelementptr inbounds ptr, ptr %25, i64 0
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = call i32 @usage(ptr noundef %27)
  store i32 %28, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %81

29:                                               ; preds = %19
  br label %12, !llvm.loop !13

30:                                               ; preds = %12
  %31 = load i32, ptr @optind, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = icmp sge i32 %32, %33
  br i1 %34, label %35, label %40

35:                                               ; preds = %30
  %36 = load ptr, ptr %5, align 8, !tbaa !9
  %37 = getelementptr inbounds ptr, ptr %36, i64 0
  %38 = load ptr, ptr %37, align 8, !tbaa !9
  %39 = call i32 @usage(ptr noundef %38)
  store i32 %39, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %81

40:                                               ; preds = %30
  %41 = load ptr, ptr %5, align 8, !tbaa !9
  %42 = load i32, ptr @optind, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds ptr, ptr %41, i64 %43
  %45 = load ptr, ptr %44, align 8, !tbaa !9
  store ptr %45, ptr %8, align 8, !tbaa !9
  %46 = load i32, ptr @optind, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr @optind, align 4, !tbaa !5
  %48 = load ptr, ptr %8, align 8, !tbaa !9
  %49 = load i64, ptr %10, align 8, !tbaa !11
  %50 = call ptr @open_archive(ptr noundef %48, i64 noundef %49, ptr noundef %6)
  store ptr %50, ptr %9, align 8, !tbaa !9
  %51 = load i32, ptr %6, align 4, !tbaa !5
  %52 = icmp slt i32 %51, 0
  br i1 %52, label %53, label %56

53:                                               ; preds = %40
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = load ptr, ptr %8, align 8, !tbaa !9
  call void @sqsh_perror(i32 noundef %54, ptr noundef %55)
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %77

56:                                               ; preds = %40
  br label %57

57:                                               ; preds = %73, %56
  %58 = load i32, ptr @optind, align 4, !tbaa !5
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = icmp slt i32 %58, %59
  br i1 %60, label %61, label %76

61:                                               ; preds = %57
  %62 = load ptr, ptr %9, align 8, !tbaa !9
  %63 = load ptr, ptr %5, align 8, !tbaa !9
  %64 = load i32, ptr @optind, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds ptr, ptr %63, i64 %65
  %67 = load ptr, ptr %66, align 8, !tbaa !9
  %68 = call i32 @cat_path(ptr noundef %62, ptr noundef %67)
  store i32 %68, ptr %6, align 4, !tbaa !5
  %69 = load i32, ptr %6, align 4, !tbaa !5
  %70 = icmp slt i32 %69, 0
  br i1 %70, label %71, label %72

71:                                               ; preds = %61
  br label %77

72:                                               ; preds = %61
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr @optind, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr @optind, align 4, !tbaa !5
  br label %57, !llvm.loop !15

76:                                               ; preds = %57
  br label %77

77:                                               ; preds = %76, %71, %53
  %78 = load ptr, ptr %9, align 8, !tbaa !9
  %79 = call i32 @sqsh_archive_close(ptr noundef %78)
  %80 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %80, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %81

81:                                               ; preds = %77, %35, %24, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %82 = load i32, ptr %3, align 4
  ret i32 %82
}

; 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 @getopt_long(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i64 @strtoull(ptr noundef, ptr noundef, i32 noundef) #2

declare i32 @puts(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden i32 @usage(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @cat_path(ptr noundef, ptr noundef) #0

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


; 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.option = type { ptr, i32, ptr, i32 }

@opts = external hidden constant [5 x i8], align 1
@long_opts = external hidden constant [4 x %struct.option], align 16
@optarg = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [23 x i8], align 1
@optind = external local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #6
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %6, %2
  %.0 = phi i64 [ 0, %2 ], [ %8, %6 ]
  %5 = tail call i32 @getopt_long(i32 noundef %0, ptr noundef %1, ptr noundef nonnull @opts, ptr noundef nonnull @long_opts, ptr noundef null) #6
  switch i32 %5, label %11 [
    i32 -1, label %14
    i32 111, label %6
    i32 118, label %9
  ]

6:                                                ; preds = %4
  %7 = load ptr, ptr @optarg, align 8, !tbaa !9
  %8 = tail call i64 @strtoull(ptr nocapture noundef %7, ptr noundef null, i32 noundef 0) #6
  br label %4, !llvm.loop !11

9:                                                ; preds = %4
  %10 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str)
  br label %42

11:                                               ; preds = %4
  %12 = load ptr, ptr %1, align 8, !tbaa !9
  %13 = tail call i32 @usage(ptr noundef %12)
  br label %42

14:                                               ; preds = %4
  %15 = load i32, ptr @optind, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  %.not20 = icmp slt i32 %16, %0
  br i1 %.not20, label %20, label %17

17:                                               ; preds = %14
  %18 = load ptr, ptr %1, align 8, !tbaa !9
  %19 = tail call i32 @usage(ptr noundef %18)
  br label %42

20:                                               ; preds = %14
  %21 = sext i32 %15 to i64
  %22 = getelementptr inbounds ptr, ptr %1, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  store i32 %16, ptr @optind, align 4, !tbaa !5
  %24 = call ptr @open_archive(ptr noundef %23, i64 noundef %.0, ptr noundef nonnull %3) #6
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = icmp slt i32 %25, 0
  br i1 %26, label %29, label %.preheader

.preheader:                                       ; preds = %20
  %27 = load i32, ptr @optind, align 4, !tbaa !5
  %28 = icmp slt i32 %27, %0
  br i1 %28, label %.lr.ph, label %.loopexit

29:                                               ; preds = %20
  call void @sqsh_perror(i32 noundef %25, ptr noundef %23) #6
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %36
  %30 = phi i32 [ %38, %36 ], [ %27, %.preheader ]
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds ptr, ptr %1, i64 %31
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  %34 = call i32 @cat_path(ptr noundef %24, ptr noundef %33)
  store i32 %34, ptr %3, align 4, !tbaa !5
  %35 = icmp slt i32 %34, 0
  br i1 %35, label %.loopexit, label %36

36:                                               ; preds = %.lr.ph
  %37 = load i32, ptr @optind, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr @optind, align 4, !tbaa !5
  %39 = icmp slt i32 %38, %0
  br i1 %39, label %.lr.ph, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %.lr.ph, %36, %.preheader, %29
  %40 = call i32 @sqsh_archive_close(ptr noundef %24) #6
  %41 = load i32, ptr %3, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %.loopexit, %17, %11, %9
  %.014 = phi i32 [ %13, %11 ], [ 0, %9 ], [ %19, %17 ], [ %41, %.loopexit ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #6
  ret i32 %.014
}

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

; Function Attrs: nounwind
declare i32 @getopt_long(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn
declare i64 @strtoull(ptr noundef readonly, ptr nocapture noundef, i32 noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
declare hidden i32 @usage(ptr noundef) local_unnamed_addr #0

declare ptr @open_archive(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #5

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

; Function Attrs: nounwind uwtable
declare hidden i32 @cat_path(ptr noundef, ptr noundef) local_unnamed_addr #0

declare i32 @sqsh_archive_close(ptr noundef) local_unnamed_addr #5

; 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 = { 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 nofree nounwind willreturn "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 = { "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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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