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

; 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.HTTP_ANSWER = type { %struct.HTTP_CONTENT, i8 }
%struct.HTTP_CONTENT = type { ptr, i32 }

@uploadable_api_handle.flash = external hidden constant [13 x i8], align 1
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @uploadable_api_handle(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %13 = load ptr, ptr %9, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.HTTP_ANSWER, ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds %struct.HTTP_CONTENT, ptr %14, i32 0, i32 1
  store i32 0, ptr %15, align 8, !tbaa !9
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = call i32 @ets_strncmp(ptr noundef %16, ptr noundef @uploadable_api_handle.flash, i32 noundef 12)
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %95

19:                                               ; preds = %4
  %20 = call ptr @dhsettings_get_devicehive_key()
  %21 = getelementptr inbounds i8, ptr %20, i64 0
  %22 = load i8, ptr %21, align 1, !tbaa !13
  %23 = icmp ne i8 %22, 0
  br i1 %23, label %24, label %35

24:                                               ; preds = %19
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %28

27:                                               ; preds = %24
  store i32 11, ptr %5, align 4
  br label %96

28:                                               ; preds = %24
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = call ptr @dhsettings_get_devicehive_key()
  %31 = call i32 @ets_strcmp(ptr noundef %29, ptr noundef %30)
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %28
  store i32 11, ptr %5, align 4
  br label %96

34:                                               ; preds = %28
  br label %35

35:                                               ; preds = %34, %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 12
  store ptr %37, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 2, ptr %11, align 4, !tbaa !14
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = call i32 @ets_strcmp(ptr noundef %38, ptr noundef @.str)
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %41, label %49

41:                                               ; preds = %35
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.HTTP_CONTENT, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 8, !tbaa !15
  %45 = icmp eq i32 %44, 0
  br i1 %45, label %46, label %48

46:                                               ; preds = %41
  %47 = call i32 (...) @uploadable_page_begin()
  store i32 %47, ptr %11, align 4, !tbaa !14
  br label %48

48:                                               ; preds = %46, %41
  br label %82

49:                                               ; preds = %35
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = call i32 @ets_strcmp(ptr noundef %50, ptr noundef @.str.1)
  %52 = icmp eq i32 %51, 0
  br i1 %52, label %53, label %61

53:                                               ; preds = %49
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.HTTP_CONTENT, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %55, align 8, !tbaa !15
  %57 = icmp eq i32 %56, 0
  br i1 %57, label %58, label %60

58:                                               ; preds = %53
  %59 = call i32 (...) @uploadable_page_finish()
  store i32 %59, ptr %11, align 4, !tbaa !14
  br label %60

60:                                               ; preds = %58, %53
  br label %81

61:                                               ; preds = %49
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = call i32 @ets_strcmp(ptr noundef %62, ptr noundef @.str.2)
  %64 = icmp eq i32 %63, 0
  br i1 %64, label %65, label %79

65:                                               ; preds = %61
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.HTTP_CONTENT, ptr %66, i32 0, i32 1
  %68 = load i32, ptr %67, align 8, !tbaa !15
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %78

70:                                               ; preds = %65
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.HTTP_CONTENT, ptr %71, i32 0, i32 0
  %73 = load ptr, ptr %72, align 8, !tbaa !16
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.HTTP_CONTENT, ptr %74, i32 0, i32 1
  %76 = load i32, ptr %75, align 8, !tbaa !15
  %77 = call i32 @uploadable_page_put(ptr noundef %73, i32 noundef %76)
  store i32 %77, ptr %11, align 4, !tbaa !14
  br label %78

78:                                               ; preds = %70, %65
  br label %80

79:                                               ; preds = %61
  store i32 7, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %94

80:                                               ; preds = %78
  br label %81

81:                                               ; preds = %80, %60
  br label %82

82:                                               ; preds = %81, %48
  %83 = load i32, ptr %11, align 4, !tbaa !14
  switch i32 %83, label %93 [
    i32 0, label %84
    i32 1, label %85
    i32 2, label %86
    i32 3, label %92
  ]

84:                                               ; preds = %82
  store i32 4, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %94

85:                                               ; preds = %82
  store i32 8, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %94

86:                                               ; preds = %82
  %87 = load ptr, ptr %9, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.HTTP_ANSWER, ptr %87, i32 0, i32 1
  %89 = load i8, ptr %88, align 8
  %90 = and i8 %89, -2
  %91 = or i8 %90, 0
  store i8 %91, ptr %88, align 8
  store i32 4, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %94

92:                                               ; preds = %82
  store i32 12, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %94

93:                                               ; preds = %82
  store i32 4, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %94

94:                                               ; preds = %93, %92, %86, %85, %84, %79
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %96

95:                                               ; preds = %4
  store i32 7, ptr %5, align 4
  br label %96

96:                                               ; preds = %95, %94, %33, %27
  %97 = load i32, ptr %5, align 4
  ret i32 %97
}

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

declare ptr @dhsettings_get_devicehive_key() #1

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

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

declare i32 @uploadable_page_begin(...) #1

declare i32 @uploadable_page_finish(...) #1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !12, i64 8}
!10 = !{!"", !11, i64 0, !12, i64 16, !12, i64 16, !12, i64 16}
!11 = !{!"", !6, i64 0, !12, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!11, !12, i64 8}
!16 = !{!11, !6, i64 0}


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

@uploadable_api_handle.flash = external hidden constant [13 x i8], align 1
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 4, 13) i32 @uploadable_api_handle(ptr noundef %0, ptr noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %3, i64 8
  store i32 0, ptr %5, align 8, !tbaa !5
  %6 = tail call i32 @ets_strncmp(ptr noundef %0, ptr noundef nonnull @uploadable_api_handle.flash, i32 noundef 12) #2
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %50

8:                                                ; preds = %4
  %9 = tail call ptr @dhsettings_get_devicehive_key() #2
  %10 = load i8, ptr %9, align 1, !tbaa !12
  %.not = icmp eq i8 %10, 0
  br i1 %.not, label %16, label %11

11:                                               ; preds = %8
  %12 = icmp eq ptr %1, null
  br i1 %12, label %50, label %13

13:                                               ; preds = %11
  %14 = tail call ptr @dhsettings_get_devicehive_key() #2
  %15 = tail call i32 @ets_strcmp(ptr noundef nonnull %1, ptr noundef %14) #2
  %.not18 = icmp eq i32 %15, 0
  br i1 %.not18, label %16, label %50

16:                                               ; preds = %13, %8
  %17 = getelementptr inbounds i8, ptr %0, i64 12
  %18 = tail call i32 @ets_strcmp(ptr noundef nonnull %17, ptr noundef nonnull @.str) #2
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %26

20:                                               ; preds = %16
  %21 = getelementptr inbounds i8, ptr %2, i64 8
  %22 = load i32, ptr %21, align 8, !tbaa !13
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %.thread

24:                                               ; preds = %20
  %25 = tail call i32 (...) @uploadable_page_begin() #2
  br label %44

26:                                               ; preds = %16
  %27 = tail call i32 @ets_strcmp(ptr noundef nonnull %17, ptr noundef nonnull @.str.1) #2
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %35

29:                                               ; preds = %26
  %30 = getelementptr inbounds i8, ptr %2, i64 8
  %31 = load i32, ptr %30, align 8, !tbaa !13
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %.thread

33:                                               ; preds = %29
  %34 = tail call i32 (...) @uploadable_page_finish() #2
  br label %44

35:                                               ; preds = %26
  %36 = tail call i32 @ets_strcmp(ptr noundef nonnull %17, ptr noundef nonnull @.str.2) #2
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %50

38:                                               ; preds = %35
  %39 = getelementptr inbounds i8, ptr %2, i64 8
  %40 = load i32, ptr %39, align 8, !tbaa !13
  %.not19 = icmp eq i32 %40, 0
  br i1 %.not19, label %.thread, label %41

41:                                               ; preds = %38
  %42 = load ptr, ptr %2, align 8, !tbaa !14
  %43 = tail call i32 @uploadable_page_put(ptr noundef %42, i32 noundef %40) #2
  br label %44

44:                                               ; preds = %33, %41, %24
  %.0 = phi i32 [ %25, %24 ], [ %34, %33 ], [ %43, %41 ]
  switch i32 %.0, label %50 [
    i32 3, label %49
    i32 1, label %45
    i32 2, label %.thread
  ]

45:                                               ; preds = %44
  br label %50

.thread:                                          ; preds = %38, %29, %20, %44
  %46 = getelementptr inbounds i8, ptr %3, i64 16
  %47 = load i8, ptr %46, align 8
  %48 = and i8 %47, -2
  store i8 %48, ptr %46, align 8
  br label %50

49:                                               ; preds = %44
  br label %50

50:                                               ; preds = %4, %45, %.thread, %49, %35, %44, %13, %11
  %.1 = phi i32 [ 11, %11 ], [ 11, %13 ], [ 12, %49 ], [ 4, %.thread ], [ 8, %45 ], [ 7, %35 ], [ 4, %44 ], [ 7, %4 ]
  ret i32 %.1
}

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

declare ptr @dhsettings_get_devicehive_key() local_unnamed_addr #1

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

declare i32 @uploadable_page_begin(...) local_unnamed_addr #1

declare i32 @uploadable_page_finish(...) local_unnamed_addr #1

declare i32 @uploadable_page_put(ptr noundef, 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, !11, i64 8}
!6 = !{!"", !7, i64 0, !11, i64 16, !11, i64 16, !11, i64 16}
!7 = !{!"", !8, i64 0, !11, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!9, !9, i64 0}
!13 = !{!7, !11, i64 8}
!14 = !{!7, !8, i64 0}


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