; LLVM IR from golems/ach :: src (libach)

; 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.ach_channel_vtab = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32 }
%struct.anon.4 = type { %union.anon.5, ptr, %union.anon.6 }
%union.anon.5 = type { i32 }
%union.anon.6 = type { i64 }
%struct.ach_attr = type { %union.anon.3 }
%union.anon.3 = type { [8 x i64] }
%struct.ach_channel = type { %union.anon.8 }
%union.anon.8 = type { [16 x i64] }
%struct.anon.9 = type { ptr, i64, i32, %union.anon.10, i64, i32, i32, ptr, i32 }
%union.anon.10 = type { %struct.achk_opt }
%struct.achk_opt = type { i32, %struct.timespec }
%struct.timespec = type { i64, i64 }

@libach_vtabs = external hidden global [4 x ptr], align 16
@libach_vtab_klinux = external constant %struct.ach_channel_vtab, align 8
@default_ach_attr = external hidden global { { %struct.anon.4, [40 x i8] } }, align 8

; 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 hidden i32 @bad_map(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @ach_open(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 i32, align 4
  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
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 -1, ptr %9, align 4, !tbaa !9
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  %12 = icmp eq ptr null, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  store ptr @default_ach_attr, ptr %7, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %13, %3
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ach_attr, ptr %15, i32 0, i32 0
  %17 = getelementptr inbounds %struct.anon.4, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %19 = call i32 @bad_map(i32 noundef %18)
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %14
  store i32 12, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %126

22:                                               ; preds = %14
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ach_attr, ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds %struct.anon.4, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds [4 x ptr], ptr @libach_vtabs, i64 0, i64 %27
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ach_channel_vtab, ptr %29, i32 0, i32 11
  %31 = load ptr, ptr %30, align 8, !tbaa !12
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = call i32 %31(ptr noundef %32)
  store i32 %33, ptr %8, align 4, !tbaa !9
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = icmp ne i32 0, %34
  br i1 %35, label %36, label %38

36:                                               ; preds = %22
  %37 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %37, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %126

38:                                               ; preds = %22
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ach_attr, ptr %39, i32 0, i32 0
  %41 = getelementptr inbounds %struct.anon.4, ptr %40, i32 0, i32 2
  %42 = load i8, ptr %41, align 8
  %43 = and i8 %42, 1
  %44 = zext i8 %43 to i32
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %61

46:                                               ; preds = %38
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = call i32 @open_source_lock(ptr noundef %47, ptr noundef %9)
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = call i32 @lockf(i32 noundef %49, i32 noundef 2, i64 noundef 0)
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %60

52:                                               ; preds = %46
  %53 = call ptr @__errno_location() #5
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = icmp eq i32 13, %54
  br i1 %55, label %56, label %58

56:                                               ; preds = %52
  %57 = call ptr @__errno_location() #5
  store i32 11, ptr %57, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %56, %52
  %59 = call i32 @check_errno()
  store i32 %59, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %126

60:                                               ; preds = %46
  br label %61

61:                                               ; preds = %60, %38
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.ach_attr, ptr %62, i32 0, i32 0
  %64 = getelementptr inbounds %struct.anon.4, ptr %63, i32 0, i32 0
  %65 = load i32, ptr %64, align 8, !tbaa !11
  %66 = icmp eq i32 0, %65
  br i1 %66, label %67, label %85

67:                                               ; preds = %61
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.ach_channel, ptr %68, i32 0, i32 0
  %70 = getelementptr inbounds %struct.anon.9, ptr %69, i32 0, i32 7
  store ptr @libach_vtab_klinux, ptr %70, align 8, !tbaa !11
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.ach_channel, ptr %71, i32 0, i32 0
  %73 = getelementptr inbounds %struct.anon.9, ptr %72, i32 0, i32 7
  %74 = load ptr, ptr %73, align 8, !tbaa !11
  %75 = getelementptr inbounds %struct.ach_channel_vtab, ptr %74, i32 0, i32 1
  %76 = load ptr, ptr %75, align 8, !tbaa !14
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  %80 = call i32 %76(ptr noundef %77, ptr noundef %78, ptr noundef %79)
  store i32 %80, ptr %8, align 4, !tbaa !9
  %81 = load i32, ptr %8, align 4, !tbaa !9
  switch i32 %81, label %83 [
    i32 9, label %82
    i32 15, label %82
  ]

82:                                               ; preds = %67, %67
  br label %84

83:                                               ; preds = %67
  br label %106

84:                                               ; preds = %82
  br label %85

85:                                               ; preds = %84, %61
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.ach_attr, ptr %86, i32 0, i32 0
  %88 = getelementptr inbounds %struct.anon.4, ptr %87, i32 0, i32 0
  %89 = load i32, ptr %88, align 8, !tbaa !11
  %90 = zext i32 %89 to i64
  %91 = getelementptr inbounds [4 x ptr], ptr @libach_vtabs, i64 0, i64 %90
  %92 = load ptr, ptr %91, align 8, !tbaa !5
  %93 = load ptr, ptr %5, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.ach_channel, ptr %93, i32 0, i32 0
  %95 = getelementptr inbounds %struct.anon.9, ptr %94, i32 0, i32 7
  store ptr %92, ptr %95, align 8, !tbaa !11
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.ach_channel, ptr %96, i32 0, i32 0
  %98 = getelementptr inbounds %struct.anon.9, ptr %97, i32 0, i32 7
  %99 = load ptr, ptr %98, align 8, !tbaa !11
  %100 = getelementptr inbounds %struct.ach_channel_vtab, ptr %99, i32 0, i32 1
  %101 = load ptr, ptr %100, align 8, !tbaa !14
  %102 = load ptr, ptr %5, align 8, !tbaa !5
  %103 = load ptr, ptr %6, align 8, !tbaa !5
  %104 = load ptr, ptr %7, align 8, !tbaa !5
  %105 = call i32 %101(ptr noundef %102, ptr noundef %103, ptr noundef %104)
  store i32 %105, ptr %8, align 4, !tbaa !9
  br label %106

106:                                              ; preds = %85, %83
  %107 = load i32, ptr %8, align 4, !tbaa !9
  %108 = icmp ne i32 0, %107
  br i1 %108, label %109, label %120

109:                                              ; preds = %106
  %110 = load ptr, ptr %7, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.ach_attr, ptr %110, i32 0, i32 0
  %112 = getelementptr inbounds %struct.anon.4, ptr %111, i32 0, i32 2
  %113 = load i8, ptr %112, align 8
  %114 = and i8 %113, 1
  %115 = zext i8 %114 to i32
  %116 = icmp ne i32 %115, 0
  br i1 %116, label %117, label %120

117:                                              ; preds = %109
  %118 = load i32, ptr %9, align 4, !tbaa !9
  %119 = call i32 @lockf(i32 noundef %118, i32 noundef 0, i64 noundef 0)
  br label %120

120:                                              ; preds = %117, %109, %106
  %121 = load i32, ptr %9, align 4, !tbaa !9
  %122 = load ptr, ptr %5, align 8, !tbaa !5
  %123 = getelementptr inbounds %struct.ach_channel, ptr %122, i32 0, i32 0
  %124 = getelementptr inbounds %struct.anon.9, ptr %123, i32 0, i32 8
  store i32 %121, ptr %124, align 8, !tbaa !11
  %125 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %125, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %126

126:                                              ; preds = %120, %58, %36, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %127 = load i32, ptr %4, align 4
  ret i32 %127
}

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

declare i32 @lockf(i32 noundef, i32 noundef, i64 noundef) #2

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #3

; Function Attrs: nounwind uwtable
declare hidden i32 @check_errno() #1

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 = { "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 willreturn memory(none) "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 = { nounwind willreturn memory(none) }

!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 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 88}
!13 = !{!"ach_channel_vtab", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !10, i64 96}
!14 = !{!13, !6, 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"

%struct.ach_channel_vtab = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32 }
%struct.anon.4 = type { %union.anon.5, ptr, %union.anon.6 }
%union.anon.5 = type { i32 }
%union.anon.6 = type { i64 }

@libach_vtabs = external hidden local_unnamed_addr global [4 x ptr], align 16
@libach_vtab_klinux = external constant %struct.ach_channel_vtab, align 8
@default_ach_attr = external hidden global { { %struct.anon.4, [40 x i8] } }, align 8

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

; Function Attrs: nounwind uwtable
define dso_local i32 @ach_open(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  store i32 -1, ptr %4, align 4, !tbaa !5
  %5 = icmp eq ptr %2, null
  %spec.store.select = select i1 %5, ptr @default_ach_attr, ptr %2
  %6 = load i32, ptr %spec.store.select, align 8, !tbaa !9
  %7 = tail call i32 @bad_map(i32 noundef %6)
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %8, label %57

8:                                                ; preds = %3
  %9 = load i32, ptr %spec.store.select, align 8, !tbaa !9
  %10 = zext i32 %9 to i64
  %11 = getelementptr inbounds [4 x ptr], ptr @libach_vtabs, i64 0, i64 %10
  %12 = load ptr, ptr %11, align 8, !tbaa !10
  %13 = getelementptr inbounds i8, ptr %12, i64 88
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = tail call i32 %14(ptr noundef %1) #4
  %.not27 = icmp eq i32 %15, 0
  br i1 %.not27, label %16, label %57

16:                                               ; preds = %8
  %17 = getelementptr inbounds i8, ptr %spec.store.select, i64 16
  %18 = load i8, ptr %17, align 8
  %19 = and i8 %18, 1
  %.not28 = icmp eq i8 %19, 0
  br i1 %.not28, label %31, label %20

20:                                               ; preds = %16
  %21 = call i32 @open_source_lock(ptr noundef %1, ptr noundef nonnull %4)
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = call i32 @lockf(i32 noundef %22, i32 noundef 2, i64 noundef 0) #4
  %.not29 = icmp eq i32 %23, 0
  br i1 %.not29, label %31, label %24

24:                                               ; preds = %20
  %25 = tail call ptr @__errno_location() #5
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = icmp eq i32 %26, 13
  br i1 %27, label %28, label %29

28:                                               ; preds = %24
  store i32 11, ptr %25, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %28, %24
  %30 = call i32 @check_errno()
  br label %57

31:                                               ; preds = %20, %16
  %32 = load i32, ptr %spec.store.select, align 8, !tbaa !9
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %38

34:                                               ; preds = %31
  %35 = getelementptr inbounds i8, ptr %0, i64 64
  store ptr @libach_vtab_klinux, ptr %35, align 8, !tbaa !9
  %36 = load ptr, ptr getelementptr inbounds (i8, ptr @libach_vtab_klinux, i64 8), align 8, !tbaa !14
  %37 = call i32 %36(ptr noundef %0, ptr noundef %1, ptr noundef nonnull %spec.store.select) #4
  switch i32 %37, label %47 [
    i32 9, label %38
    i32 15, label %38
  ]

38:                                               ; preds = %34, %34, %31
  %39 = load i32, ptr %spec.store.select, align 8, !tbaa !9
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds [4 x ptr], ptr @libach_vtabs, i64 0, i64 %40
  %42 = load ptr, ptr %41, align 8, !tbaa !10
  %43 = getelementptr inbounds i8, ptr %0, i64 64
  store ptr %42, ptr %43, align 8, !tbaa !9
  %44 = getelementptr inbounds i8, ptr %42, i64 8
  %45 = load ptr, ptr %44, align 8, !tbaa !14
  %46 = call i32 %45(ptr noundef %0, ptr noundef %1, ptr noundef nonnull %spec.store.select) #4
  br label %47

47:                                               ; preds = %34, %38
  %.0 = phi i32 [ %37, %34 ], [ %46, %38 ]
  %.not30 = icmp eq i32 %.0, 0
  br i1 %.not30, label %54, label %48

48:                                               ; preds = %47
  %49 = load i8, ptr %17, align 8
  %50 = and i8 %49, 1
  %.not31 = icmp eq i8 %50, 0
  br i1 %.not31, label %54, label %51

51:                                               ; preds = %48
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = call i32 @lockf(i32 noundef %52, i32 noundef 0, i64 noundef 0) #4
  br label %54

54:                                               ; preds = %51, %48, %47
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %0, i64 72
  store i32 %55, ptr %56, align 8, !tbaa !9
  br label %57

57:                                               ; preds = %8, %3, %54, %29
  %.025 = phi i32 [ %30, %29 ], [ %.0, %54 ], [ 12, %3 ], [ %15, %8 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  ret i32 %.025
}

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

declare i32 @lockf(i32 noundef, i32 noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden i32 @check_errno() local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { "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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { nounwind willreturn memory(none) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !11, i64 88}
!13 = !{!"ach_channel_vtab", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !6, i64 96}
!14 = !{!13, !11, i64 8}


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