; LLVM IR from control-flow-attestation/c-flat :: samples/soldering (ScreenConfig)

; 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.ScreenConfigStruct = type { %struct.ScreenStruct, ptr, ptr, ptr, ptr, i32, i8, i8, i8, i8, i8, [4 x i8], [4 x i8] }
%struct.ScreenStruct = type { ptr, ptr, ptr, i8, i16, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local ptr @menuScreenConfig(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %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
  store ptr %7, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.ScreenConfigStruct, ptr %8, i32 0, i32 3
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %10, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.ScreenConfigStruct, ptr %11, i32 0, i32 7
  %13 = load i8, ptr %12, align 1, !tbaa !15, !range !16, !noundef !17
  %14 = trunc i8 %13 to i1
  br i1 %14, label %15, label %23

15:                                               ; preds = %1
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ScreenConfigStruct, ptr %16, i32 0, i32 7
  store i8 0, ptr %17, align 1, !tbaa !15
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.ScreenConfigStruct, ptr %19, i32 0, i32 6
  %21 = load i8, ptr %20, align 4, !tbaa !18
  %22 = zext i8 %21 to i16
  call void @initEncoder(ptr noundef %18, i16 noundef signext %22, i16 noundef signext 0, i16 noundef signext 2, i8 noundef zeroext 1, i8 noundef zeroext 0, i32 noundef 1)
  br label %56

23:                                               ; preds = %1
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.ScreenConfigStruct, ptr %24, i32 0, i32 6
  %26 = load i8, ptr %25, align 4, !tbaa !18
  %27 = zext i8 %26 to i32
  switch i32 %27, label %53 [
    i32 0, label %28
    i32 1, label %34
    i32 2, label %41
  ]

28:                                               ; preds = %23
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ScreenConfigStruct, ptr %30, i32 0, i32 9
  %32 = load i8, ptr %31, align 1, !tbaa !19
  %33 = zext i8 %32 to i16
  call void @initEncoder(ptr noundef %29, i16 noundef signext %33, i16 noundef signext 0, i16 noundef signext 15, i8 noundef zeroext 1, i8 noundef zeroext 0, i32 noundef 0)
  br label %53

34:                                               ; preds = %23
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.ScreenConfigStruct, ptr %36, i32 0, i32 10
  %38 = load i8, ptr %37, align 8, !tbaa !20, !range !16, !noundef !17
  %39 = trunc i8 %38 to i1
  %40 = zext i1 %39 to i16
  call void @initEncoder(ptr noundef %35, i16 noundef signext %40, i16 noundef signext 0, i16 noundef signext 1, i8 noundef zeroext 1, i8 noundef zeroext 0, i32 noundef 1)
  br label %53

41:                                               ; preds = %23
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.ScreenConfigStruct, ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds %struct.ScreenStruct, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !21
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %52

47:                                               ; preds = %41
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.ScreenConfigStruct, ptr %48, i32 0, i32 0
  %50 = getelementptr inbounds %struct.ScreenStruct, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !21
  store ptr %51, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %61

52:                                               ; preds = %41
  br label %53

53:                                               ; preds = %52, %34, %28, %23
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.ScreenConfigStruct, ptr %54, i32 0, i32 7
  store i8 1, ptr %55, align 1, !tbaa !15
  br label %56

56:                                               ; preds = %53, %15
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.ScreenConfigStruct, ptr %57, i32 0, i32 0
  %59 = getelementptr inbounds %struct.ScreenStruct, ptr %58, i32 0, i32 3
  store i8 1, ptr %59, align 8, !tbaa !22
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %60, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %61

61:                                               ; preds = %56, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %62 = load ptr, ptr %2, align 8
  ret ptr %62
}

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

declare void @initEncoder(ptr noundef, i16 noundef signext, i16 noundef signext, i16 noundef signext, i8 noundef zeroext, i8 noundef zeroext, i32 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 128}
!10 = !{!"ScreenConfigStruct", !11, i64 0, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !14, i64 144, !7, i64 148, !12, i64 149, !12, i64 150, !7, i64 151, !12, i64 152, !7, i64 153, !7, i64 157}
!11 = !{!"ScreenStruct", !6, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !13, i64 26, !14, i64 28, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!10, !12, i64 149}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!10, !7, i64 148}
!19 = !{!10, !7, i64 151}
!20 = !{!10, !12, i64 152}
!21 = !{!10, !6, i64 0}
!22 = !{!10, !12, i64 24}


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

; Function Attrs: nounwind uwtable
define dso_local ptr @menuScreenConfig(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 128
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 149
  %5 = load i8, ptr %4, align 1, !tbaa !14, !range !15, !noundef !16
  %6 = trunc nuw i8 %5 to i1
  br i1 %6, label %7, label %11

7:                                                ; preds = %1
  store i8 0, ptr %4, align 1, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %0, i64 148
  %9 = load i8, ptr %8, align 4, !tbaa !17
  %10 = zext i8 %9 to i16
  tail call void @initEncoder(ptr noundef %3, i16 noundef signext %10, i16 noundef signext 0, i16 noundef signext 2, i8 noundef zeroext 1, i8 noundef zeroext 0, i32 noundef 1) #2
  br label %25

11:                                               ; preds = %1
  %12 = getelementptr inbounds i8, ptr %0, i64 148
  %13 = load i8, ptr %12, align 4, !tbaa !17
  switch i8 %13, label %24 [
    i8 0, label %14
    i8 1, label %18
    i8 2, label %22
  ]

14:                                               ; preds = %11
  %15 = getelementptr inbounds i8, ptr %0, i64 151
  %16 = load i8, ptr %15, align 1, !tbaa !18
  %17 = zext i8 %16 to i16
  tail call void @initEncoder(ptr noundef %3, i16 noundef signext %17, i16 noundef signext 0, i16 noundef signext 15, i8 noundef zeroext 1, i8 noundef zeroext 0, i32 noundef 0) #2
  br label %24

18:                                               ; preds = %11
  %19 = getelementptr inbounds i8, ptr %0, i64 152
  %20 = load i8, ptr %19, align 8, !tbaa !19, !range !15, !noundef !16
  %21 = zext nneg i8 %20 to i16
  tail call void @initEncoder(ptr noundef %3, i16 noundef signext %21, i16 noundef signext 0, i16 noundef signext 1, i8 noundef zeroext 1, i8 noundef zeroext 0, i32 noundef 1) #2
  br label %24

22:                                               ; preds = %11
  %23 = load ptr, ptr %0, align 8, !tbaa !20
  %.not = icmp eq ptr %23, null
  br i1 %.not, label %24, label %27

24:                                               ; preds = %22, %18, %14, %11
  store i8 1, ptr %4, align 1, !tbaa !14
  br label %25

25:                                               ; preds = %24, %7
  %26 = getelementptr inbounds i8, ptr %0, i64 24
  store i8 1, ptr %26, align 8, !tbaa !21
  br label %27

27:                                               ; preds = %22, %25
  %.0 = phi ptr [ %0, %25 ], [ %23, %22 ]
  ret ptr %.0
}

declare void @initEncoder(ptr noundef, i16 noundef signext, i16 noundef signext, i16 noundef signext, i8 noundef zeroext, i8 noundef zeroext, i32 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, !8, i64 128}
!6 = !{!"ScreenConfigStruct", !7, i64 0, !8, i64 112, !8, i64 120, !8, i64 128, !8, i64 136, !13, i64 144, !9, i64 148, !11, i64 149, !11, i64 150, !9, i64 151, !11, i64 152, !9, i64 153, !9, i64 157}
!7 = !{!"ScreenStruct", !8, i64 0, !8, i64 8, !8, i64 16, !11, i64 24, !12, i64 26, !13, i64 28, !8, i64 32, !8, i64 40, !8, i64 48, !8, i64 56, !8, i64 64, !8, i64 72, !8, i64 80, !8, i64 88, !8, i64 96, !8, i64 104}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"_Bool", !9, i64 0}
!12 = !{!"short", !9, i64 0}
!13 = !{!"int", !9, i64 0}
!14 = !{!6, !11, i64 149}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!6, !9, i64 148}
!18 = !{!6, !9, i64 151}
!19 = !{!6, !11, i64 152}
!20 = !{!6, !8, i64 0}
!21 = !{!6, !11, i64 24}


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