; LLVM IR from devicehive/esp8266-firmware :: firmware-src/sources/commands (gpio_cmd)

; 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.gpio_command_params = type { i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i32, i32, %union.anon, i16, i32, i8, i8, i8, [264 x i8], i32, i32, i32, i32, i32, i32, i32, i32, float }
%union.anon = type { [16 x i32] }
%struct.COMMAND_RESULT = type { ptr, %union.CommandResultArgument }
%union.CommandResultArgument = type { ptr }

@.str.3 = external hidden unnamed_addr constant [32 x i8], align 1

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

declare ptr @parse_params_pins_set(ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) #1

declare void @dh_command_fail(ptr noundef, ptr noundef) #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 void @dh_handle_gpio_read(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca %struct.gpio_command_params, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  %13 = load i32, ptr %8, align 4, !tbaa !9
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %42

15:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 408, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = call ptr @parse_params_pins_set(ptr noundef %16, i32 noundef %17, ptr noundef %9, i32 noundef 61503, i32 noundef 0, i32 noundef 28, ptr noundef %10)
  store ptr %18, ptr %11, align 8, !tbaa !5
  %19 = load ptr, ptr %11, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %24

21:                                               ; preds = %15
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load ptr, ptr %11, align 8, !tbaa !5
  call void @dh_command_fail(ptr noundef %22, ptr noundef %23)
  store i32 1, ptr %12, align 4
  br label %39

24:                                               ; preds = %15
  %25 = getelementptr inbounds %struct.gpio_command_params, ptr %9, i32 0, i32 2
  %26 = load i16, ptr %25, align 4, !tbaa !11
  %27 = zext i16 %26 to i32
  %28 = getelementptr inbounds %struct.gpio_command_params, ptr %9, i32 0, i32 3
  %29 = load i16, ptr %28, align 2, !tbaa !15
  %30 = zext i16 %29 to i32
  %31 = getelementptr inbounds %struct.gpio_command_params, ptr %9, i32 0, i32 4
  %32 = load i16, ptr %31, align 4, !tbaa !16
  %33 = zext i16 %32 to i32
  %34 = call i32 @dh_gpio_input(i32 noundef %27, i32 noundef %30, i32 noundef %33)
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %38

36:                                               ; preds = %24
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  call void @dh_command_fail(ptr noundef %37, ptr noundef @.str.3)
  store i32 1, ptr %12, align 4
  br label %39

38:                                               ; preds = %24
  store i32 0, ptr %12, align 4
  br label %39

39:                                               ; preds = %38, %36, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 408, ptr %9) #3
  %40 = load i32, ptr %12, align 4
  switch i32 %40, label %53 [
    i32 0, label %41
    i32 1, label %52
  ]

41:                                               ; preds = %39
  br label %42

42:                                               ; preds = %41, %4
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.COMMAND_RESULT, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !17
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.COMMAND_RESULT, ptr %46, i32 0, i32 1
  %48 = call i32 @dh_gpio_read()
  %49 = call i32 @system_get_time()
  %50 = getelementptr inbounds %union.CommandResultArgument, ptr %47, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8
  call void (ptr, i32, i32, ...) %45(ptr %51, i32 noundef 1, i32 noundef 3, i32 noundef 0, i32 noundef %48, i32 noundef %49, i32 noundef 61503)
  br label %52

52:                                               ; preds = %42, %39
  ret void

53:                                               ; preds = %39
  unreachable
}

declare i32 @dh_gpio_input(i32 noundef, i32 noundef, i32 noundef) #1

declare i32 @dh_gpio_read() #1

declare i32 @system_get_time() #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 = !{!"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, !13, i64 4}
!12 = !{!"", !13, i64 0, !13, i64 2, !13, i64 4, !13, i64 6, !13, i64 8, !13, i64 10, !13, i64 12, !13, i64 14, !13, i64 16, !13, i64 18, !13, i64 20, !10, i64 24, !10, i64 28, !7, i64 32, !13, i64 96, !10, i64 100, !7, i64 104, !7, i64 105, !7, i64 106, !7, i64 107, !10, i64 372, !10, i64 376, !10, i64 380, !10, i64 384, !10, i64 388, !10, i64 392, !10, i64 396, !10, i64 400, !14, i64 404}
!13 = !{!"short", !7, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = !{!12, !13, i64 6}
!16 = !{!12, !13, i64 8}
!17 = !{!18, !6, i64 0}
!18 = !{!"", !6, i64 0, !7, i64 8}


; 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.gpio_command_params = type { i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i32, i32, %union.anon, i16, i32, i8, i8, i8, [264 x i8], i32, i32, i32, i32, i32, i32, i32, i32, float }
%union.anon = type { [16 x i32] }

@.str.3 = external hidden unnamed_addr constant [32 x i8], align 1

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

declare ptr @parse_params_pins_set(ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare void @dh_command_fail(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress 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 void @dh_handle_gpio_read(ptr noundef %0, ptr nocapture noundef readnone %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #2 {
  %5 = alloca %struct.gpio_command_params, align 4
  %6 = alloca i32, align 4
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %21, label %7

7:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 408, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  %8 = call ptr @parse_params_pins_set(ptr noundef %2, i32 noundef %3, ptr noundef nonnull %5, i32 noundef 61503, i32 noundef 0, i32 noundef 28, ptr noundef nonnull %6) #3
  %.not11 = icmp eq ptr %8, null
  br i1 %.not11, label %9, label %.thread

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %5, i64 4
  %11 = load i16, ptr %10, align 4, !tbaa !9
  %12 = zext i16 %11 to i32
  %13 = getelementptr inbounds i8, ptr %5, i64 6
  %14 = load i16, ptr %13, align 2, !tbaa !13
  %15 = zext i16 %14 to i32
  %16 = getelementptr inbounds i8, ptr %5, i64 8
  %17 = load i16, ptr %16, align 4, !tbaa !14
  %18 = zext i16 %17 to i32
  %19 = call i32 @dh_gpio_input(i32 noundef %12, i32 noundef %15, i32 noundef %18) #3
  %.not12 = icmp eq i32 %19, 0
  br i1 %.not12, label %20, label %.thread

.thread:                                          ; preds = %9, %7
  %.sink = phi ptr [ %8, %7 ], [ @.str.3, %9 ]
  call void @dh_command_fail(ptr noundef %0, ptr noundef nonnull %.sink) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 408, ptr nonnull %5) #3
  br label %27

20:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 408, ptr nonnull %5) #3
  br label %21

21:                                               ; preds = %20, %4
  %22 = load ptr, ptr %0, align 8, !tbaa !15
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  %24 = call i32 @dh_gpio_read() #3
  %25 = call i32 @system_get_time() #3
  %26 = load ptr, ptr %23, align 8
  call void (ptr, i32, i32, ...) %22(ptr %26, i32 noundef 1, i32 noundef 3, i32 noundef 0, i32 noundef %24, i32 noundef %25, i32 noundef 61503) #3
  br label %27

27:                                               ; preds = %.thread, %21
  ret void
}

declare i32 @dh_gpio_input(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare i32 @dh_gpio_read() local_unnamed_addr #1

declare i32 @system_get_time() local_unnamed_addr #1

attributes #0 = { mustprogress 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 4}
!10 = !{!"", !11, i64 0, !11, i64 2, !11, i64 4, !11, i64 6, !11, i64 8, !11, i64 10, !11, i64 12, !11, i64 14, !11, i64 16, !11, i64 18, !11, i64 20, !6, i64 24, !6, i64 28, !7, i64 32, !11, i64 96, !6, i64 100, !7, i64 104, !7, i64 105, !7, i64 106, !7, i64 107, !6, i64 372, !6, i64 376, !6, i64 380, !6, i64 384, !6, i64 388, !6, i64 392, !6, i64 396, !6, i64 400, !12, i64 404}
!11 = !{!"short", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!10, !11, i64 6}
!14 = !{!10, !11, i64 8}
!15 = !{!16, !17, i64 0}
!16 = !{!"", !17, i64 0, !7, i64 8}
!17 = !{!"any pointer", !7, i64 0}


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