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

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

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

declare i32 @close(i32 noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @gsd_open(ptr noundef %0, ptr noundef %1, i32 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  call void @gsd_util_zero_memory(ptr noundef %9, i64 noundef 536)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %12, label %21

12:                                               ; preds = %3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = or i32 2, %14
  %16 = call i32 @gsd_open_file(ptr noundef %13, i32 noundef %15, i32 noundef 0)
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.gsd_handle, ptr %17, i32 0, i32 0
  store i32 %16, ptr %18, align 8, !tbaa !11
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.gsd_handle, ptr %19, i32 0, i32 10
  store i32 1, ptr %20, align 8, !tbaa !19
  br label %47

21:                                               ; preds = %3
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = icmp eq i32 %22, 2
  br i1 %23, label %24, label %33

24:                                               ; preds = %21
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = or i32 0, %26
  %28 = call i32 @gsd_open_file(ptr noundef %25, i32 noundef %27, i32 noundef 0)
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.gsd_handle, ptr %29, i32 0, i32 0
  store i32 %28, ptr %30, align 8, !tbaa !11
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.gsd_handle, ptr %31, i32 0, i32 10
  store i32 2, ptr %32, align 8, !tbaa !19
  br label %46

33:                                               ; preds = %21
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = icmp eq i32 %34, 3
  br i1 %35, label %36, label %45

36:                                               ; preds = %33
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = or i32 2, %38
  %40 = call i32 @gsd_open_file(ptr noundef %37, i32 noundef %39, i32 noundef 0)
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.gsd_handle, ptr %41, i32 0, i32 0
  store i32 %40, ptr %42, align 8, !tbaa !11
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.gsd_handle, ptr %43, i32 0, i32 10
  store i32 3, ptr %44, align 8, !tbaa !19
  br label %45

45:                                               ; preds = %36, %33
  br label %46

46:                                               ; preds = %45, %24
  br label %47

47:                                               ; preds = %46, %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = call i32 @gsd_initialize_handle(ptr noundef %48)
  store i32 %49, ptr %8, align 4, !tbaa !9
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %63

52:                                               ; preds = %47
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.gsd_handle, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 8, !tbaa !11
  %56 = icmp ne i32 %55, -1
  br i1 %56, label %57, label %62

57:                                               ; preds = %52
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.gsd_handle, ptr %58, i32 0, i32 0
  %60 = load i32, ptr %59, align 8, !tbaa !11
  %61 = call i32 @close(i32 noundef %60)
  br label %62

62:                                               ; preds = %57, %52
  br label %63

63:                                               ; preds = %62, %47
  %64 = load i32, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret i32 %64
}

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 = { "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 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, !10, i64 0}
!12 = !{!"gsd_handle", !10, i64 0, !13, i64 8, !15, i64 264, !15, i64 304, !15, i64 344, !16, i64 384, !17, i64 408, !17, i64 440, !14, i64 472, !14, i64 480, !10, i64 488, !18, i64 496, !14, i64 512, !14, i64 520, !14, i64 528}
!13 = !{!"gsd_header", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !10, i64 40, !10, i64 44, !7, i64 48, !7, i64 112, !7, i64 176}
!14 = !{!"long", !7, i64 0}
!15 = !{!"gsd_index_buffer", !6, i64 0, !14, i64 8, !14, i64 16, !6, i64 24, !14, i64 32}
!16 = !{!"gsd_byte_buffer", !6, i64 0, !14, i64 8, !14, i64 16}
!17 = !{!"gsd_name_buffer", !16, i64 0, !14, i64 24}
!18 = !{!"gsd_name_id_map", !6, i64 0, !14, i64 8}
!19 = !{!12, !10, i64 488}


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

@switch.table.gsd_open = private unnamed_addr constant [3 x i32] [i32 2, i32 0, i32 2], align 4

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

declare i32 @close(i32 noundef) local_unnamed_addr #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @gsd_initialize_handle(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @gsd_open(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #2 {
  tail call void @gsd_util_zero_memory(ptr noundef %0, i64 noundef 536)
  %switch.tableidx = add i32 %2, -1
  %4 = icmp ult i32 %switch.tableidx, 3
  br i1 %4, label %switch.lookup, label %8

switch.lookup:                                    ; preds = %3
  %5 = zext nneg i32 %switch.tableidx to i64
  %switch.gep = getelementptr inbounds [3 x i32], ptr @switch.table.gsd_open, i64 0, i64 %5
  %switch.load = load i32, ptr %switch.gep, align 4
  %6 = tail call i32 @gsd_open_file(ptr noundef %1, i32 noundef %switch.load, i32 noundef 0)
  store i32 %6, ptr %0, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 488
  store i32 %2, ptr %7, align 8, !tbaa !17
  br label %8

8:                                                ; preds = %3, %switch.lookup
  %9 = tail call i32 @gsd_initialize_handle(ptr noundef %0)
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %14, label %10

10:                                               ; preds = %8
  %11 = load i32, ptr %0, align 8, !tbaa !5
  %.not21 = icmp eq i32 %11, -1
  br i1 %.not21, label %14, label %12

12:                                               ; preds = %10
  %13 = tail call i32 @close(i32 noundef %11) #3
  br label %14

14:                                               ; preds = %10, %12, %8
  ret i32 %9
}

attributes #0 = { 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 #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, !7, i64 0}
!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 = !{!6, !7, i64 488}


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