; LLVM IR from 0intro/wmii :: lib/libstuff/x11 (xatom)

; 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.Map = type { ptr, i32, i32 }

@atommap = external global %struct.Map, align 8
@display = external global ptr, align 8
@atomnamemap = external global %struct.Map, align 8

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

declare ptr @hash_get(ptr noundef, ptr noundef, i1 noundef zeroext) #1

declare ptr @map_get(ptr noundef, i64 noundef, i1 noundef zeroext) #1

; 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 ptr @atomname(i64 noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %6 = load i64, ptr %3, align 8, !tbaa !5
  %7 = call ptr @map_get(ptr noundef @atomnamemap, i64 noundef %6, i1 noundef zeroext true)
  store ptr %7, ptr %4, align 8, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !9
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %28

11:                                               ; preds = %1
  %12 = load ptr, ptr @display, align 8, !tbaa !9
  %13 = load i64, ptr %3, align 8, !tbaa !5
  %14 = call ptr @XGetAtomName(ptr noundef %12, i64 noundef %13)
  %15 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %14, ptr %15, align 8, !tbaa !9
  %16 = load ptr, ptr %4, align 8, !tbaa !9
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %22

19:                                               ; preds = %11
  %20 = load i64, ptr %3, align 8, !tbaa !5
  %21 = call ptr @map_rm(ptr noundef @atomnamemap, i64 noundef %20)
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %31

22:                                               ; preds = %11
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = inttoptr i64 %23 to ptr
  %25 = load ptr, ptr %4, align 8, !tbaa !9
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  %27 = call ptr @hash_get(ptr noundef @atommap, ptr noundef %26, i1 noundef zeroext true)
  store ptr %24, ptr %27, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %22, %1
  %29 = load ptr, ptr %4, align 8, !tbaa !9
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  store ptr %30, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %31

31:                                               ; preds = %28, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %32 = load ptr, ptr %2, align 8
  ret ptr %32
}

declare ptr @XGetAtomName(ptr noundef, i64 noundef) #1

declare ptr @map_rm(ptr noundef, i64 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, 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"

%struct.Map = type { ptr, i32, i32 }

@atommap = external global %struct.Map, align 8
@display = external local_unnamed_addr global ptr, align 8
@atomnamemap = external global %struct.Map, align 8

declare ptr @hash_get(ptr noundef, ptr noundef, i1 noundef zeroext) local_unnamed_addr #0

declare ptr @map_get(ptr noundef, i64 noundef, i1 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @atomname(i64 noundef %0) local_unnamed_addr #1 {
  %2 = tail call ptr @map_get(ptr noundef nonnull @atomnamemap, i64 noundef %0, i1 noundef zeroext true) #2
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %14

5:                                                ; preds = %1
  %6 = load ptr, ptr @display, align 8, !tbaa !5
  %7 = tail call ptr @XGetAtomName(ptr noundef %6, i64 noundef %0) #2
  store ptr %7, ptr %2, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %11

9:                                                ; preds = %5
  %10 = tail call ptr @map_rm(ptr noundef nonnull @atomnamemap, i64 noundef %0) #2
  br label %14

11:                                               ; preds = %5
  %12 = inttoptr i64 %0 to ptr
  %13 = tail call ptr @hash_get(ptr noundef nonnull @atommap, ptr noundef nonnull %7, i1 noundef zeroext true) #2
  store ptr %12, ptr %13, align 8, !tbaa !5
  %.pre = load ptr, ptr %2, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %1, %11, %9
  %.0 = phi ptr [ null, %9 ], [ %.pre, %11 ], [ %3, %1 ]
  ret ptr %.0
}

declare ptr @XGetAtomName(ptr noundef, i64 noundef) local_unnamed_addr #0

declare ptr @map_rm(ptr noundef, i64 noundef) local_unnamed_addr #0

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


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