; LLVM IR from openssl/openssl :: crypto/ct (ct_sct)

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @SCT_set_log_entry_type(ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @SCT_set_source(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %6 = load i32, ptr %5, align 4, !tbaa !9
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.sct_st, ptr %7, i32 0, i32 13
  store i32 %6, ptr %8, align 4, !tbaa !11
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.sct_st, ptr %9, i32 0, i32 14
  store i32 0, ptr %10, align 8, !tbaa !14
  %11 = load i32, ptr %5, align 4, !tbaa !9
  switch i32 %11, label %18 [
    i32 1, label %12
    i32 3, label %12
    i32 2, label %15
    i32 0, label %18
  ]

12:                                               ; preds = %2, %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call i32 @SCT_set_log_entry_type(ptr noundef %13, i32 noundef 0)
  store i32 %14, ptr %3, align 4
  br label %19

15:                                               ; preds = %2
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = call i32 @SCT_set_log_entry_type(ptr noundef %16, i32 noundef 1)
  store i32 %17, ptr %3, align 4
  br label %19

18:                                               ; preds = %2, %2
  store i32 1, ptr %3, align 4
  br label %19

19:                                               ; preds = %18, %15, %12
  %20 = load i32, ptr %3, align 4
  ret i32 %20
}

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

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


; 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.SCT_set_source = private unnamed_addr constant [3 x i32] [i32 0, i32 1, i32 0], align 4

; Function Attrs: nounwind uwtable
declare dso_local i32 @SCT_set_log_entry_type(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @SCT_set_source(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 92
  store i32 %1, ptr %3, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 96
  store i32 0, ptr %4, align 8, !tbaa !12
  %switch.tableidx = add i32 %1, -1
  %5 = icmp ult i32 %switch.tableidx, 3
  br i1 %5, label %switch.lookup, label %8

switch.lookup:                                    ; preds = %2
  %6 = zext nneg i32 %switch.tableidx to i64
  %switch.gep = getelementptr inbounds [3 x i32], ptr @switch.table.SCT_set_source, i64 0, i64 %6
  %switch.load = load i32, ptr %switch.gep, align 4
  %7 = tail call i32 @SCT_set_log_entry_type(ptr noundef nonnull %0, i32 noundef %switch.load)
  br label %8

8:                                                ; preds = %2, %switch.lookup
  %.0 = phi i32 [ 1, %2 ], [ %7, %switch.lookup ]
  ret i32 %.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" }

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


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass