; 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_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 }
%struct.gsd_index_entry = type { i64, i64, i64, i32, i16, i8, 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 uwtable
declare dso_local i32 @gsd_flush(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @gsd_read_chunk(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %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 i64, align 8
  %11 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %3
  store i32 -2, ptr %4, align 4
  br label %94

15:                                               ; preds = %3
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %15
  store i32 -2, ptr %4, align 4
  br label %94

19:                                               ; preds = %15
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %23

22:                                               ; preds = %19
  store i32 -2, ptr %4, align 4
  br label %94

23:                                               ; preds = %19
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.gsd_handle, ptr %24, i32 0, i32 10
  %26 = load i32, ptr %25, align 8, !tbaa !9
  %27 = icmp ne i32 %26, 2
  br i1 %27, label %28, label %39

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = call i32 @gsd_flush(ptr noundef %29)
  store i32 %30, ptr %8, align 4, !tbaa !18
  %31 = load i32, ptr %8, align 4, !tbaa !18
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %35

33:                                               ; preds = %28
  %34 = load i32, ptr %8, align 4, !tbaa !18
  store i32 %34, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %36

35:                                               ; preds = %28
  store i32 0, ptr %9, align 4
  br label %36

36:                                               ; preds = %35, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %37 = load i32, ptr %9, align 4
  switch i32 %37, label %96 [
    i32 0, label %38
    i32 1, label %94
  ]

38:                                               ; preds = %36
  br label %39

39:                                               ; preds = %38, %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.gsd_index_entry, ptr %40, i32 0, i32 1
  %42 = load i64, ptr %41, align 8, !tbaa !19
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.gsd_index_entry, ptr %43, i32 0, i32 3
  %45 = load i32, ptr %44, align 8, !tbaa !22
  %46 = zext i32 %45 to i64
  %47 = mul i64 %42, %46
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.gsd_index_entry, ptr %48, i32 0, i32 5
  %50 = load i8, ptr %49, align 2, !tbaa !23
  %51 = zext i8 %50 to i32
  %52 = call i64 @gsd_sizeof_type(i32 noundef %51)
  %53 = mul i64 %47, %52
  store i64 %53, ptr %10, align 8, !tbaa !24
  %54 = load i64, ptr %10, align 8, !tbaa !24
  %55 = icmp eq i64 %54, 0
  br i1 %55, label %56, label %57

56:                                               ; preds = %39
  store i32 -5, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %93

57:                                               ; preds = %39
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.gsd_index_entry, ptr %58, i32 0, i32 2
  %60 = load i64, ptr %59, align 8, !tbaa !25
  %61 = icmp eq i64 %60, 0
  br i1 %61, label %62, label %63

62:                                               ; preds = %57
  store i32 -5, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %93

63:                                               ; preds = %57
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.gsd_index_entry, ptr %64, i32 0, i32 2
  %66 = load i64, ptr %65, align 8, !tbaa !25
  %67 = load i64, ptr %10, align 8, !tbaa !24
  %68 = add i64 %66, %67
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.gsd_handle, ptr %69, i32 0, i32 9
  %71 = load i64, ptr %70, align 8, !tbaa !26
  %72 = icmp ugt i64 %68, %71
  br i1 %72, label %73, label %74

73:                                               ; preds = %63
  store i32 -5, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %93

74:                                               ; preds = %63
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.gsd_handle, ptr %75, i32 0, i32 0
  %77 = load i32, ptr %76, align 8, !tbaa !27
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = load i64, ptr %10, align 8, !tbaa !24
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.gsd_index_entry, ptr %80, i32 0, i32 2
  %82 = load i64, ptr %81, align 8, !tbaa !25
  %83 = call i64 @gsd_io_pread_retry(i32 noundef %77, ptr noundef %78, i64 noundef %79, i64 noundef %82)
  store i64 %83, ptr %11, align 8, !tbaa !24
  %84 = load i64, ptr %11, align 8, !tbaa !24
  %85 = icmp eq i64 %84, -1
  br i1 %85, label %90, label %86

86:                                               ; preds = %74
  %87 = load i64, ptr %11, align 8, !tbaa !24
  %88 = load i64, ptr %10, align 8, !tbaa !24
  %89 = icmp ne i64 %87, %88
  br i1 %89, label %90, label %91

90:                                               ; preds = %86, %74
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %92

91:                                               ; preds = %86
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %92

92:                                               ; preds = %91, %90
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %93

93:                                               ; preds = %92, %73, %62, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %94

94:                                               ; preds = %93, %36, %22, %18, %14
  %95 = load i32, ptr %4, align 4
  ret i32 %95

96:                                               ; preds = %36
  unreachable
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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, !11, i64 488}
!10 = !{!"gsd_handle", !11, i64 0, !12, i64 8, !14, i64 264, !14, i64 304, !14, i64 344, !15, i64 384, !16, i64 408, !16, i64 440, !13, i64 472, !13, i64 480, !11, i64 488, !17, i64 496, !13, i64 512, !13, i64 520, !13, i64 528}
!11 = !{!"int", !7, i64 0}
!12 = !{!"gsd_header", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !11, i64 40, !11, i64 44, !7, i64 48, !7, i64 112, !7, i64 176}
!13 = !{!"long", !7, i64 0}
!14 = !{!"gsd_index_buffer", !6, i64 0, !13, i64 8, !13, i64 16, !6, i64 24, !13, i64 32}
!15 = !{!"gsd_byte_buffer", !6, i64 0, !13, i64 8, !13, i64 16}
!16 = !{!"gsd_name_buffer", !15, i64 0, !13, i64 24}
!17 = !{!"gsd_name_id_map", !6, i64 0, !13, i64 8}
!18 = !{!11, !11, i64 0}
!19 = !{!20, !13, i64 8}
!20 = !{!"gsd_index_entry", !13, i64 0, !13, i64 8, !13, i64 16, !11, i64 24, !21, i64 28, !7, i64 30, !7, i64 31}
!21 = !{!"short", !7, i64 0}
!22 = !{!20, !11, i64 24}
!23 = !{!20, !7, i64 30}
!24 = !{!13, !13, i64 0}
!25 = !{!20, !13, i64 16}
!26 = !{!10, !13, i64 480}
!27 = !{!10, !11, 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: nounwind uwtable
declare dso_local i32 @gsd_flush(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @gsd_read_chunk(ptr noundef %0, ptr noundef %1, ptr noundef readonly %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %0, null
  %5 = icmp eq ptr %1, null
  %or.cond31 = or i1 %4, %5
  %6 = icmp eq ptr %2, null
  %or.cond32 = or i1 %or.cond31, %6
  br i1 %or.cond32, label %38, label %7

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 488
  %9 = load i32, ptr %8, align 8, !tbaa !5
  %.not = icmp eq i32 %9, 2
  br i1 %.not, label %12, label %10

10:                                               ; preds = %7
  %11 = tail call i32 @gsd_flush(ptr noundef nonnull %0)
  %.not29.not = icmp eq i32 %11, 0
  br i1 %.not29.not, label %12, label %38

12:                                               ; preds = %10, %7
  %13 = getelementptr inbounds i8, ptr %2, i64 8
  %14 = load i64, ptr %13, align 8, !tbaa !17
  %15 = getelementptr inbounds i8, ptr %2, i64 24
  %16 = load i32, ptr %15, align 8, !tbaa !20
  %17 = zext i32 %16 to i64
  %18 = mul i64 %14, %17
  %19 = getelementptr inbounds i8, ptr %2, i64 30
  %20 = load i8, ptr %19, align 2, !tbaa !21
  %21 = zext i8 %20 to i32
  %22 = tail call i64 @gsd_sizeof_type(i32 noundef %21)
  %23 = mul i64 %18, %22
  %24 = icmp eq i64 %23, 0
  br i1 %24, label %38, label %25

25:                                               ; preds = %12
  %26 = getelementptr inbounds i8, ptr %2, i64 16
  %27 = load i64, ptr %26, align 8, !tbaa !22
  %28 = icmp eq i64 %27, 0
  br i1 %28, label %38, label %29

29:                                               ; preds = %25
  %30 = add i64 %27, %23
  %31 = getelementptr inbounds i8, ptr %0, i64 480
  %32 = load i64, ptr %31, align 8, !tbaa !23
  %33 = icmp ugt i64 %30, %32
  br i1 %33, label %38, label %34

34:                                               ; preds = %29
  %35 = load i32, ptr %0, align 8, !tbaa !24
  %36 = tail call i64 @gsd_io_pread_retry(i32 noundef %35, ptr noundef nonnull %1, i64 noundef %23, i64 noundef %27)
  %37 = icmp eq i64 %36, -1
  %.not30 = icmp ne i64 %36, %23
  %or.cond.not = or i1 %37, %.not30
  %.1 = sext i1 %or.cond.not to i32
  br label %38

38:                                               ; preds = %10, %34, %12, %25, %29, %3
  %.3 = phi i32 [ %11, %10 ], [ -2, %3 ], [ %.1, %34 ], [ -5, %12 ], [ -5, %25 ], [ -5, %29 ]
  ret i32 %.3
}

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

attributes #0 = { 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 #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" }

!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, !11, i64 8}
!18 = !{!"gsd_index_entry", !11, i64 0, !11, i64 8, !11, i64 16, !7, i64 24, !19, i64 28, !8, i64 30, !8, i64 31}
!19 = !{!"short", !8, i64 0}
!20 = !{!18, !7, i64 24}
!21 = !{!18, !8, i64 30}
!22 = !{!18, !11, i64 16}
!23 = !{!6, !11, i64 480}
!24 = !{!6, !7, i64 0}


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