; LLVM IR from libtcod/libtcod :: src/libtcod (zip_c)

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

@.str.2 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [69 x i8], align 1
@__PRETTY_FUNCTION__.TCOD_zip_skip_bytes = external hidden unnamed_addr constant [47 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

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

declare ptr @TCOD_list_get(ptr noundef, i32 noundef) #1

declare i32 @TCOD_list_size(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_zip_skip_bytes(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %7, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.TCOD_Zip, ptr %8, i32 0, i32 4
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = sext i32 %10 to i64
  %12 = mul i64 %11, 8
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.TCOD_Zip, ptr %13, i32 0, i32 2
  %15 = load i32, ptr %14, align 8, !tbaa !14
  %16 = sext i32 %15 to i64
  %17 = sub i64 %12, %16
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = zext i32 %18 to i64
  %20 = add i64 %17, %19
  %21 = trunc i64 %20 to i32
  store i32 %21, ptr %6, align 4, !tbaa !9
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = zext i32 %22 to i64
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.TCOD_Zip, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  %27 = call i32 @TCOD_list_size(ptr noundef %26)
  %28 = sext i32 %27 to i64
  %29 = mul i64 %28, 8
  %30 = icmp ule i64 %23, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %2
  br label %33

32:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.3, i32 noundef 442, ptr noundef @__PRETTY_FUNCTION__.TCOD_zip_skip_bytes) #5
  unreachable

33:                                               ; preds = %31
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = add i64 %35, 8
  %37 = sub i64 %36, 1
  %38 = udiv i64 %37, 8
  %39 = trunc i64 %38 to i32
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.TCOD_Zip, ptr %40, i32 0, i32 4
  store i32 %39, ptr %41, align 8, !tbaa !11
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = zext i32 %42 to i64
  %44 = urem i64 %43, 8
  %45 = trunc i64 %44 to i32
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.TCOD_Zip, ptr %46, i32 0, i32 2
  store i32 %45, ptr %47, align 8, !tbaa !14
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.TCOD_Zip, ptr %48, i32 0, i32 2
  %50 = load i32, ptr %49, align 8, !tbaa !14
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %72

52:                                               ; preds = %33
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.TCOD_Zip, ptr %53, i32 0, i32 2
  %55 = load i32, ptr %54, align 8, !tbaa !14
  %56 = sext i32 %55 to i64
  %57 = sub i64 8, %56
  %58 = trunc i64 %57 to i32
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.TCOD_Zip, ptr %59, i32 0, i32 2
  store i32 %58, ptr %60, align 8, !tbaa !14
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.TCOD_Zip, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !15
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.TCOD_Zip, ptr %64, i32 0, i32 4
  %66 = load i32, ptr %65, align 8, !tbaa !11
  %67 = sub nsw i32 %66, 1
  %68 = call ptr @TCOD_list_get(ptr noundef %63, i32 noundef %67)
  %69 = ptrtoint ptr %68 to i64
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.TCOD_Zip, ptr %70, i32 0, i32 1
  store i64 %69, ptr %71, align 8, !tbaa !16
  br label %72

72:                                               ; preds = %52, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"TCOD_Zip", !6, i64 0, !13, i64 8, !10, i64 16, !10, i64 20, !10, i64 24}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !10, i64 16}
!15 = !{!12, !6, i64 0}
!16 = !{!12, !13, i64 8}


; 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.2 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [69 x i8], align 1
@__PRETTY_FUNCTION__.TCOD_zip_skip_bytes = external hidden unnamed_addr constant [47 x i8], align 1

declare ptr @TCOD_list_get(ptr noundef, i32 noundef) local_unnamed_addr #0

declare i32 @TCOD_list_size(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_zip_skip_bytes(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = shl i32 %4, 3
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load i32, ptr %6, align 8, !tbaa !12
  %8 = sub i32 %5, %7
  %9 = add i32 %8, %1
  %10 = zext i32 %9 to i64
  %11 = load ptr, ptr %0, align 8, !tbaa !13
  %12 = tail call i32 @TCOD_list_size(ptr noundef %11) #3
  %13 = sext i32 %12 to i64
  %14 = shl nsw i64 %13, 3
  %.not = icmp ult i64 %14, %10
  br i1 %.not, label %15, label %16

15:                                               ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.3, i32 noundef 442, ptr noundef nonnull @__PRETTY_FUNCTION__.TCOD_zip_skip_bytes) #4
  unreachable

16:                                               ; preds = %2
  %17 = add nuw nsw i64 %10, 7
  %18 = lshr i64 %17, 3
  %19 = trunc nuw nsw i64 %18 to i32
  store i32 %19, ptr %3, align 8, !tbaa !5
  %20 = and i32 %9, 7
  store i32 %20, ptr %6, align 8, !tbaa !12
  %.not16 = icmp eq i32 %20, 0
  br i1 %.not16, label %27, label %21

21:                                               ; preds = %16
  %narrow = sub nuw nsw i32 8, %20
  store i32 %narrow, ptr %6, align 8, !tbaa !12
  %22 = load ptr, ptr %0, align 8, !tbaa !13
  %23 = add nsw i32 %19, -1
  %24 = tail call ptr @TCOD_list_get(ptr noundef %22, i32 noundef %23) #3
  %25 = ptrtoint ptr %24 to i64
  %26 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %25, ptr %26, align 8, !tbaa !14
  br label %27

27:                                               ; preds = %21, %16
  ret void
}

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

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 = { 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 #3 = { nounwind }
attributes #4 = { 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, !11, i64 24}
!6 = !{!"TCOD_Zip", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 20, !11, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !11, i64 16}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !10, i64 8}


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