; LLVM IR from glotzerlab/hoomd-blue :: hoomd/extern (gsd)

; 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.gsd_index_entry = type { i64, i64, i64, i32, i16, i8, i8 }
%struct.gsd_handle = type { i32, %struct.gsd_header, %struct.gsd_index_buffer, %struct.gsd_index_buffer, %struct.gsd_index_buffer, %struct.gsd_byte_buffer, %struct.gsd_name_buffer, %struct.gsd_name_buffer, i64, i64, i32, %struct.gsd_name_id_map, i64, i64, i64 }
%struct.gsd_header = type { i64, i64, i64, i64, i64, i32, i32, [64 x i8], [64 x i8], [80 x i8] }
%struct.gsd_index_buffer = type { ptr, i64, i64, ptr, i64 }
%struct.gsd_byte_buffer = type { ptr, i64, i64 }
%struct.gsd_name_buffer = type { %struct.gsd_byte_buffer, i64 }
%struct.gsd_name_id_map = type { ptr, i64 }

; 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: inlinehint nounwind uwtable
declare hidden void @gsd_util_zero_memory(ptr noundef, i64 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) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @gsd_flush_write_buffer(ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @gsd_io_pwrite_retry(i32 noundef, ptr noundef, i64 noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @gsd_write_chunk(ptr noundef %0, ptr noundef %1, i32 noundef %2, i64 noundef %3, i32 noundef %4, i8 noundef zeroext %5, ptr noundef %6) #3 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i8, align 1
  %15 = alloca ptr, align 8
  %16 = alloca i16, align 2
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca %struct.gsd_index_entry, align 8
  %20 = alloca i64, align 8
  %21 = alloca ptr, align 8
  %22 = alloca i32, align 4
  %23 = alloca ptr, align 8
  %24 = alloca i32, align 4
  %25 = alloca i64, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store i32 %2, ptr %11, align 4, !tbaa !9
  store i64 %3, ptr %12, align 8, !tbaa !11
  store i32 %4, ptr %13, align 4, !tbaa !9
  store i8 %5, ptr %14, align 1, !tbaa !13
  store ptr %6, ptr %15, align 8, !tbaa !5
  %26 = load i64, ptr %12, align 8, !tbaa !11
  %27 = icmp ugt i64 %26, 0
  br i1 %27, label %28, label %32

28:                                               ; preds = %7
  %29 = load ptr, ptr %15, align 8, !tbaa !5
  %30 = icmp eq ptr %29, null
  br i1 %30, label %31, label %32

31:                                               ; preds = %28
  store i32 -2, ptr %8, align 4
  br label %192

32:                                               ; preds = %28, %7
  %33 = load i32, ptr %13, align 4, !tbaa !9
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %32
  store i32 -2, ptr %8, align 4
  br label %192

36:                                               ; preds = %32
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.gsd_handle, ptr %37, i32 0, i32 10
  %39 = load i32, ptr %38, align 8, !tbaa !14
  %40 = icmp eq i32 %39, 2
  br i1 %40, label %41, label %42

41:                                               ; preds = %36
  store i32 -8, ptr %8, align 4
  br label %192

42:                                               ; preds = %36
  %43 = load i8, ptr %14, align 1, !tbaa !13
  %44 = zext i8 %43 to i32
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %42
  store i32 -2, ptr %8, align 4
  br label %192

47:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 2, ptr %16) #4
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.gsd_handle, ptr %48, i32 0, i32 11
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = call zeroext i16 @gsd_name_id_map_find(ptr noundef %49, ptr noundef %50)
  store i16 %51, ptr %16, align 2, !tbaa !21
  %52 = load i16, ptr %16, align 2, !tbaa !21
  %53 = zext i16 %52 to i32
  %54 = icmp eq i32 %53, 65535
  br i1 %54, label %55, label %72

55:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = call i32 @gsd_append_name(ptr noundef %16, ptr noundef %56, ptr noundef %57)
  store i32 %58, ptr %17, align 4, !tbaa !9
  %59 = load i32, ptr %17, align 4, !tbaa !9
  %60 = icmp ne i32 %59, 0
  br i1 %60, label %61, label %63

61:                                               ; preds = %55
  %62 = load i32, ptr %17, align 4, !tbaa !9
  store i32 %62, ptr %8, align 4
  store i32 1, ptr %18, align 4
  br label %69

63:                                               ; preds = %55
  %64 = load i16, ptr %16, align 2, !tbaa !21
  %65 = zext i16 %64 to i32
  %66 = icmp eq i32 %65, 65535
  br i1 %66, label %67, label %68

67:                                               ; preds = %63
  store i32 -7, ptr %8, align 4
  store i32 1, ptr %18, align 4
  br label %69

68:                                               ; preds = %63
  store i32 0, ptr %18, align 4
  br label %69

69:                                               ; preds = %68, %67, %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  %70 = load i32, ptr %18, align 4
  switch i32 %70, label %191 [
    i32 0, label %71
  ]

71:                                               ; preds = %69
  br label %72

72:                                               ; preds = %71, %47
  call void @llvm.lifetime.start.p0(i64 32, ptr %19) #4
  call void @gsd_util_zero_memory(ptr noundef %19, i64 noundef 32)
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.gsd_handle, ptr %73, i32 0, i32 8
  %75 = load i64, ptr %74, align 8, !tbaa !23
  %76 = getelementptr inbounds %struct.gsd_index_entry, ptr %19, i32 0, i32 0
  store i64 %75, ptr %76, align 8, !tbaa !24
  %77 = load i16, ptr %16, align 2, !tbaa !21
  %78 = getelementptr inbounds %struct.gsd_index_entry, ptr %19, i32 0, i32 4
  store i16 %77, ptr %78, align 4, !tbaa !26
  %79 = load i32, ptr %11, align 4, !tbaa !9
  %80 = trunc i32 %79 to i8
  %81 = getelementptr inbounds %struct.gsd_index_entry, ptr %19, i32 0, i32 5
  store i8 %80, ptr %81, align 2, !tbaa !27
  %82 = load i64, ptr %12, align 8, !tbaa !11
  %83 = getelementptr inbounds %struct.gsd_index_entry, ptr %19, i32 0, i32 1
  store i64 %82, ptr %83, align 8, !tbaa !28
  %84 = load i32, ptr %13, align 4, !tbaa !9
  %85 = getelementptr inbounds %struct.gsd_index_entry, ptr %19, i32 0, i32 3
  store i32 %84, ptr %85, align 8, !tbaa !29
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  %86 = load i64, ptr %12, align 8, !tbaa !11
  %87 = load i32, ptr %13, align 4, !tbaa !9
  %88 = zext i32 %87 to i64
  %89 = mul i64 %86, %88
  %90 = load i32, ptr %11, align 4, !tbaa !9
  %91 = call i64 @gsd_sizeof_type(i32 noundef %90)
  %92 = mul i64 %89, %91
  store i64 %92, ptr %20, align 8, !tbaa !11
  %93 = load i64, ptr %20, align 8, !tbaa !11
  %94 = load ptr, ptr %9, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.gsd_handle, ptr %94, i32 0, i32 13
  %96 = load i64, ptr %95, align 8, !tbaa !30
  %97 = icmp ult i64 %93, %96
  br i1 %97, label %98, label %144

98:                                               ; preds = %72
  %99 = load i64, ptr %20, align 8, !tbaa !11
  %100 = load ptr, ptr %9, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.gsd_handle, ptr %100, i32 0, i32 13
  %102 = load i64, ptr %101, align 8, !tbaa !30
  %103 = load ptr, ptr %9, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.gsd_handle, ptr %103, i32 0, i32 5
  %105 = getelementptr inbounds %struct.gsd_byte_buffer, ptr %104, i32 0, i32 1
  %106 = load i64, ptr %105, align 8, !tbaa !31
  %107 = sub i64 %102, %106
  %108 = icmp ugt i64 %99, %107
  br i1 %108, label %109, label %112

109:                                              ; preds = %98
  %110 = load ptr, ptr %9, align 8, !tbaa !5
  %111 = call i32 @gsd_flush_write_buffer(ptr noundef %110)
  br label %112

112:                                              ; preds = %109, %98
  %113 = load ptr, ptr %9, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.gsd_handle, ptr %113, i32 0, i32 5
  %115 = getelementptr inbounds %struct.gsd_byte_buffer, ptr %114, i32 0, i32 1
  %116 = load i64, ptr %115, align 8, !tbaa !31
  %117 = getelementptr inbounds %struct.gsd_index_entry, ptr %19, i32 0, i32 2
  store i64 %116, ptr %117, align 8, !tbaa !32
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #4
  %118 = load ptr, ptr %9, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.gsd_handle, ptr %118, i32 0, i32 4
  %120 = call i32 @gsd_index_buffer_add(ptr noundef %119, ptr noundef %21)
  store i32 %120, ptr %22, align 4, !tbaa !9
  %121 = load i32, ptr %22, align 4, !tbaa !9
  %122 = icmp ne i32 %121, 0
  br i1 %122, label %123, label %125

123:                                              ; preds = %112
  %124 = load i32, ptr %22, align 4, !tbaa !9
  store i32 %124, ptr %8, align 4
  store i32 1, ptr %18, align 4
  br label %141

125:                                              ; preds = %112
  %126 = load ptr, ptr %21, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %126, ptr align 8 %19, i64 32, i1 false), !tbaa.struct !33
  %127 = load i64, ptr %20, align 8, !tbaa !11
  %128 = icmp ugt i64 %127, 0
  br i1 %128, label %129, label %140

129:                                              ; preds = %125
  %130 = load ptr, ptr %9, align 8, !tbaa !5
  %131 = getelementptr inbounds %struct.gsd_handle, ptr %130, i32 0, i32 5
  %132 = load ptr, ptr %15, align 8, !tbaa !5
  %133 = load i64, ptr %20, align 8, !tbaa !11
  %134 = call i32 @gsd_byte_buffer_append(ptr noundef %131, ptr noundef %132, i64 noundef %133)
  store i32 %134, ptr %22, align 4, !tbaa !9
  %135 = load i32, ptr %22, align 4, !tbaa !9
  %136 = icmp ne i32 %135, 0
  br i1 %136, label %137, label %139

137:                                              ; preds = %129
  %138 = load i32, ptr %22, align 4, !tbaa !9
  store i32 %138, ptr %8, align 4
  store i32 1, ptr %18, align 4
  br label %141

139:                                              ; preds = %129
  br label %140

140:                                              ; preds = %139, %125
  store i32 0, ptr %18, align 4
  br label %141

141:                                              ; preds = %140, %137, %123
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #4
  %142 = load i32, ptr %18, align 4
  switch i32 %142, label %190 [
    i32 0, label %143
  ]

143:                                              ; preds = %141
  br label %185

144:                                              ; preds = %72
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #4
  %145 = load ptr, ptr %9, align 8, !tbaa !5
  %146 = getelementptr inbounds %struct.gsd_handle, ptr %145, i32 0, i32 3
  %147 = call i32 @gsd_index_buffer_add(ptr noundef %146, ptr noundef %23)
  store i32 %147, ptr %24, align 4, !tbaa !9
  %148 = load i32, ptr %24, align 4, !tbaa !9
  %149 = icmp ne i32 %148, 0
  br i1 %149, label %150, label %152

150:                                              ; preds = %144
  %151 = load i32, ptr %24, align 4, !tbaa !9
  store i32 %151, ptr %8, align 4
  store i32 1, ptr %18, align 4
  br label %182

152:                                              ; preds = %144
  %153 = load ptr, ptr %23, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %153, ptr align 8 %19, i64 32, i1 false), !tbaa.struct !33
  %154 = load ptr, ptr %9, align 8, !tbaa !5
  %155 = getelementptr inbounds %struct.gsd_handle, ptr %154, i32 0, i32 9
  %156 = load i64, ptr %155, align 8, !tbaa !34
  %157 = load ptr, ptr %23, align 8, !tbaa !5
  %158 = getelementptr inbounds %struct.gsd_index_entry, ptr %157, i32 0, i32 2
  store i64 %156, ptr %158, align 8, !tbaa !32
  call void @llvm.lifetime.start.p0(i64 8, ptr %25) #4
  %159 = load ptr, ptr %9, align 8, !tbaa !5
  %160 = getelementptr inbounds %struct.gsd_handle, ptr %159, i32 0, i32 0
  %161 = load i32, ptr %160, align 8, !tbaa !35
  %162 = load ptr, ptr %15, align 8, !tbaa !5
  %163 = load i64, ptr %20, align 8, !tbaa !11
  %164 = load ptr, ptr %23, align 8, !tbaa !5
  %165 = getelementptr inbounds %struct.gsd_index_entry, ptr %164, i32 0, i32 2
  %166 = load i64, ptr %165, align 8, !tbaa !32
  %167 = call i64 @gsd_io_pwrite_retry(i32 noundef %161, ptr noundef %162, i64 noundef %163, i64 noundef %166)
  store i64 %167, ptr %25, align 8, !tbaa !11
  %168 = load i64, ptr %25, align 8, !tbaa !11
  %169 = icmp eq i64 %168, -1
  br i1 %169, label %174, label %170

170:                                              ; preds = %152
  %171 = load i64, ptr %25, align 8, !tbaa !11
  %172 = load i64, ptr %20, align 8, !tbaa !11
  %173 = icmp ne i64 %171, %172
  br i1 %173, label %174, label %175

174:                                              ; preds = %170, %152
  store i32 -1, ptr %8, align 4
  store i32 1, ptr %18, align 4
  br label %181

175:                                              ; preds = %170
  %176 = load i64, ptr %25, align 8, !tbaa !11
  %177 = load ptr, ptr %9, align 8, !tbaa !5
  %178 = getelementptr inbounds %struct.gsd_handle, ptr %177, i32 0, i32 9
  %179 = load i64, ptr %178, align 8, !tbaa !34
  %180 = add nsw i64 %179, %176
  store i64 %180, ptr %178, align 8, !tbaa !34
  store i32 0, ptr %18, align 4
  br label %181

181:                                              ; preds = %175, %174
  call void @llvm.lifetime.end.p0(i64 8, ptr %25) #4
  br label %182

182:                                              ; preds = %181, %150
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #4
  %183 = load i32, ptr %18, align 4
  switch i32 %183, label %190 [
    i32 0, label %184
  ]

184:                                              ; preds = %182
  br label %185

185:                                              ; preds = %184, %143
  %186 = load ptr, ptr %9, align 8, !tbaa !5
  %187 = getelementptr inbounds %struct.gsd_handle, ptr %186, i32 0, i32 12
  %188 = load i64, ptr %187, align 8, !tbaa !36
  %189 = add i64 %188, 1
  store i64 %189, ptr %187, align 8, !tbaa !36
  store i32 0, ptr %8, align 4
  store i32 1, ptr %18, align 4
  br label %190

190:                                              ; preds = %185, %182, %141
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %19) #4
  br label %191

191:                                              ; preds = %190, %69
  call void @llvm.lifetime.end.p0(i64 2, ptr %16) #4
  br label %192

192:                                              ; preds = %191, %46, %41, %35, %31
  %193 = load i32, ptr %8, align 4
  ret i32 %193
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @gsd_name_id_map_find(ptr noundef, ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @gsd_append_name(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @gsd_sizeof_type(i32 noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @gsd_index_buffer_add(ptr noundef, ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @gsd_byte_buffer_append(ptr noundef, ptr noundef, i64 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !10, i64 488}
!15 = !{!"gsd_handle", !10, i64 0, !16, i64 8, !17, i64 264, !17, i64 304, !17, i64 344, !18, i64 384, !19, i64 408, !19, i64 440, !12, i64 472, !12, i64 480, !10, i64 488, !20, i64 496, !12, i64 512, !12, i64 520, !12, i64 528}
!16 = !{!"gsd_header", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !10, i64 40, !10, i64 44, !7, i64 48, !7, i64 112, !7, i64 176}
!17 = !{!"gsd_index_buffer", !6, i64 0, !12, i64 8, !12, i64 16, !6, i64 24, !12, i64 32}
!18 = !{!"gsd_byte_buffer", !6, i64 0, !12, i64 8, !12, i64 16}
!19 = !{!"gsd_name_buffer", !18, i64 0, !12, i64 24}
!20 = !{!"gsd_name_id_map", !6, i64 0, !12, i64 8}
!21 = !{!22, !22, i64 0}
!22 = !{!"short", !7, i64 0}
!23 = !{!15, !12, i64 472}
!24 = !{!25, !12, i64 0}
!25 = !{!"gsd_index_entry", !12, i64 0, !12, i64 8, !12, i64 16, !10, i64 24, !22, i64 28, !7, i64 30, !7, i64 31}
!26 = !{!25, !22, i64 28}
!27 = !{!25, !7, i64 30}
!28 = !{!25, !12, i64 8}
!29 = !{!25, !10, i64 24}
!30 = !{!15, !12, i64 520}
!31 = !{!15, !12, i64 392}
!32 = !{!25, !12, i64 16}
!33 = !{i64 0, i64 8, !11, i64 8, i64 8, !11, i64 16, i64 8, !11, i64 24, i64 4, !9, i64 28, i64 2, !21, i64 30, i64 1, !13, i64 31, i64 1, !13}
!34 = !{!15, !12, i64 480}
!35 = !{!15, !10, i64 0}
!36 = !{!15, !12, i64 512}


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

%struct.gsd_index_entry = type { i64, i64, i64, i32, i16, i8, i8 }

; 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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @gsd_util_zero_memory(ptr noundef, i64 noundef) local_unnamed_addr #1

; 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: inlinehint nounwind uwtable
declare hidden i32 @gsd_flush_write_buffer(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @gsd_io_pwrite_retry(i32 noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @gsd_write_chunk(ptr noundef %0, ptr noundef %1, i32 noundef %2, i64 noundef %3, i32 noundef %4, i8 noundef zeroext %5, ptr noundef %6) local_unnamed_addr #3 {
  %8 = alloca i16, align 2
  %9 = alloca %struct.gsd_index_entry, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = icmp ne i64 %3, 0
  %13 = icmp eq ptr %6, null
  %or.cond = and i1 %12, %13
  %14 = icmp eq i32 %4, 0
  %or.cond74 = or i1 %14, %or.cond
  br i1 %or.cond74, label %81, label %15

15:                                               ; preds = %7
  %16 = getelementptr inbounds i8, ptr %0, i64 488
  %17 = load i32, ptr %16, align 8, !tbaa !5
  %18 = icmp eq i32 %17, 2
  br i1 %18, label %81, label %19

19:                                               ; preds = %15
  %.not = icmp eq i8 %5, 0
  br i1 %.not, label %20, label %81

20:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %8) #4
  %21 = getelementptr inbounds i8, ptr %0, i64 496
  %22 = tail call zeroext i16 @gsd_name_id_map_find(ptr noundef nonnull %21, ptr noundef %1)
  store i16 %22, ptr %8, align 2, !tbaa !17
  %23 = icmp eq i16 %22, -1
  br i1 %23, label %24, label %28

24:                                               ; preds = %20
  %25 = call i32 @gsd_append_name(ptr noundef nonnull %8, ptr noundef nonnull %0, ptr noundef %1)
  %.not66 = icmp eq i32 %25, 0
  br i1 %.not66, label %26, label %.thread

26:                                               ; preds = %24
  %27 = load i16, ptr %8, align 2, !tbaa !17
  %.not84 = icmp eq i16 %27, -1
  br i1 %.not84, label %.thread, label %28

28:                                               ; preds = %26, %20
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %9) #4
  call void @gsd_util_zero_memory(ptr noundef nonnull %9, i64 noundef 32)
  %29 = getelementptr inbounds i8, ptr %0, i64 472
  %30 = load i64, ptr %29, align 8, !tbaa !19
  store i64 %30, ptr %9, align 8, !tbaa !20
  %31 = load i16, ptr %8, align 2, !tbaa !17
  %32 = getelementptr inbounds i8, ptr %9, i64 28
  store i16 %31, ptr %32, align 4, !tbaa !22
  %33 = trunc i32 %2 to i8
  %34 = getelementptr inbounds i8, ptr %9, i64 30
  store i8 %33, ptr %34, align 2, !tbaa !23
  %35 = getelementptr inbounds i8, ptr %9, i64 8
  store i64 %3, ptr %35, align 8, !tbaa !24
  %36 = getelementptr inbounds i8, ptr %9, i64 24
  store i32 %4, ptr %36, align 8, !tbaa !25
  %37 = zext i32 %4 to i64
  %38 = mul i64 %37, %3
  %39 = call i64 @gsd_sizeof_type(i32 noundef %2)
  %40 = mul i64 %38, %39
  %41 = getelementptr inbounds i8, ptr %0, i64 520
  %42 = load i64, ptr %41, align 8, !tbaa !26
  %43 = icmp ult i64 %40, %42
  br i1 %43, label %44, label %62

44:                                               ; preds = %28
  %45 = getelementptr inbounds i8, ptr %0, i64 384
  %46 = getelementptr inbounds i8, ptr %0, i64 392
  %47 = load i64, ptr %46, align 8, !tbaa !27
  %48 = sub i64 %42, %47
  %49 = icmp ugt i64 %40, %48
  br i1 %49, label %50, label %52

50:                                               ; preds = %44
  %51 = call i32 @gsd_flush_write_buffer(ptr noundef nonnull %0)
  %.pre = load i64, ptr %46, align 8, !tbaa !27
  br label %52

52:                                               ; preds = %50, %44
  %53 = phi i64 [ %.pre, %50 ], [ %47, %44 ]
  %54 = getelementptr inbounds i8, ptr %9, i64 16
  store i64 %53, ptr %54, align 8, !tbaa !28
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %10) #4
  %55 = getelementptr inbounds i8, ptr %0, i64 344
  %56 = call i32 @gsd_index_buffer_add(ptr noundef nonnull %55, ptr noundef nonnull %10)
  %.not69 = icmp eq i32 %56, 0
  br i1 %.not69, label %57, label %.thread77

57:                                               ; preds = %52
  %58 = load ptr, ptr %10, align 8, !tbaa !29
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %58, ptr noundef nonnull align 8 dereferenceable(32) %9, i64 32, i1 false), !tbaa.struct !30
  %.not70 = icmp eq i64 %40, 0
  br i1 %.not70, label %61, label %59

59:                                               ; preds = %57
  %60 = call i32 @gsd_byte_buffer_append(ptr noundef nonnull %45, ptr noundef %6, i64 noundef %40)
  %.not71 = icmp eq i32 %60, 0
  br i1 %.not71, label %61, label %.thread77

.thread77:                                        ; preds = %52, %59
  %.2.ph = phi i32 [ %60, %59 ], [ %56, %52 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #4
  br label %80

61:                                               ; preds = %57, %59
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #4
  br label %76

62:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %11) #4
  %63 = getelementptr inbounds i8, ptr %0, i64 304
  %64 = call i32 @gsd_index_buffer_add(ptr noundef nonnull %63, ptr noundef nonnull %11)
  %.not67 = icmp eq i32 %64, 0
  br i1 %.not67, label %65, label %.thread81

65:                                               ; preds = %62
  %66 = load ptr, ptr %11, align 8, !tbaa !29
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %66, ptr noundef nonnull align 8 dereferenceable(32) %9, i64 32, i1 false), !tbaa.struct !30
  %67 = getelementptr inbounds i8, ptr %0, i64 480
  %68 = load i64, ptr %67, align 8, !tbaa !34
  %69 = getelementptr inbounds i8, ptr %66, i64 16
  store i64 %68, ptr %69, align 8, !tbaa !28
  %70 = load i32, ptr %0, align 8, !tbaa !35
  %71 = call i64 @gsd_io_pwrite_retry(i32 noundef %70, ptr noundef %6, i64 noundef %40, i64 noundef %68)
  %72 = icmp ne i64 %71, -1
  %.not68 = icmp eq i64 %71, %40
  %or.cond73 = and i1 %72, %.not68
  br i1 %or.cond73, label %73, label %.thread81

.thread81:                                        ; preds = %62, %65
  %.4.ph = phi i32 [ -1, %65 ], [ %64, %62 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %11) #4
  br label %80

73:                                               ; preds = %65
  %74 = load i64, ptr %67, align 8, !tbaa !34
  %75 = add nsw i64 %74, %40
  store i64 %75, ptr %67, align 8, !tbaa !34
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %11) #4
  br label %76

76:                                               ; preds = %73, %61
  %77 = getelementptr inbounds i8, ptr %0, i64 512
  %78 = load i64, ptr %77, align 8, !tbaa !36
  %79 = add i64 %78, 1
  store i64 %79, ptr %77, align 8, !tbaa !36
  br label %80

80:                                               ; preds = %.thread81, %.thread77, %76
  %.5 = phi i32 [ 0, %76 ], [ %.2.ph, %.thread77 ], [ %.4.ph, %.thread81 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %9) #4
  br label %.thread

.thread:                                          ; preds = %24, %26, %80
  %.6 = phi i32 [ %.5, %80 ], [ -7, %26 ], [ %25, %24 ]
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %8) #4
  br label %81

81:                                               ; preds = %19, %15, %7, %.thread
  %.7 = phi i32 [ %.6, %.thread ], [ -2, %7 ], [ -8, %15 ], [ -2, %19 ]
  ret i32 %.7
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @gsd_name_id_map_find(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @gsd_append_name(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @gsd_sizeof_type(i32 noundef) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @gsd_index_buffer_add(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @gsd_byte_buffer_append(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 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 #4 = { 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, !7, i64 488}
!6 = !{!"gsd_handle", !7, i64 0, !10, i64 8, !12, i64 264, !12, i64 304, !12, i64 344, !14, i64 384, !15, i64 408, !15, i64 440, !11, i64 472, !11, i64 480, !7, i64 488, !16, i64 496, !11, i64 512, !11, i64 520, !11, i64 528}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"gsd_header", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !7, i64 40, !7, i64 44, !8, i64 48, !8, i64 112, !8, i64 176}
!11 = !{!"long", !8, i64 0}
!12 = !{!"gsd_index_buffer", !13, i64 0, !11, i64 8, !11, i64 16, !13, i64 24, !11, i64 32}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!"gsd_byte_buffer", !13, i64 0, !11, i64 8, !11, i64 16}
!15 = !{!"gsd_name_buffer", !14, i64 0, !11, i64 24}
!16 = !{!"gsd_name_id_map", !13, i64 0, !11, i64 8}
!17 = !{!18, !18, i64 0}
!18 = !{!"short", !8, i64 0}
!19 = !{!6, !11, i64 472}
!20 = !{!21, !11, i64 0}
!21 = !{!"gsd_index_entry", !11, i64 0, !11, i64 8, !11, i64 16, !7, i64 24, !18, i64 28, !8, i64 30, !8, i64 31}
!22 = !{!21, !18, i64 28}
!23 = !{!21, !8, i64 30}
!24 = !{!21, !11, i64 8}
!25 = !{!21, !7, i64 24}
!26 = !{!6, !11, i64 520}
!27 = !{!6, !11, i64 392}
!28 = !{!21, !11, i64 16}
!29 = !{!13, !13, i64 0}
!30 = !{i64 0, i64 8, !31, i64 8, i64 8, !31, i64 16, i64 8, !31, i64 24, i64 4, !32, i64 28, i64 2, !17, i64 30, i64 1, !33, i64 31, i64 1, !33}
!31 = !{!11, !11, i64 0}
!32 = !{!7, !7, i64 0}
!33 = !{!8, !8, i64 0}
!34 = !{!6, !11, i64 480}
!35 = !{!6, !7, i64 0}
!36 = !{!6, !11, i64 512}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass