; LLVM IR from marcobambini/gravity :: src/compiler (gravity_token)

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

@.str.93 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.94 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.95 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.96 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.97 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @token_special_builtin(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.gtoken_s, ptr %7, i32 0, i32 8
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %9, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.gtoken_s, ptr %10, i32 0, i32 4
  %12 = load i32, ptr %11, align 8, !tbaa !12
  store i32 %12, ptr %5, align 4, !tbaa !13
  %13 = load i32, ptr %5, align 4, !tbaa !13
  switch i32 %13, label %63 [
    i32 8, label %14
    i32 9, label %33
    i32 10, label %43
    i32 12, label %53
  ]

14:                                               ; preds = %1
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load i32, ptr %5, align 4, !tbaa !13
  %17 = sext i32 %16 to i64
  %18 = call i32 @string_casencmp(ptr noundef %15, ptr noundef @.str.93, i64 noundef %17)
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %23

20:                                               ; preds = %14
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.gtoken_s, ptr %21, i32 0, i32 7
  store i32 1, ptr %22, align 4, !tbaa !14
  store i32 4, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %64

23:                                               ; preds = %14
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load i32, ptr %5, align 4, !tbaa !13
  %26 = sext i32 %25 to i64
  %27 = call i32 @string_casencmp(ptr noundef %24, ptr noundef @.str.94, i64 noundef %26)
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %32

29:                                               ; preds = %23
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.gtoken_s, ptr %30, i32 0, i32 7
  store i32 3, ptr %31, align 4, !tbaa !14
  store i32 3, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %64

32:                                               ; preds = %23
  br label %63

33:                                               ; preds = %1
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load i32, ptr %5, align 4, !tbaa !13
  %36 = sext i32 %35 to i64
  %37 = call i32 @string_casencmp(ptr noundef %34, ptr noundef @.str.95, i64 noundef %36)
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %39, label %42

39:                                               ; preds = %33
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.gtoken_s, ptr %40, i32 0, i32 7
  store i32 5, ptr %41, align 4, !tbaa !14
  store i32 3, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %64

42:                                               ; preds = %33
  br label %63

43:                                               ; preds = %1
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = load i32, ptr %5, align 4, !tbaa !13
  %46 = sext i32 %45 to i64
  %47 = call i32 @string_casencmp(ptr noundef %44, ptr noundef @.str.96, i64 noundef %46)
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %52

49:                                               ; preds = %43
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.gtoken_s, ptr %50, i32 0, i32 7
  store i32 2, ptr %51, align 4, !tbaa !14
  store i32 4, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %64

52:                                               ; preds = %43
  br label %63

53:                                               ; preds = %1
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = load i32, ptr %5, align 4, !tbaa !13
  %56 = sext i32 %55 to i64
  %57 = call i32 @string_casencmp(ptr noundef %54, ptr noundef @.str.97, i64 noundef %56)
  %58 = icmp eq i32 %57, 0
  br i1 %58, label %59, label %62

59:                                               ; preds = %53
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.gtoken_s, ptr %60, i32 0, i32 7
  store i32 4, ptr %61, align 4, !tbaa !14
  store i32 3, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %64

62:                                               ; preds = %53
  br label %63

63:                                               ; preds = %62, %52, %42, %32, %1
  store i32 5, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %64

64:                                               ; preds = %63, %59, %49, %39, %29, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %65 = load i32, ptr %2, align 4
  ret i32 %65
}

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

declare i32 @string_casencmp(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }

!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, !6, i64 32}
!10 = !{!"gtoken_s", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !6, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 16}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 28}


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

@.str.93 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.94 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.95 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.96 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.97 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 3, 6) i32 @token_special_builtin(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 32
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load i32, ptr %4, align 8, !tbaa !11
  switch i32 %5, label %22 [
    i32 8, label %6
    i32 9, label %12
    i32 10, label %15
    i32 12, label %18
  ]

6:                                                ; preds = %1
  %7 = tail call i32 @string_casencmp(ptr noundef %3, ptr noundef nonnull @.str.93, i64 noundef 8) #2
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %.sink.split, label %9

9:                                                ; preds = %6
  %10 = tail call i32 @string_casencmp(ptr noundef %3, ptr noundef nonnull @.str.94, i64 noundef 8) #2
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %.sink.split, label %22

12:                                               ; preds = %1
  %13 = tail call i32 @string_casencmp(ptr noundef %3, ptr noundef nonnull @.str.95, i64 noundef 9) #2
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %.sink.split, label %22

15:                                               ; preds = %1
  %16 = tail call i32 @string_casencmp(ptr noundef %3, ptr noundef nonnull @.str.96, i64 noundef 10) #2
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %.sink.split, label %22

18:                                               ; preds = %1
  %19 = tail call i32 @string_casencmp(ptr noundef %3, ptr noundef nonnull @.str.97, i64 noundef 12) #2
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %.sink.split, label %22

.sink.split:                                      ; preds = %18, %15, %12, %9, %6
  %.sink = phi i32 [ 1, %6 ], [ 3, %9 ], [ 5, %12 ], [ 2, %15 ], [ 4, %18 ]
  %.0.ph = phi i32 [ 4, %6 ], [ 3, %9 ], [ 3, %12 ], [ 4, %15 ], [ 3, %18 ]
  %21 = getelementptr inbounds i8, ptr %0, i64 28
  store i32 %.sink, ptr %21, align 4, !tbaa !12
  br label %22

22:                                               ; preds = %.sink.split, %1, %9, %12, %15, %18
  %.0 = phi i32 [ 5, %18 ], [ 5, %15 ], [ 5, %12 ], [ 5, %9 ], [ 5, %1 ], [ %.0.ph, %.sink.split ]
  ret i32 %.0
}

declare i32 @string_casencmp(ptr noundef, ptr 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 = { "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, !10, i64 32}
!6 = !{!"gtoken_s", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !10, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 16}
!12 = !{!6, !7, i64 28}


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