; LLVM IR from moonglow/pcan_cantact :: Src (pcan_protocol)

; 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.anon = type { i8, i8, i8, i16, i16, %struct.anon.0, [6 x i8], i8, i8, i32 }
%struct.anon.0 = type { i8, i8, i8, i8, i8, i8, i8, i8, i8, i32 }
%struct.PCAN_RECORD_BUFFER_EX = type { [896 x i8], i16, i16 }
%struct.PCAN_USB_PARAM = type { i8, i8, [14 x i8] }

@pcan_device = external hidden global %struct.anon, align 4
@pcan_records = external hidden global %struct.PCAN_RECORD_BUFFER_EX, align 2
@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [75 x i8], align 1
@__PRETTY_FUNCTION__.pcan_protocol_process_command = external hidden unnamed_addr constant [56 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @pcan_sja1000_write(i8 noundef zeroext, i8 noundef zeroext) #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @pcan_sja1000_read(i8 noundef zeroext) #0

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

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

declare zeroext i16 @pcan_timestamp_ticks() #2

; Function Attrs: nounwind uwtable
declare dso_local void @pcan_timesync_event(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @pcan_protocol_process_command(ptr noundef %0, i16 noundef zeroext %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i16, align 2
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i16 %1, ptr %4, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %7, ptr %5, align 8, !tbaa !5
  %8 = load i16, ptr %4, align 2, !tbaa !9
  %9 = zext i16 %8 to i32
  %10 = icmp slt i32 %9, 2
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  store i32 1, ptr %6, align 4
  br label %193

12:                                               ; preds = %2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %13, i32 0, i32 1
  %15 = load i8, ptr %14, align 1, !tbaa !11
  %16 = zext i8 %15 to i32
  switch i32 %16, label %191 [
    i32 0, label %17
    i32 3, label %23
    i32 2, label %35
    i32 1, label %109
  ]

17:                                               ; preds = %12
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %18, i32 0, i32 0
  %20 = load i8, ptr %19, align 1, !tbaa !13
  %21 = zext i8 %20 to i32
  switch i32 %21, label %22 [
    i32 200, label %22
  ]

22:                                               ; preds = %17, %17
  br label %192

23:                                               ; preds = %12
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %24, i32 0, i32 0
  %26 = load i8, ptr %25, align 1, !tbaa !13
  %27 = zext i8 %26 to i32
  switch i32 %27, label %34 [
    i32 3, label %28
  ]

28:                                               ; preds = %23
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %29, i32 0, i32 2
  %31 = getelementptr inbounds [14 x i8], ptr %30, i64 0, i64 0
  %32 = load i8, ptr %31, align 1, !tbaa !14
  store i8 %32, ptr getelementptr inbounds (%struct.anon.0, ptr getelementptr inbounds (%struct.anon, ptr @pcan_device, i32 0, i32 5), i32 0, i32 6), align 2, !tbaa !15
  %33 = load i8, ptr getelementptr inbounds (%struct.anon.0, ptr getelementptr inbounds (%struct.anon, ptr @pcan_device, i32 0, i32 5), i32 0, i32 6), align 2, !tbaa !15
  call void @pcan_can_set_silent(i8 noundef zeroext %33)
  br label %34

34:                                               ; preds = %28, %23
  br label %192

35:                                               ; preds = %12
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %36, i32 0, i32 0
  %38 = load i8, ptr %37, align 1, !tbaa !13
  %39 = zext i8 %38 to i32
  switch i32 %39, label %108 [
    i32 1, label %40
    i32 3, label %52
    i32 4, label %79
    i32 5, label %108
    i32 9, label %84
    i32 10, label %93
    i32 11, label %98
    i32 12, label %103
  ]

40:                                               ; preds = %35
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %41, i32 0, i32 2
  %43 = getelementptr inbounds [14 x i8], ptr %42, i64 0, i64 1
  %44 = load i8, ptr %43, align 1, !tbaa !14
  store i8 %44, ptr getelementptr inbounds (%struct.anon.0, ptr getelementptr inbounds (%struct.anon, ptr @pcan_device, i32 0, i32 5), i32 0, i32 4), align 4, !tbaa !19
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %45, i32 0, i32 2
  %47 = getelementptr inbounds [14 x i8], ptr %46, i64 0, i64 0
  %48 = load i8, ptr %47, align 1, !tbaa !14
  store i8 %48, ptr getelementptr inbounds (%struct.anon.0, ptr getelementptr inbounds (%struct.anon, ptr @pcan_device, i32 0, i32 5), i32 0, i32 5), align 1, !tbaa !20
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %49, i32 0, i32 2
  %51 = getelementptr inbounds [14 x i8], ptr %50, i64 0, i64 0
  call void @pcan_set_bitrate(ptr noundef %51)
  br label %108

52:                                               ; preds = %35
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %53, i32 0, i32 2
  %55 = getelementptr inbounds [14 x i8], ptr %54, i64 0, i64 0
  %56 = load i8, ptr %55, align 1, !tbaa !14
  store i8 %56, ptr @pcan_device, align 4, !tbaa !21
  %57 = load i8, ptr @pcan_device, align 4, !tbaa !21
  %58 = zext i8 %57 to i32
  %59 = icmp ne i32 %58, 0
  %60 = zext i1 %59 to i64
  %61 = select i1 %59, i32 4, i32 2
  call void @pcan_led_set_mode(i32 noundef 2, i32 noundef %61, i16 noundef zeroext 0)
  %62 = load i8, ptr @pcan_device, align 4, !tbaa !21
  %63 = zext i8 %62 to i16
  call void @pcan_can_set_bus_active(i16 noundef zeroext %63)
  %64 = load i8, ptr @pcan_device, align 4, !tbaa !21
  %65 = icmp ne i8 %64, 0
  br i1 %65, label %66, label %68

66:                                               ; preds = %52
  %67 = call zeroext i16 @pcan_timestamp_ticks()
  store i16 %67, ptr getelementptr inbounds (%struct.anon, ptr @pcan_device, i32 0, i32 3), align 4, !tbaa !22
  call void @pcan_timesync_event(ptr noundef @pcan_records)
  br label %68

68:                                               ; preds = %66, %52
  %69 = load i8, ptr @pcan_device, align 4, !tbaa !21
  %70 = zext i8 %69 to i32
  %71 = icmp ne i32 %70, 0
  %72 = zext i1 %71 to i64
  %73 = select i1 %71, i32 2, i32 1
  call void @pcan_led_set_mode(i32 noundef 0, i32 noundef %73, i16 noundef zeroext 0)
  %74 = load i8, ptr @pcan_device, align 4, !tbaa !21
  %75 = zext i8 %74 to i32
  %76 = icmp ne i32 %75, 0
  %77 = zext i1 %76 to i64
  %78 = select i1 %76, i32 2, i32 1
  call void @pcan_led_set_mode(i32 noundef 1, i32 noundef %78, i16 noundef zeroext 0)
  br label %108

79:                                               ; preds = %35
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %80, i32 0, i32 2
  %82 = getelementptr inbounds [14 x i8], ptr %81, i64 0, i64 0
  %83 = load i8, ptr %82, align 1, !tbaa !14
  store i8 %83, ptr getelementptr inbounds (%struct.anon, ptr @pcan_device, i32 0, i32 8), align 1, !tbaa !23
  br label %108

84:                                               ; preds = %35
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %85, i32 0, i32 2
  %87 = getelementptr inbounds [14 x i8], ptr %86, i64 0, i64 0
  %88 = load i8, ptr %87, align 1, !tbaa !14
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %89, i32 0, i32 2
  %91 = getelementptr inbounds [14 x i8], ptr %90, i64 0, i64 1
  %92 = load i8, ptr %91, align 1, !tbaa !14
  call void @pcan_sja1000_write(i8 noundef zeroext %88, i8 noundef zeroext %92)
  br label %108

93:                                               ; preds = %35
  %94 = load ptr, ptr %5, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %94, i32 0, i32 2
  %96 = getelementptr inbounds [14 x i8], ptr %95, i64 0, i64 0
  %97 = load i8, ptr %96, align 1, !tbaa !14
  store i8 %97, ptr getelementptr inbounds (%struct.anon, ptr @pcan_device, i32 0, i32 1), align 1, !tbaa !24
  br label %108

98:                                               ; preds = %35
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %99, i32 0, i32 2
  %101 = getelementptr inbounds [14 x i8], ptr %100, i64 0, i64 0
  %102 = load i8, ptr %101, align 1, !tbaa !14
  store i8 %102, ptr getelementptr inbounds (%struct.anon.0, ptr getelementptr inbounds (%struct.anon, ptr @pcan_device, i32 0, i32 5), i32 0, i32 8), align 4, !tbaa !25
  br label %108

103:                                              ; preds = %35
  %104 = load ptr, ptr %5, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %104, i32 0, i32 2
  %106 = getelementptr inbounds [14 x i8], ptr %105, i64 0, i64 0
  %107 = load i8, ptr %106, align 1, !tbaa !14
  store i8 %107, ptr getelementptr inbounds (%struct.anon, ptr @pcan_device, i32 0, i32 2), align 2, !tbaa !26
  br label %108

108:                                              ; preds = %103, %98, %93, %84, %79, %68, %40, %35, %35
  br label %192

109:                                              ; preds = %12
  %110 = load ptr, ptr %5, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %110, i32 0, i32 0
  %112 = load i8, ptr %111, align 1, !tbaa !13
  %113 = zext i8 %112 to i32
  switch i32 %113, label %190 [
    i32 1, label %114
    i32 2, label %125
    i32 4, label %134
    i32 6, label %141
    i32 9, label %172
    i32 12, label %183
  ]

114:                                              ; preds = %109
  %115 = load i8, ptr getelementptr inbounds (%struct.anon.0, ptr getelementptr inbounds (%struct.anon, ptr @pcan_device, i32 0, i32 5), i32 0, i32 4), align 4, !tbaa !19
  %116 = load ptr, ptr %5, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %116, i32 0, i32 2
  %118 = getelementptr inbounds [14 x i8], ptr %117, i64 0, i64 1
  store i8 %115, ptr %118, align 1, !tbaa !14
  %119 = load i8, ptr getelementptr inbounds (%struct.anon.0, ptr getelementptr inbounds (%struct.anon, ptr @pcan_device, i32 0, i32 5), i32 0, i32 5), align 1, !tbaa !20
  %120 = load ptr, ptr %5, align 8, !tbaa !5
  %121 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %120, i32 0, i32 2
  %122 = getelementptr inbounds [14 x i8], ptr %121, i64 0, i64 0
  store i8 %119, ptr %122, align 1, !tbaa !14
  %123 = load ptr, ptr %5, align 8, !tbaa !5
  %124 = call zeroext i16 @pcan_usb_send_command_buffer(ptr noundef %123, i16 noundef zeroext 16)
  br label %190

125:                                              ; preds = %109
  %126 = load i32, ptr getelementptr inbounds (%struct.anon.0, ptr getelementptr inbounds (%struct.anon, ptr @pcan_device, i32 0, i32 5), i32 0, i32 9), align 4, !tbaa !27
  %127 = udiv i32 %126, 1000000
  %128 = trunc i32 %127 to i8
  %129 = load ptr, ptr %5, align 8, !tbaa !5
  %130 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %129, i32 0, i32 2
  %131 = getelementptr inbounds [14 x i8], ptr %130, i64 0, i64 0
  store i8 %128, ptr %131, align 1, !tbaa !14
  %132 = load ptr, ptr %5, align 8, !tbaa !5
  %133 = call zeroext i16 @pcan_usb_send_command_buffer(ptr noundef %132, i16 noundef zeroext 16)
  br label %190

134:                                              ; preds = %109
  %135 = load i8, ptr getelementptr inbounds (%struct.anon, ptr @pcan_device, i32 0, i32 8), align 1, !tbaa !23
  %136 = load ptr, ptr %5, align 8, !tbaa !5
  %137 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %136, i32 0, i32 2
  %138 = getelementptr inbounds [14 x i8], ptr %137, i64 0, i64 0
  store i8 %135, ptr %138, align 1, !tbaa !14
  %139 = load ptr, ptr %5, align 8, !tbaa !5
  %140 = call zeroext i16 @pcan_usb_send_command_buffer(ptr noundef %139, i16 noundef zeroext 16)
  br label %190

141:                                              ; preds = %109
  %142 = load i32, ptr getelementptr inbounds (%struct.anon, ptr @pcan_device, i32 0, i32 9), align 4, !tbaa !28
  %143 = lshr i32 %142, 24
  %144 = and i32 %143, 255
  %145 = trunc i32 %144 to i8
  %146 = load ptr, ptr %5, align 8, !tbaa !5
  %147 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %146, i32 0, i32 2
  %148 = getelementptr inbounds [14 x i8], ptr %147, i64 0, i64 0
  store i8 %145, ptr %148, align 1, !tbaa !14
  %149 = load i32, ptr getelementptr inbounds (%struct.anon, ptr @pcan_device, i32 0, i32 9), align 4, !tbaa !28
  %150 = lshr i32 %149, 16
  %151 = and i32 %150, 255
  %152 = trunc i32 %151 to i8
  %153 = load ptr, ptr %5, align 8, !tbaa !5
  %154 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %153, i32 0, i32 2
  %155 = getelementptr inbounds [14 x i8], ptr %154, i64 0, i64 1
  store i8 %152, ptr %155, align 1, !tbaa !14
  %156 = load i32, ptr getelementptr inbounds (%struct.anon, ptr @pcan_device, i32 0, i32 9), align 4, !tbaa !28
  %157 = lshr i32 %156, 8
  %158 = and i32 %157, 255
  %159 = trunc i32 %158 to i8
  %160 = load ptr, ptr %5, align 8, !tbaa !5
  %161 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %160, i32 0, i32 2
  %162 = getelementptr inbounds [14 x i8], ptr %161, i64 0, i64 2
  store i8 %159, ptr %162, align 1, !tbaa !14
  %163 = load i32, ptr getelementptr inbounds (%struct.anon, ptr @pcan_device, i32 0, i32 9), align 4, !tbaa !28
  %164 = lshr i32 %163, 0
  %165 = and i32 %164, 255
  %166 = trunc i32 %165 to i8
  %167 = load ptr, ptr %5, align 8, !tbaa !5
  %168 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %167, i32 0, i32 2
  %169 = getelementptr inbounds [14 x i8], ptr %168, i64 0, i64 3
  store i8 %166, ptr %169, align 1, !tbaa !14
  %170 = load ptr, ptr %5, align 8, !tbaa !5
  %171 = call zeroext i16 @pcan_usb_send_command_buffer(ptr noundef %170, i16 noundef zeroext 16)
  br label %190

172:                                              ; preds = %109
  %173 = load ptr, ptr %5, align 8, !tbaa !5
  %174 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %173, i32 0, i32 2
  %175 = getelementptr inbounds [14 x i8], ptr %174, i64 0, i64 0
  %176 = load i8, ptr %175, align 1, !tbaa !14
  %177 = call zeroext i8 @pcan_sja1000_read(i8 noundef zeroext %176)
  %178 = load ptr, ptr %5, align 8, !tbaa !5
  %179 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %178, i32 0, i32 2
  %180 = getelementptr inbounds [14 x i8], ptr %179, i64 0, i64 1
  store i8 %177, ptr %180, align 1, !tbaa !14
  %181 = load ptr, ptr %5, align 8, !tbaa !5
  %182 = call zeroext i16 @pcan_usb_send_command_buffer(ptr noundef %181, i16 noundef zeroext 16)
  br label %190

183:                                              ; preds = %109
  %184 = load i8, ptr getelementptr inbounds (%struct.anon, ptr @pcan_device, i32 0, i32 2), align 2, !tbaa !26
  %185 = load ptr, ptr %5, align 8, !tbaa !5
  %186 = getelementptr inbounds %struct.PCAN_USB_PARAM, ptr %185, i32 0, i32 2
  %187 = getelementptr inbounds [14 x i8], ptr %186, i64 0, i64 0
  store i8 %184, ptr %187, align 1, !tbaa !14
  %188 = load ptr, ptr %5, align 8, !tbaa !5
  %189 = call zeroext i16 @pcan_usb_send_command_buffer(ptr noundef %188, i16 noundef zeroext 16)
  br label %190

190:                                              ; preds = %183, %172, %141, %134, %125, %114, %109
  br label %192

191:                                              ; preds = %12
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 747, ptr noundef @__PRETTY_FUNCTION__.pcan_protocol_process_command) #5
  unreachable

192:                                              ; preds = %190, %108, %34, %22
  store i32 0, ptr %6, align 4
  br label %193

193:                                              ; preds = %192, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  %194 = load i32, ptr %6, align 4
  switch i32 %194, label %196 [
    i32 0, label %195
    i32 1, label %195
  ]

195:                                              ; preds = %193, %193
  ret void

196:                                              ; preds = %193
  unreachable
}

declare void @pcan_can_set_silent(i8 noundef zeroext) #2

; Function Attrs: nounwind uwtable
declare hidden void @pcan_set_bitrate(ptr noundef) #0

declare void @pcan_led_set_mode(i32 noundef, i32 noundef, i16 noundef zeroext) #2

declare void @pcan_can_set_bus_active(i16 noundef zeroext) #2

declare zeroext i16 @pcan_usb_send_command_buffer(ptr noundef, i16 noundef zeroext) #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

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 = { noreturn nounwind "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 #4 = { nounwind }
attributes #5 = { noreturn 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 = !{!"short", !7, i64 0}
!11 = !{!12, !7, i64 1}
!12 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!13 = !{!12, !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !7, i64 14}
!16 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !10, i64 4, !10, i64 6, !17, i64 8, !7, i64 24, !7, i64 30, !7, i64 31, !18, i64 32}
!17 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !18, i64 12}
!18 = !{!"int", !7, i64 0}
!19 = !{!16, !7, i64 12}
!20 = !{!16, !7, i64 13}
!21 = !{!16, !7, i64 0}
!22 = !{!16, !10, i64 4}
!23 = !{!16, !7, i64 31}
!24 = !{!16, !7, i64 1}
!25 = !{!16, !7, i64 16}
!26 = !{!16, !7, i64 2}
!27 = !{!16, !18, i64 20}
!28 = !{!16, !18, i64 32}


; 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.anon = type { i8, i8, i8, i16, i16, %struct.anon.0, [6 x i8], i8, i8, i32 }
%struct.anon.0 = type { i8, i8, i8, i8, i8, i8, i8, i8, i8, i32 }
%struct.PCAN_RECORD_BUFFER_EX = type { [896 x i8], i16, i16 }

@pcan_device = external hidden local_unnamed_addr global %struct.anon, align 4
@pcan_records = external hidden global %struct.PCAN_RECORD_BUFFER_EX, align 2
@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [75 x i8], align 1
@__PRETTY_FUNCTION__.pcan_protocol_process_command = external hidden unnamed_addr constant [56 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @pcan_sja1000_write(i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @pcan_sja1000_read(i8 noundef zeroext) local_unnamed_addr #0

declare zeroext i16 @pcan_timestamp_ticks() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @pcan_timesync_event(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @pcan_protocol_process_command(ptr noundef %0, i16 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = icmp ult i16 %1, 2
  br i1 %3, label %96, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 1
  %6 = load i8, ptr %5, align 1, !tbaa !5
  switch i8 %6, label %95 [
    i8 0, label %96
    i8 3, label %7
    i8 2, label %12
    i8 1, label %50
  ]

7:                                                ; preds = %4
  %8 = load i8, ptr %0, align 1, !tbaa !9
  %cond = icmp eq i8 %8, 3
  br i1 %cond, label %9, label %96

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %0, i64 2
  %11 = load i8, ptr %10, align 1, !tbaa !10
  store i8 %11, ptr getelementptr inbounds (i8, ptr @pcan_device, i64 14), align 2, !tbaa !11
  tail call void @pcan_can_set_silent(i8 noundef zeroext %11) #3
  br label %96

12:                                               ; preds = %4
  %13 = load i8, ptr %0, align 1, !tbaa !9
  switch i8 %13, label %96 [
    i8 1, label %14
    i8 3, label %19
    i8 4, label %33
    i8 12, label %47
    i8 9, label %36
    i8 10, label %41
    i8 11, label %44
  ]

14:                                               ; preds = %12
  %15 = getelementptr inbounds i8, ptr %0, i64 2
  %16 = getelementptr inbounds i8, ptr %0, i64 3
  %17 = load i8, ptr %16, align 1, !tbaa !10
  store i8 %17, ptr getelementptr inbounds (i8, ptr @pcan_device, i64 12), align 4, !tbaa !16
  %18 = load i8, ptr %15, align 1, !tbaa !10
  store i8 %18, ptr getelementptr inbounds (i8, ptr @pcan_device, i64 13), align 1, !tbaa !17
  tail call void @pcan_set_bitrate(ptr noundef nonnull %15)
  br label %96

19:                                               ; preds = %12
  %20 = getelementptr inbounds i8, ptr %0, i64 2
  %21 = load i8, ptr %20, align 1, !tbaa !10
  store i8 %21, ptr @pcan_device, align 4, !tbaa !18
  %.not = icmp eq i8 %21, 0
  %22 = select i1 %.not, i32 2, i32 4
  tail call void @pcan_led_set_mode(i32 noundef 2, i32 noundef %22, i16 noundef zeroext 0) #3
  %23 = load i8, ptr @pcan_device, align 4, !tbaa !18
  %24 = zext i8 %23 to i16
  tail call void @pcan_can_set_bus_active(i16 noundef zeroext %24) #3
  %25 = load i8, ptr @pcan_device, align 4, !tbaa !18
  %.not33 = icmp eq i8 %25, 0
  br i1 %.not33, label %30, label %26

26:                                               ; preds = %19
  %27 = tail call zeroext i16 @pcan_timestamp_ticks() #3
  store i16 %27, ptr getelementptr inbounds (i8, ptr @pcan_device, i64 4), align 4, !tbaa !19
  tail call void @pcan_timesync_event(ptr noundef nonnull @pcan_records)
  %.pre = load i8, ptr @pcan_device, align 4, !tbaa !18
  %28 = icmp eq i8 %.pre, 0
  %29 = select i1 %28, i32 1, i32 2
  br label %30

30:                                               ; preds = %26, %19
  %.not34 = phi i32 [ %29, %26 ], [ 1, %19 ]
  tail call void @pcan_led_set_mode(i32 noundef 0, i32 noundef %.not34, i16 noundef zeroext 0) #3
  %31 = load i8, ptr @pcan_device, align 4, !tbaa !18
  %.not35 = icmp eq i8 %31, 0
  %32 = select i1 %.not35, i32 1, i32 2
  tail call void @pcan_led_set_mode(i32 noundef 1, i32 noundef %32, i16 noundef zeroext 0) #3
  br label %96

33:                                               ; preds = %12
  %34 = getelementptr inbounds i8, ptr %0, i64 2
  %35 = load i8, ptr %34, align 1, !tbaa !10
  store i8 %35, ptr getelementptr inbounds (i8, ptr @pcan_device, i64 31), align 1, !tbaa !20
  br label %96

36:                                               ; preds = %12
  %37 = getelementptr inbounds i8, ptr %0, i64 2
  %38 = load i8, ptr %37, align 1, !tbaa !10
  %39 = getelementptr inbounds i8, ptr %0, i64 3
  %40 = load i8, ptr %39, align 1, !tbaa !10
  tail call void @pcan_sja1000_write(i8 noundef zeroext %38, i8 noundef zeroext %40)
  br label %96

41:                                               ; preds = %12
  %42 = getelementptr inbounds i8, ptr %0, i64 2
  %43 = load i8, ptr %42, align 1, !tbaa !10
  store i8 %43, ptr getelementptr inbounds (i8, ptr @pcan_device, i64 1), align 1, !tbaa !21
  br label %96

44:                                               ; preds = %12
  %45 = getelementptr inbounds i8, ptr %0, i64 2
  %46 = load i8, ptr %45, align 1, !tbaa !10
  store i8 %46, ptr getelementptr inbounds (i8, ptr @pcan_device, i64 16), align 4, !tbaa !22
  br label %96

47:                                               ; preds = %12
  %48 = getelementptr inbounds i8, ptr %0, i64 2
  %49 = load i8, ptr %48, align 1, !tbaa !10
  store i8 %49, ptr getelementptr inbounds (i8, ptr @pcan_device, i64 2), align 2, !tbaa !23
  br label %96

50:                                               ; preds = %4
  %51 = load i8, ptr %0, align 1, !tbaa !9
  switch i8 %51, label %96 [
    i8 1, label %52
    i8 2, label %58
    i8 4, label %64
    i8 6, label %68
    i8 9, label %85
    i8 12, label %91
  ]

52:                                               ; preds = %50
  %53 = load i8, ptr getelementptr inbounds (i8, ptr @pcan_device, i64 12), align 4, !tbaa !16
  %54 = getelementptr inbounds i8, ptr %0, i64 2
  %55 = getelementptr inbounds i8, ptr %0, i64 3
  store i8 %53, ptr %55, align 1, !tbaa !10
  %56 = load i8, ptr getelementptr inbounds (i8, ptr @pcan_device, i64 13), align 1, !tbaa !17
  store i8 %56, ptr %54, align 1, !tbaa !10
  %57 = tail call zeroext i16 @pcan_usb_send_command_buffer(ptr noundef nonnull %0, i16 noundef zeroext 16) #3
  br label %96

58:                                               ; preds = %50
  %59 = load i32, ptr getelementptr inbounds (i8, ptr @pcan_device, i64 20), align 4, !tbaa !24
  %60 = udiv i32 %59, 1000000
  %61 = trunc i32 %60 to i8
  %62 = getelementptr inbounds i8, ptr %0, i64 2
  store i8 %61, ptr %62, align 1, !tbaa !10
  %63 = tail call zeroext i16 @pcan_usb_send_command_buffer(ptr noundef nonnull %0, i16 noundef zeroext 16) #3
  br label %96

64:                                               ; preds = %50
  %65 = load i8, ptr getelementptr inbounds (i8, ptr @pcan_device, i64 31), align 1, !tbaa !20
  %66 = getelementptr inbounds i8, ptr %0, i64 2
  store i8 %65, ptr %66, align 1, !tbaa !10
  %67 = tail call zeroext i16 @pcan_usb_send_command_buffer(ptr noundef nonnull %0, i16 noundef zeroext 16) #3
  br label %96

68:                                               ; preds = %50
  %69 = load i32, ptr getelementptr inbounds (i8, ptr @pcan_device, i64 32), align 4, !tbaa !25
  %70 = lshr i32 %69, 24
  %71 = trunc nuw i32 %70 to i8
  %72 = getelementptr inbounds i8, ptr %0, i64 2
  store i8 %71, ptr %72, align 1, !tbaa !10
  %73 = load i32, ptr getelementptr inbounds (i8, ptr @pcan_device, i64 32), align 4, !tbaa !25
  %74 = lshr i32 %73, 16
  %75 = trunc i32 %74 to i8
  %76 = getelementptr inbounds i8, ptr %0, i64 3
  store i8 %75, ptr %76, align 1, !tbaa !10
  %77 = load i32, ptr getelementptr inbounds (i8, ptr @pcan_device, i64 32), align 4, !tbaa !25
  %78 = lshr i32 %77, 8
  %79 = trunc i32 %78 to i8
  %80 = getelementptr inbounds i8, ptr %0, i64 4
  store i8 %79, ptr %80, align 1, !tbaa !10
  %81 = load i32, ptr getelementptr inbounds (i8, ptr @pcan_device, i64 32), align 4, !tbaa !25
  %82 = trunc i32 %81 to i8
  %83 = getelementptr inbounds i8, ptr %0, i64 5
  store i8 %82, ptr %83, align 1, !tbaa !10
  %84 = tail call zeroext i16 @pcan_usb_send_command_buffer(ptr noundef nonnull %0, i16 noundef zeroext 16) #3
  br label %96

85:                                               ; preds = %50
  %86 = getelementptr inbounds i8, ptr %0, i64 2
  %87 = load i8, ptr %86, align 1, !tbaa !10
  %88 = tail call zeroext i8 @pcan_sja1000_read(i8 noundef zeroext %87)
  %89 = getelementptr inbounds i8, ptr %0, i64 3
  store i8 %88, ptr %89, align 1, !tbaa !10
  %90 = tail call zeroext i16 @pcan_usb_send_command_buffer(ptr noundef nonnull %0, i16 noundef zeroext 16) #3
  br label %96

91:                                               ; preds = %50
  %92 = load i8, ptr getelementptr inbounds (i8, ptr @pcan_device, i64 2), align 2, !tbaa !23
  %93 = getelementptr inbounds i8, ptr %0, i64 2
  store i8 %92, ptr %93, align 1, !tbaa !10
  %94 = tail call zeroext i16 @pcan_usb_send_command_buffer(ptr noundef nonnull %0, i16 noundef zeroext 16) #3
  br label %96

95:                                               ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 747, ptr noundef nonnull @__PRETTY_FUNCTION__.pcan_protocol_process_command) #4
  unreachable

96:                                               ; preds = %4, %7, %9, %47, %44, %41, %36, %33, %30, %14, %12, %91, %85, %68, %64, %58, %52, %50, %2
  ret void
}

declare void @pcan_can_set_silent(i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @pcan_set_bitrate(ptr noundef) local_unnamed_addr #0

declare void @pcan_led_set_mode(i32 noundef, i32 noundef, i16 noundef zeroext) local_unnamed_addr #1

declare void @pcan_can_set_bus_active(i16 noundef zeroext) local_unnamed_addr #1

declare zeroext i16 @pcan_usb_send_command_buffer(ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

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 = { noreturn nounwind "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 }
attributes #4 = { noreturn 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, !7, i64 1}
!6 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!6, !7, i64 0}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !7, i64 14}
!12 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !13, i64 4, !13, i64 6, !14, i64 8, !7, i64 24, !7, i64 30, !7, i64 31, !15, i64 32}
!13 = !{!"short", !7, i64 0}
!14 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !15, i64 12}
!15 = !{!"int", !7, i64 0}
!16 = !{!12, !7, i64 12}
!17 = !{!12, !7, i64 13}
!18 = !{!12, !7, i64 0}
!19 = !{!12, !13, i64 4}
!20 = !{!12, !7, i64 31}
!21 = !{!12, !7, i64 1}
!22 = !{!12, !7, i64 16}
!23 = !{!12, !7, i64 2}
!24 = !{!12, !15, i64 20}
!25 = !{!12, !15, i64 32}


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