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

%union.anon = type { i32 }
%struct.anon = type { i8, [3 x i8] }
%struct.ach_channel_vtab = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32 }
%struct.ach_create_attr = type { %union.anon.2 }
%union.anon.2 = type { [16 x i64] }
%struct.anon.1 = type { %union.anon, ptr, i32, %union.anon.0 }
%union.anon.0 = type { i64 }

@default_create_attr = external dso_local global { { { %union.anon, ptr, i32, [4 x i8], { %struct.anon, [4 x i8] } }, [96 x i8] } }, align 8
@libach_vtabs = external hidden global [4 x ptr], align 16
@libach_vtab_klinux = external constant %struct.ach_channel_vtab, align 8
@libach_vtab_user = external constant %struct.ach_channel_vtab, 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
define dso_local i32 @ach_create(ptr noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i64 %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %14 = load ptr, ptr %9, align 8, !tbaa !5
  %15 = icmp eq ptr null, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %4
  store ptr @default_create_attr, ptr %9, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %16, %4
  %18 = load i64, ptr %7, align 8, !tbaa !9
  %19 = icmp eq i64 0, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  store i64 16, ptr %7, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %20, %17
  %22 = load i64, ptr %8, align 8, !tbaa !9
  %23 = icmp eq i64 0, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  store i64 512, ptr %8, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %24, %21
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ach_create_attr, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds %struct.anon.1, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !11
  %30 = call i32 @bad_map(i32 noundef %29)
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %25
  store i32 12, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %84

33:                                               ; preds = %25
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ach_create_attr, ptr %34, i32 0, i32 0
  %36 = getelementptr inbounds %struct.anon.1, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 8, !tbaa !11
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds [4 x ptr], ptr @libach_vtabs, i64 0, i64 %38
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  store ptr %40, ptr %10, align 8, !tbaa !5
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.ach_channel_vtab, ptr %41, i32 0, i32 11
  %43 = load ptr, ptr %42, align 8, !tbaa !12
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = call i32 %43(ptr noundef %44)
  store i32 %45, ptr %12, align 4, !tbaa !15
  %46 = load i32, ptr %12, align 4, !tbaa !15
  %47 = icmp ne i32 0, %46
  br i1 %47, label %48, label %50

48:                                               ; preds = %33
  %49 = load i32, ptr %12, align 4, !tbaa !15
  store i32 %49, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %84

50:                                               ; preds = %33
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ach_create_attr, ptr %51, i32 0, i32 0
  %53 = getelementptr inbounds %struct.anon.1, ptr %52, i32 0, i32 0
  %54 = load i32, ptr %53, align 8, !tbaa !11
  %55 = icmp eq i32 0, %54
  br i1 %55, label %56, label %75

56:                                               ; preds = %50
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.ach_channel_vtab, ptr %57, i32 0, i32 12
  %59 = load i32, ptr %58, align 8, !tbaa !16
  switch i32 %59, label %62 [
    i32 2, label %60
    i32 3, label %61
  ]

60:                                               ; preds = %56
  store ptr @libach_vtab_klinux, ptr %11, align 8, !tbaa !5
  br label %63

61:                                               ; preds = %56
  store ptr @libach_vtab_user, ptr %11, align 8, !tbaa !5
  br label %63

62:                                               ; preds = %56
  store ptr null, ptr %11, align 8, !tbaa !5
  br label %63

63:                                               ; preds = %62, %61, %60
  %64 = load ptr, ptr %11, align 8, !tbaa !5
  %65 = icmp ne ptr %64, null
  br i1 %65, label %66, label %74

66:                                               ; preds = %63
  %67 = load ptr, ptr %11, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.ach_channel_vtab, ptr %67, i32 0, i32 8
  %69 = load ptr, ptr %68, align 8, !tbaa !17
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = call i32 %69(ptr noundef %70)
  %72 = icmp eq i32 0, %71
  br i1 %72, label %73, label %74

73:                                               ; preds = %66
  store i32 8, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %84

74:                                               ; preds = %66, %63
  br label %75

75:                                               ; preds = %74, %50
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.ach_channel_vtab, ptr %76, i32 0, i32 0
  %78 = load ptr, ptr %77, align 8, !tbaa !18
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = load i64, ptr %7, align 8, !tbaa !9
  %81 = load i64, ptr %8, align 8, !tbaa !9
  %82 = load ptr, ptr %9, align 8, !tbaa !5
  %83 = call i32 %78(ptr noundef %79, i64 noundef %80, i64 noundef %81, ptr noundef %82)
  store i32 %83, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %84

84:                                               ; preds = %75, %73, %48, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %85 = load i32, ptr %5, align 4
  ret i32 %85
}

; Function Attrs: nounwind uwtable
declare hidden i32 @bad_map(i32 noundef) #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 = { 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 = !{!"long", !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, !14, i64 96}
!14 = !{!"int", !7, i64 0}
!15 = !{!14, !14, i64 0}
!16 = !{!13, !14, i64 96}
!17 = !{!13, !6, i64 64}
!18 = !{!13, !6, 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"

%union.anon = type { i32 }
%struct.anon = type { i8, [3 x i8] }
%struct.ach_channel_vtab = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32 }

@default_create_attr = external dso_local global { { { %union.anon, ptr, i32, [4 x i8], { %struct.anon, [4 x i8] } }, [96 x i8] } }, align 8
@libach_vtabs = external hidden local_unnamed_addr global [4 x ptr], align 16
@libach_vtab_klinux = external local_unnamed_addr constant %struct.ach_channel_vtab, align 8
@libach_vtab_user = external local_unnamed_addr constant %struct.ach_channel_vtab, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @ach_create(ptr noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %3, null
  %spec.store.select = select i1 %5, ptr @default_create_attr, ptr %3
  %6 = icmp eq i64 %1, 0
  %spec.store.select2 = select i1 %6, i64 16, i64 %1
  %7 = icmp eq i64 %2, 0
  %spec.store.select1 = select i1 %7, i64 512, i64 %2
  %8 = load i32, ptr %spec.store.select, align 8, !tbaa !5
  %9 = tail call i32 @bad_map(i32 noundef %8)
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %10, label %33

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

18:                                               ; preds = %10
  %19 = load i32, ptr %spec.store.select, align 8, !tbaa !5
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %30

21:                                               ; preds = %18
  %22 = getelementptr inbounds i8, ptr %14, i64 96
  %23 = load i32, ptr %22, align 8, !tbaa !13
  switch i32 %23, label %30 [
    i32 2, label %25
    i32 3, label %24
  ]

24:                                               ; preds = %21
  br label %25

25:                                               ; preds = %24, %21
  %.021.ph = phi ptr [ @libach_vtab_klinux, %21 ], [ @libach_vtab_user, %24 ]
  %26 = getelementptr inbounds i8, ptr %.021.ph, i64 64
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = tail call i32 %27(ptr noundef %0) #1
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %33, label %30

30:                                               ; preds = %21, %25, %18
  %31 = load ptr, ptr %14, align 8, !tbaa !15
  %32 = tail call i32 %31(ptr noundef %0, i64 noundef %spec.store.select2, i64 noundef %spec.store.select1, ptr noundef nonnull %spec.store.select) #1
  br label %33

33:                                               ; preds = %25, %10, %4, %30
  %.0 = phi i32 [ %32, %30 ], [ 12, %4 ], [ %17, %10 ], [ 8, %25 ]
  ret i32 %.0
}

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

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


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