; LLVM IR from holzschu/ios_system :: libarchive/libarchive/contrib/shar (shar)

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

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@b_opt = external hidden global i32, align 4
@optarg = external global ptr, align 8
@o_arg = external hidden global ptr, align 8
@r_opt = external hidden global i32, align 4
@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
  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
  br label %7

7:                                                ; preds = %19, %2
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = load ptr, ptr %5, align 8, !tbaa !9
  %10 = call i32 @getopt(i32 noundef %8, ptr noundef %9, ptr noundef @.str) #4
  store i32 %10, ptr %6, align 4, !tbaa !5
  %11 = icmp ne i32 %10, -1
  br i1 %11, label %12, label %20

12:                                               ; preds = %7
  %13 = load i32, ptr %6, align 4, !tbaa !5
  switch i32 %13, label %18 [
    i32 98, label %14
    i32 111, label %15
    i32 114, label %17
  ]

14:                                               ; preds = %12
  store i32 1, ptr @b_opt, align 4, !tbaa !5
  br label %19

15:                                               ; preds = %12
  %16 = load ptr, ptr @optarg, align 8, !tbaa !9
  store ptr %16, ptr @o_arg, align 8, !tbaa !9
  br label %19

17:                                               ; preds = %12
  store i32 1, ptr @r_opt, align 4, !tbaa !5
  br label %19

18:                                               ; preds = %12
  call void @usage()
  br label %19

19:                                               ; preds = %18, %17, %15, %14
  br label %7, !llvm.loop !11

20:                                               ; preds = %7
  %21 = load i32, ptr @optind, align 4, !tbaa !5
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = sub nsw i32 %22, %21
  store i32 %23, ptr %4, align 4, !tbaa !5
  %24 = load i32, ptr @optind, align 4, !tbaa !5
  %25 = load ptr, ptr %5, align 8, !tbaa !9
  %26 = sext i32 %24 to i64
  %27 = getelementptr inbounds ptr, ptr %25, i64 %26
  store ptr %27, ptr %5, align 8, !tbaa !9
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = icmp slt i32 %28, 1
  br i1 %29, label %30, label %31

30:                                               ; preds = %20
  call void @usage()
  br label %31

31:                                               ; preds = %30, %20
  %32 = load ptr, ptr %5, align 8, !tbaa !9
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = call i32 @shar_write(ptr noundef %32, i64 noundef %34)
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %31
  call void @exit(i32 noundef 1) #5
  unreachable

38:                                               ; preds = %31
  call void @exit(i32 noundef 0) #5
  unreachable
}

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

; Function Attrs: nounwind uwtable
declare hidden void @usage() #0

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #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 = { 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 = { noreturn 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 #4 = { nounwind }
attributes #5 = { noreturn 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"}


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

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@b_opt = external hidden local_unnamed_addr global i32, align 4
@optarg = external local_unnamed_addr global ptr, align 8
@o_arg = external hidden local_unnamed_addr global ptr, align 8
@r_opt = external hidden local_unnamed_addr global i32, align 4
@optind = external local_unnamed_addr global i32, align 4

; Function Attrs: noreturn nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  br label %3

3:                                                ; preds = %.backedge, %2
  %4 = tail call i32 @getopt(i32 noundef %0, ptr noundef %1, ptr noundef nonnull @.str) #4
  switch i32 %4, label %9 [
    i32 -1, label %10
    i32 98, label %5
    i32 111, label %6
    i32 114, label %8
  ]

5:                                                ; preds = %3
  store i32 1, ptr @b_opt, align 4, !tbaa !5
  br label %.backedge

6:                                                ; preds = %3
  %7 = load ptr, ptr @optarg, align 8, !tbaa !9
  store ptr %7, ptr @o_arg, align 8, !tbaa !9
  br label %.backedge

8:                                                ; preds = %3
  store i32 1, ptr @r_opt, align 4, !tbaa !5
  br label %.backedge

9:                                                ; preds = %3
  tail call void @usage()
  br label %.backedge

.backedge:                                        ; preds = %9, %8, %6, %5
  br label %3, !llvm.loop !11

10:                                               ; preds = %3
  %11 = load i32, ptr @optind, align 4, !tbaa !5
  %12 = sub nsw i32 %0, %11
  %13 = sext i32 %11 to i64
  %14 = getelementptr inbounds ptr, ptr %1, i64 %13
  %15 = icmp slt i32 %12, 1
  br i1 %15, label %16, label %17

16:                                               ; preds = %10
  tail call void @usage()
  br label %17

17:                                               ; preds = %16, %10
  %18 = sext i32 %12 to i64
  %19 = tail call i32 @shar_write(ptr noundef %14, i64 noundef %18)
  %.not7 = icmp eq i32 %19, 0
  br i1 %.not7, label %21, label %20

20:                                               ; preds = %17
  tail call void @exit(i32 noundef 1) #5
  unreachable

21:                                               ; preds = %17
  tail call void @exit(i32 noundef 0) #5
  unreachable
}

; Function Attrs: nounwind
declare i32 @getopt(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @usage() local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @shar_write(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #3

attributes #0 = { noreturn 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 = { 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 #2 = { 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 #3 = { noreturn 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 #4 = { nounwind }
attributes #5 = { noreturn 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,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass