; LLVM IR from ihucos/plash :: shrink (shrink_main)

; 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.4 = external hidden unnamed_addr constant [15 x i8], align 1
@constinit = external hidden constant [3 x ptr], align 8
@.str.6 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [3 x i8], align 1

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

declare i32 @pl_fatal(ptr noundef, ...) #1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @count_images() #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @get_oldest_leave() #2

; Function Attrs: nounwind uwtable
define dso_local i32 @shrink_main(i32 noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca [3 x ptr], align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca [4 x ptr], align 8
  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 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 @constinit, i64 24, i1 false), !tbaa.struct !11
  %14 = getelementptr inbounds [3 x ptr], ptr %8, i64 0, i64 0
  %15 = call ptr @pl_check_output(ptr noundef %14)
  %16 = call ptr @pl_firstline(ptr noundef %15)
  store ptr %16, ptr %7, align 8, !tbaa !9
  %17 = load ptr, ptr %7, align 8, !tbaa !9
  %18 = call i32 @chdir(ptr noundef %17) #5
  %19 = icmp eq i32 %18, -1
  br i1 %19, label %20, label %22

20:                                               ; preds = %2
  %21 = call i32 (ptr, ...) @pl_fatal(ptr noundef @.str.6)
  br label %22

22:                                               ; preds = %20, %2
  %23 = call i32 @chdir(ptr noundef @.str.7) #5
  %24 = icmp eq i32 %23, -1
  br i1 %24, label %25, label %27

25:                                               ; preds = %22
  %26 = call i32 (ptr, ...) @pl_fatal(ptr noundef @.str.6)
  br label %27

27:                                               ; preds = %25, %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %28 = call i32 @count_images()
  %29 = sub nsw i32 %28, 1
  store i32 %29, ptr %9, align 4, !tbaa !5
  %30 = load i32, ptr %9, align 4, !tbaa !5
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %34, label %32

32:                                               ; preds = %27
  %33 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %80

34:                                               ; preds = %27
  %35 = load i32, ptr %9, align 4, !tbaa !5
  %36 = call i32 (ptr, ...) @printf(ptr noundef @.str.9, i32 noundef %35)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %37 = load i32, ptr %9, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  %39 = sdiv i32 %38, 2
  store i32 %39, ptr %11, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %72, %34
  %41 = load i32, ptr %11, align 4, !tbaa !5
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %44, label %43

43:                                               ; preds = %40
  store i32 2, ptr %10, align 4
  br label %75

44:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %45 = call ptr @get_oldest_leave()
  store ptr %45, ptr %12, align 8, !tbaa !9
  %46 = load ptr, ptr %12, align 8, !tbaa !9
  %47 = getelementptr inbounds i8, ptr %46, i64 0
  %48 = load i8, ptr %47, align 1, !tbaa !12
  %49 = sext i8 %48 to i32
  %50 = icmp eq i32 %49, 48
  br i1 %50, label %51, label %59

51:                                               ; preds = %44
  %52 = load ptr, ptr %12, align 8, !tbaa !9
  %53 = getelementptr inbounds i8, ptr %52, i64 1
  %54 = load i8, ptr %53, align 1, !tbaa !12
  %55 = sext i8 %54 to i32
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %59

57:                                               ; preds = %51
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str.10)
  store i32 2, ptr %10, align 4
  br label %69

59:                                               ; preds = %51, %44
  %60 = load ptr, ptr %12, align 8, !tbaa !9
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.11, ptr noundef %60)
  store ptr @.str.4, ptr %13, align 8, !tbaa !9
  %62 = getelementptr inbounds ptr, ptr %13, i64 1
  store ptr @.str.12, ptr %62, align 8, !tbaa !9
  %63 = getelementptr inbounds ptr, ptr %13, i64 2
  %64 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %64, ptr %63, align 8, !tbaa !9
  %65 = getelementptr inbounds ptr, ptr %13, i64 3
  store ptr null, ptr %65, align 8, !tbaa !9
  %66 = getelementptr inbounds [4 x ptr], ptr %13, i64 0, i64 0
  %67 = call ptr @pl_check_output(ptr noundef %66)
  %68 = call ptr @pl_firstline(ptr noundef %67)
  store i32 0, ptr %10, align 4
  br label %69

69:                                               ; preds = %59, %57
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %70 = load i32, ptr %10, align 4
  switch i32 %70, label %75 [
    i32 0, label %71
  ]

71:                                               ; preds = %69
  br label %72

72:                                               ; preds = %71
  %73 = load i32, ptr %11, align 4, !tbaa !5
  %74 = add nsw i32 %73, -1
  store i32 %74, ptr %11, align 4, !tbaa !5
  br label %40, !llvm.loop !13

75:                                               ; preds = %69, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %76

76:                                               ; preds = %75
  %77 = call i32 @count_images()
  %78 = sub nsw i32 %77, 1
  %79 = call i32 (ptr, ...) @printf(ptr noundef @.str.9, i32 noundef %78)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %80

80:                                               ; preds = %76, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %81 = load i32, ptr %3, align 4
  ret i32 %81
}

declare ptr @pl_firstline(ptr noundef) #1

declare ptr @pl_check_output(ptr noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: nounwind
declare i32 @chdir(ptr noundef) #4

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = { 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 = !{i64 0, i64 24, !12}
!12 = !{!7, !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"

@.str.4 = external hidden unnamed_addr constant [15 x i8], align 1
@constinit = external hidden local_unnamed_addr constant [3 x ptr], align 8
@.str.6 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [3 x i8], align 1

declare i32 @pl_fatal(ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @count_images() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @get_oldest_leave() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @shrink_main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #1 {
  %3 = alloca [3 x ptr], align 8
  %4 = alloca [4 x ptr], align 8
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(24) @constinit, i64 24, i1 false), !tbaa.struct !5
  %5 = call ptr @pl_check_output(ptr noundef nonnull %3) #5
  %6 = call ptr @pl_firstline(ptr noundef %5) #5
  %7 = call i32 @chdir(ptr noundef %6) #5
  %8 = icmp eq i32 %7, -1
  br i1 %8, label %9, label %11

9:                                                ; preds = %2
  %10 = call i32 (ptr, ...) @pl_fatal(ptr noundef nonnull @.str.6) #5
  br label %11

11:                                               ; preds = %9, %2
  %12 = call i32 @chdir(ptr noundef nonnull @.str.7) #5
  %13 = icmp eq i32 %12, -1
  br i1 %13, label %14, label %16

14:                                               ; preds = %11
  %15 = call i32 (ptr, ...) @pl_fatal(ptr noundef nonnull @.str.6) #5
  br label %16

16:                                               ; preds = %14, %11
  %17 = call i32 @count_images()
  %18 = add nsw i32 %17, -1
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %19, label %21

19:                                               ; preds = %16
  %20 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  br label %44

21:                                               ; preds = %16
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9, i32 noundef %18)
  %.off = add i32 %17, 1
  %.not1314 = icmp ult i32 %.off, 3
  br i1 %.not1314, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %21
  %23 = sdiv i32 %17, 2
  %24 = getelementptr inbounds i8, ptr %4, i64 8
  %25 = getelementptr inbounds i8, ptr %4, i64 16
  %26 = getelementptr inbounds i8, ptr %4, i64 24
  br label %27

27:                                               ; preds = %.lr.ph, %36
  %.01115 = phi i32 [ %23, %.lr.ph ], [ %40, %36 ]
  %28 = call ptr @get_oldest_leave()
  %29 = load i8, ptr %28, align 1, !tbaa !6
  %30 = icmp eq i8 %29, 48
  br i1 %30, label %31, label %36

31:                                               ; preds = %27
  %32 = getelementptr inbounds i8, ptr %28, i64 1
  %33 = load i8, ptr %32, align 1, !tbaa !6
  %34 = icmp eq i8 %33, 0
  br i1 %34, label %.critedge, label %36

.critedge:                                        ; preds = %31
  %35 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10)
  br label %.loopexit

36:                                               ; preds = %31, %27
  %37 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11, ptr noundef nonnull %28)
  store ptr @.str.4, ptr %4, align 8, !tbaa !9
  store ptr @.str.12, ptr %24, align 8, !tbaa !9
  store ptr %28, ptr %25, align 8, !tbaa !9
  store ptr null, ptr %26, align 8, !tbaa !9
  %38 = call ptr @pl_check_output(ptr noundef nonnull %4) #5
  %39 = call ptr @pl_firstline(ptr noundef %38) #5
  %40 = add nsw i32 %.01115, -1
  %.not13 = icmp eq i32 %40, 0
  br i1 %.not13, label %.loopexit, label %27, !llvm.loop !11

.loopexit:                                        ; preds = %36, %21, %.critedge
  %41 = call i32 @count_images()
  %42 = add nsw i32 %41, -1
  %43 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9, i32 noundef %42)
  br label %44

44:                                               ; preds = %.loopexit, %19
  ret i32 0
}

declare ptr @pl_firstline(ptr noundef) local_unnamed_addr #0

declare ptr @pl_check_output(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind
declare i32 @chdir(ptr noundef) local_unnamed_addr #3

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

attributes #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 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = { 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 = { 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 = !{i64 0, i64 24, !6}
!6 = !{!7, !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,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass