; LLVM IR from Gottox/sqsh-tools :: tools/src (stat)

; 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 [24 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
  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 %87

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 %87

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 sgt 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 %87

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 %83

56:                                               ; preds = %40
  %57 = load i32, ptr @optind, align 4, !tbaa !5
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = icmp eq i32 %57, %58
  br i1 %59, label %60, label %63

60:                                               ; preds = %56
  %61 = load ptr, ptr %9, align 8, !tbaa !9
  %62 = call i32 @stat_image(ptr noundef %61)
  store i32 %62, ptr %6, align 4, !tbaa !5
  br label %82

63:                                               ; preds = %56
  %64 = load i32, ptr @optind, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = icmp eq i32 %65, %66
  br i1 %67, label %68, label %76

68:                                               ; preds = %63
  %69 = load ptr, ptr %9, align 8, !tbaa !9
  %70 = load ptr, ptr %5, align 8, !tbaa !9
  %71 = load i32, ptr @optind, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds ptr, ptr %70, i64 %72
  %74 = load ptr, ptr %73, align 8, !tbaa !9
  %75 = call i32 @stat_file(ptr noundef %69, ptr noundef %74)
  store i32 %75, ptr %6, align 4, !tbaa !5
  br label %81

76:                                               ; preds = %63
  %77 = load ptr, ptr %5, align 8, !tbaa !9
  %78 = getelementptr inbounds ptr, ptr %77, i64 0
  %79 = load ptr, ptr %78, align 8, !tbaa !9
  %80 = call i32 @usage(ptr noundef %79)
  store i32 %80, ptr %6, align 4, !tbaa !5
  br label %81

81:                                               ; preds = %76, %68
  br label %82

82:                                               ; preds = %81, %60
  br label %83

83:                                               ; preds = %82, %53
  %84 = load ptr, ptr %9, align 8, !tbaa !9
  %85 = call i32 @sqsh_archive_close(ptr noundef %84)
  %86 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %86, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %87

87:                                               ; preds = %83, %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
  %88 = load i32, ptr %3, align 4
  ret i32 %88
}

; 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 @stat_image(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @stat_file(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"}


; 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 [24 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 %47

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

14:                                               ; preds = %4
  %15 = load i32, ptr @optind, align 4, !tbaa !5
  %.not23 = icmp slt i32 %15, %0
  br i1 %.not23, label %19, label %16

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

19:                                               ; preds = %14
  %20 = add nsw i32 %15, 1
  %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 %20, 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 %27, label %28

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

28:                                               ; preds = %19
  %29 = load i32, ptr @optind, align 4, !tbaa !5
  %30 = icmp eq i32 %29, %0
  br i1 %30, label %31, label %33

31:                                               ; preds = %28
  %32 = call i32 @stat_image(ptr noundef %24)
  store i32 %32, ptr %3, align 4, !tbaa !5
  br label %44

33:                                               ; preds = %28
  %34 = add nsw i32 %29, 1
  %35 = icmp eq i32 %34, %0
  br i1 %35, label %36, label %41

36:                                               ; preds = %33
  %37 = sext i32 %29 to i64
  %38 = getelementptr inbounds ptr, ptr %1, i64 %37
  %39 = load ptr, ptr %38, align 8, !tbaa !9
  %40 = call i32 @stat_file(ptr noundef %24, ptr noundef %39)
  store i32 %40, ptr %3, align 4, !tbaa !5
  br label %44

41:                                               ; preds = %33
  %42 = load ptr, ptr %1, align 8, !tbaa !9
  %43 = call i32 @usage(ptr noundef %42)
  store i32 %43, ptr %3, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %31, %41, %36, %27
  %45 = call i32 @sqsh_archive_close(ptr noundef %24) #6
  %46 = load i32, ptr %3, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %44, %16, %11, %9
  %.017 = phi i32 [ %13, %11 ], [ 0, %9 ], [ %18, %16 ], [ %46, %44 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #6
  ret i32 %.017
}

; 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 @stat_image(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @stat_file(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"}


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