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

; 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_new() #1

declare void @TCOD_list_push(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @TCOD_zip_save_to_file(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %12, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = call ptr @gzopen(ptr noundef %13, ptr noundef @.str)
  store ptr %14, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.TCOD_Zip, ptr %15, i32 0, i32 3
  %17 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %17, ptr %8, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %21, label %20

20:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %78

21:                                               ; preds = %2
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = call i32 @gzwrite(ptr noundef %22, ptr noundef %8, i32 noundef 4)
  %24 = load i32, ptr %8, align 4, !tbaa !13
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %29

26:                                               ; preds = %21
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = call i32 @gzclose(ptr noundef %27)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %78

29:                                               ; preds = %21
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.TCOD_Zip, ptr %30, i32 0, i32 2
  %32 = load i32, ptr %31, align 8, !tbaa !14
  %33 = icmp sgt i32 %32, 0
  br i1 %33, label %34, label %55

34:                                               ; preds = %29
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.TCOD_Zip, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !15
  %38 = icmp ne ptr %37, null
  br i1 %38, label %43, label %39

39:                                               ; preds = %34
  %40 = call ptr @TCOD_list_new()
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.TCOD_Zip, ptr %41, i32 0, i32 0
  store ptr %40, ptr %42, align 8, !tbaa !15
  br label %43

43:                                               ; preds = %39, %34
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.TCOD_Zip, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !15
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.TCOD_Zip, ptr %47, i32 0, i32 1
  %49 = load i64, ptr %48, align 8, !tbaa !16
  %50 = inttoptr i64 %49 to ptr
  call void @TCOD_list_push(ptr noundef %46, ptr noundef %50)
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.TCOD_Zip, ptr %51, i32 0, i32 2
  store i32 0, ptr %52, align 8, !tbaa !14
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.TCOD_Zip, ptr %53, i32 0, i32 1
  store i64 0, ptr %54, align 8, !tbaa !16
  br label %55

55:                                               ; preds = %43, %29
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.TCOD_Zip, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !15
  %59 = call ptr @TCOD_list_begin(ptr noundef %58)
  store ptr %59, ptr %10, align 8, !tbaa !5
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = load i32, ptr %8, align 4, !tbaa !13
  %63 = call i32 @gzwrite(ptr noundef %60, ptr noundef %61, i32 noundef %62)
  store i32 %63, ptr %9, align 4, !tbaa !13
  %64 = load i32, ptr %9, align 4, !tbaa !13
  %65 = load i32, ptr %8, align 4, !tbaa !13
  %66 = icmp ne i32 %64, %65
  br i1 %66, label %67, label %70

67:                                               ; preds = %55
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = call i32 @gzclose(ptr noundef %68)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %78

70:                                               ; preds = %55
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = call i32 @gzclose(ptr noundef %71)
  store i32 %72, ptr %9, align 4, !tbaa !13
  %73 = load i32, ptr %9, align 4, !tbaa !13
  %74 = icmp ne i32 %73, 0
  br i1 %74, label %75, label %76

75:                                               ; preds = %70
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %78

76:                                               ; preds = %70
  %77 = load i32, ptr %8, align 4, !tbaa !13
  store i32 %77, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %78

78:                                               ; preds = %76, %75, %67, %26, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %79 = load i32, ptr %3, align 4
  ret i32 %79
}

declare ptr @gzopen(ptr noundef, ptr noundef) #1

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

declare i32 @gzclose(ptr noundef) #1

declare ptr @TCOD_list_begin(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 = { 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, !12, i64 20}
!10 = !{!"TCOD_Zip", !6, i64 0, !11, i64 8, !12, i64 16, !12, i64 20, !12, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!10, !12, i64 16}
!15 = !{!10, !6, i64 0}
!16 = !{!10, !11, 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 = external hidden unnamed_addr constant [3 x i8], align 1

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

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

declare ptr @TCOD_list_new() local_unnamed_addr #1

declare void @TCOD_list_push(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @TCOD_zip_save_to_file(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca i32, align 4
  %4 = tail call ptr @gzopen(ptr noundef %1, ptr noundef nonnull @.str) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %5 = getelementptr inbounds i8, ptr %0, i64 20
  %6 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %6, ptr %3, align 4, !tbaa !12
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %35, label %7

7:                                                ; preds = %2
  %8 = call i32 @gzwrite(ptr noundef nonnull %4, ptr noundef nonnull %3, i32 noundef 4) #3
  %9 = load i32, ptr %3, align 4, !tbaa !12
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %11, label %13

11:                                               ; preds = %7
  %12 = call i32 @gzclose(ptr noundef nonnull %4) #3
  br label %35

13:                                               ; preds = %7
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  %15 = load i32, ptr %14, align 8, !tbaa !13
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %17, label %26

17:                                               ; preds = %13
  %18 = load ptr, ptr %0, align 8, !tbaa !14
  %.not21 = icmp eq ptr %18, null
  br i1 %.not21, label %19, label %21

19:                                               ; preds = %17
  %20 = call ptr @TCOD_list_new() #3
  store ptr %20, ptr %0, align 8, !tbaa !14
  br label %21

21:                                               ; preds = %19, %17
  %22 = phi ptr [ %20, %19 ], [ %18, %17 ]
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  %24 = load i64, ptr %23, align 8, !tbaa !15
  %25 = inttoptr i64 %24 to ptr
  call void @TCOD_list_push(ptr noundef %22, ptr noundef %25) #3
  store i32 0, ptr %14, align 8, !tbaa !13
  store i64 0, ptr %23, align 8, !tbaa !15
  br label %26

26:                                               ; preds = %21, %13
  %27 = load ptr, ptr %0, align 8, !tbaa !14
  %28 = call ptr @TCOD_list_begin(ptr noundef %27) #3
  %29 = load i32, ptr %3, align 4, !tbaa !12
  %30 = call i32 @gzwrite(ptr noundef nonnull %4, ptr noundef %28, i32 noundef %29) #3
  %31 = load i32, ptr %3, align 4, !tbaa !12
  %.not22 = icmp eq i32 %30, %31
  %32 = call i32 @gzclose(ptr noundef nonnull %4) #3
  br i1 %.not22, label %33, label %35

33:                                               ; preds = %26
  %.not23 = icmp eq i32 %32, 0
  %34 = load i32, ptr %3, align 4
  %spec.select = select i1 %.not23, i32 %34, i32 0
  br label %35

35:                                               ; preds = %26, %33, %2, %11
  %.0 = phi i32 [ 0, %11 ], [ 0, %2 ], [ %spec.select, %33 ], [ 0, %26 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  ret i32 %.0
}

declare ptr @gzopen(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @gzwrite(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @gzclose(ptr noundef) local_unnamed_addr #1

declare ptr @TCOD_list_begin(ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { 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 20}
!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 = !{!11, !11, i64 0}
!13 = !{!6, !11, i64 16}
!14 = !{!6, !7, i64 0}
!15 = !{!6, !10, i64 8}


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