; LLVM IR from kuba--/zip :: src (zip)

; 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.zip_t = type { %struct.mz_zip_archive, i32, %struct.zip_entry_t }
%struct.mz_zip_archive = type { i64, i64, i32, i32, i32, i32, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.zip_entry_t = type { i64, ptr, i64, i64, i32, i64, [30 x i8], i64, i16, %struct.mz_zip_writer_add_state, %struct.tdefl_compressor, i32, i64 }
%struct.mz_zip_writer_add_state = type { ptr, i64, i64 }
%struct.tdefl_compressor = type { ptr, ptr, i32, [2 x i32], i32, i32, i32, i32, i32, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, ptr, i32, ptr, i64, i64, [33025 x i8], [3 x [288 x i16]], [3 x [288 x i16]], [3 x [288 x i8]], [65536 x i8], [32768 x i16], [32768 x i16], [85196 x i8] }

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

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @zip_entry_isdir(ptr noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i16, align 2
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %4) #3
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %9, label %8

8:                                                ; preds = %1
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %51

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.zip_t, ptr %10, i32 0, i32 2
  %12 = getelementptr inbounds %struct.zip_entry_t, ptr %11, i32 0, i32 0
  %13 = load i64, ptr %12, align 8, !tbaa !9
  %14 = icmp slt i64 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %9
  store i32 -10, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %51

16:                                               ; preds = %9
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.zip_t, ptr %17, i32 0, i32 2
  %19 = getelementptr inbounds %struct.zip_entry_t, ptr %18, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !18
  %21 = call i64 @strlen(ptr noundef %20) #4
  %22 = trunc i64 %21 to i16
  store i16 %22, ptr %4, align 2, !tbaa !19
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.zip_t, ptr %23, i32 0, i32 2
  %25 = getelementptr inbounds %struct.zip_entry_t, ptr %24, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !18
  %27 = load i16, ptr %4, align 2, !tbaa !19
  %28 = zext i16 %27 to i32
  %29 = sub nsw i32 %28, 1
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i8, ptr %26, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !20
  %33 = sext i8 %32 to i32
  %34 = icmp eq i32 %33, 47
  br i1 %34, label %48, label %35

35:                                               ; preds = %16
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.zip_t, ptr %36, i32 0, i32 2
  %38 = getelementptr inbounds %struct.zip_entry_t, ptr %37, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !18
  %40 = load i16, ptr %4, align 2, !tbaa !19
  %41 = zext i16 %40 to i32
  %42 = sub nsw i32 %41, 1
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i8, ptr %39, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !20
  %46 = sext i8 %45 to i32
  %47 = icmp eq i32 %46, 92
  br label %48

48:                                               ; preds = %35, %16
  %49 = phi i1 [ true, %16 ], [ %47, %35 ]
  %50 = zext i1 %49 to i32
  store i32 %50, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %51

51:                                               ; preds = %48, %15, %8
  call void @llvm.lifetime.end.p0(i64 2, ptr %4) #3
  %52 = load i32, ptr %2, align 4
  ret i32 %52
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind willreturn memory(read) "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 = { nounwind }
attributes #4 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 120}
!10 = !{!"zip_t", !11, i64 0, !13, i64 112, !14, i64 120}
!11 = !{!"", !12, i64 0, !12, i64 8, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !12, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104}
!12 = !{!"long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"zip_entry_t", !12, i64 0, !6, i64 8, !12, i64 16, !12, i64 24, !13, i64 32, !12, i64 40, !7, i64 48, !12, i64 80, !15, i64 88, !16, i64 96, !17, i64 120, !13, i64 319472, !12, i64 319480}
!15 = !{!"short", !7, i64 0}
!16 = !{!"", !6, i64 0, !12, i64 8, !12, i64 16}
!17 = !{!"", !6, i64 0, !6, i64 8, !13, i64 16, !7, i64 20, !13, i64 28, !13, i64 32, !13, i64 36, !13, i64 40, !13, i64 44, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !13, i64 80, !13, i64 84, !13, i64 88, !13, i64 92, !13, i64 96, !13, i64 100, !13, i64 104, !13, i64 108, !13, i64 112, !13, i64 116, !13, i64 120, !13, i64 124, !13, i64 128, !13, i64 132, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !13, i64 168, !6, i64 176, !12, i64 184, !12, i64 192, !7, i64 200, !7, i64 33226, !7, i64 34954, !7, i64 36682, !7, i64 37546, !7, i64 103082, !7, i64 168618, !7, i64 234154}
!18 = !{!10, !6, i64 128}
!19 = !{!15, !15, i64 0}
!20 = !{!7, !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"

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local range(i32 -10, 2) i32 @zip_entry_isdir(ptr noundef readonly %0) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %17, label %2

2:                                                ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 120
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = icmp slt i64 %4, 0
  br i1 %5, label %17, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 128
  %8 = load ptr, ptr %7, align 8, !tbaa !17
  %9 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %8) #2
  %10 = and i64 %9, 65535
  %11 = getelementptr i8, ptr %8, i64 %10
  %12 = getelementptr i8, ptr %11, i64 -1
  %13 = load i8, ptr %12, align 1, !tbaa !18
  %14 = icmp eq i8 %13, 47
  %15 = icmp eq i8 %13, 92
  %narrow = or i1 %14, %15
  %16 = zext i1 %narrow to i32
  br label %17

17:                                               ; preds = %2, %1, %6
  %.0 = phi i32 [ %16, %6 ], [ -1, %1 ], [ -10, %2 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 nofree nounwind willreturn memory(read, inaccessiblemem: none) 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 = { 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, !8, i64 120}
!6 = !{!"zip_t", !7, i64 0, !11, i64 112, !13, i64 120}
!7 = !{!"", !8, i64 0, !8, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !8, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!"zip_entry_t", !8, i64 0, !12, i64 8, !8, i64 16, !8, i64 24, !11, i64 32, !8, i64 40, !9, i64 48, !8, i64 80, !14, i64 88, !15, i64 96, !16, i64 120, !11, i64 319472, !8, i64 319480}
!14 = !{!"short", !9, i64 0}
!15 = !{!"", !12, i64 0, !8, i64 8, !8, i64 16}
!16 = !{!"", !12, i64 0, !12, i64 8, !11, i64 16, !9, i64 20, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !11, i64 96, !11, i64 100, !11, i64 104, !11, i64 108, !11, i64 112, !11, i64 116, !11, i64 120, !11, i64 124, !11, i64 128, !11, i64 132, !12, i64 136, !12, i64 144, !12, i64 152, !12, i64 160, !11, i64 168, !12, i64 176, !8, i64 184, !8, i64 192, !9, i64 200, !9, i64 33226, !9, i64 34954, !9, i64 36682, !9, i64 37546, !9, i64 103082, !9, i64 168618, !9, i64 234154}
!17 = !{!6, !12, i64 128}
!18 = !{!9, !9, i64 0}


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