; LLVM IR from unitreerobotics/kinect_teleoperate :: src/extern/glfw/src/tests (gamma)

; 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.nk_text_edit = type { %struct.nk_clipboard, %struct.nk_str, ptr, %struct.nk_vec2, i32, i32, i32, i8, i8, i8, i8, i8, i8, i8, float, %struct.nk_text_undo_state }
%struct.nk_clipboard = type { %union.nk_handle, ptr, ptr }
%union.nk_handle = type { ptr }
%struct.nk_str = type { %struct.nk_buffer, i32 }
%struct.nk_buffer = type { [2 x %struct.nk_buffer_marker], %struct.nk_allocator, i32, %struct.nk_memory, float, i64, i64, i64, i64 }
%struct.nk_buffer_marker = type { i32, i64 }
%struct.nk_allocator = type { %union.nk_handle, ptr, ptr }
%struct.nk_memory = type { ptr, i64 }
%struct.nk_vec2 = type { float, float }
%struct.nk_text_undo_state = type { [99 x %struct.nk_text_undo_record], [999 x i32], i16, i16, i16, i16 }
%struct.nk_text_undo_record = type { i32, i16, i16, i16 }

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

; 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
declare dso_local i32 @nk_utf_len(ptr noundef, i32 noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @nk_textedit_delete_selection(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @nk_textedit_clamp(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @nk_textedit_paste(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %11, ptr %9, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.nk_text_edit, ptr %12, i32 0, i32 7
  %14 = load i8, ptr %13, align 4, !tbaa !11
  %15 = zext i8 %14 to i32
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %59

18:                                               ; preds = %3
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  call void @nk_textedit_clamp(ptr noundef %19)
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  call void @nk_textedit_delete_selection(ptr noundef %20)
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = call i32 @nk_utf_len(ptr noundef %21, i32 noundef %22)
  store i32 %23, ptr %8, align 4, !tbaa !9
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.nk_text_edit, ptr %24, i32 0, i32 1
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.nk_text_edit, ptr %26, i32 0, i32 4
  %28 = load i32, ptr %27, align 8, !tbaa !23
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = call i32 @nk_str_insert_text_char(ptr noundef %25, i32 noundef %28, ptr noundef %29, i32 noundef %30)
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %46

33:                                               ; preds = %18
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.nk_text_edit, ptr %35, i32 0, i32 4
  %37 = load i32, ptr %36, align 8, !tbaa !23
  %38 = load i32, ptr %8, align 4, !tbaa !9
  call void @nk_textedit_makeundo_insert(ptr noundef %34, i32 noundef %37, i32 noundef %38)
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.nk_text_edit, ptr %40, i32 0, i32 4
  %42 = load i32, ptr %41, align 8, !tbaa !23
  %43 = add nsw i32 %42, %39
  store i32 %43, ptr %41, align 8, !tbaa !23
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.nk_text_edit, ptr %44, i32 0, i32 10
  store i8 0, ptr %45, align 1, !tbaa !24
  store i32 1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %59

46:                                               ; preds = %18
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.nk_text_edit, ptr %47, i32 0, i32 15
  %49 = getelementptr inbounds %struct.nk_text_undo_state, ptr %48, i32 0, i32 2
  %50 = load i16, ptr %49, align 8, !tbaa !25
  %51 = icmp ne i16 %50, 0
  br i1 %51, label %52, label %58

52:                                               ; preds = %46
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.nk_text_edit, ptr %53, i32 0, i32 15
  %55 = getelementptr inbounds %struct.nk_text_undo_state, ptr %54, i32 0, i32 2
  %56 = load i16, ptr %55, align 8, !tbaa !25
  %57 = add i16 %56, -1
  store i16 %57, ptr %55, align 8, !tbaa !25
  br label %58

58:                                               ; preds = %52, %46
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %59

59:                                               ; preds = %58, %33, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %60 = load i32, ptr %4, align 4
  ret i32 %60
}

; Function Attrs: nounwind uwtable
declare hidden void @nk_textedit_makeundo_insert(ptr noundef, i32 noundef, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !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, !7, i64 180}
!12 = !{!"nk_text_edit", !13, i64 0, !14, i64 24, !6, i64 152, !20, i64 160, !10, i64 168, !10, i64 172, !10, i64 176, !7, i64 180, !7, i64 181, !7, i64 182, !7, i64 183, !7, i64 184, !7, i64 185, !7, i64 186, !19, i64 188, !21, i64 192}
!13 = !{!"nk_clipboard", !7, i64 0, !6, i64 8, !6, i64 16}
!14 = !{!"nk_str", !15, i64 0, !10, i64 120}
!15 = !{!"nk_buffer", !7, i64 0, !16, i64 32, !10, i64 56, !17, i64 64, !19, i64 80, !18, i64 88, !18, i64 96, !18, i64 104, !18, i64 112}
!16 = !{!"nk_allocator", !7, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!"nk_memory", !6, i64 0, !18, i64 8}
!18 = !{!"long", !7, i64 0}
!19 = !{!"float", !7, i64 0}
!20 = !{!"nk_vec2", !19, i64 0, !19, i64 4}
!21 = !{!"nk_text_undo_state", !7, i64 0, !7, i64 1188, !22, i64 5184, !22, i64 5186, !22, i64 5188, !22, i64 5190}
!22 = !{!"short", !7, i64 0}
!23 = !{!12, !10, i64 168}
!24 = !{!12, !7, i64 183}
!25 = !{!12, !22, i64 5376}


; 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
declare dso_local i32 @nk_utf_len(ptr noundef, i32 noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @nk_textedit_paste(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 180
  %5 = load i8, ptr %4, align 4, !tbaa !5
  %6 = icmp eq i8 %5, 0
  br i1 %6, label %23, label %7

7:                                                ; preds = %3
  tail call void @nk_textedit_clamp(ptr noundef nonnull %0)
  tail call void @nk_textedit_delete_selection(ptr noundef nonnull %0)
  %8 = tail call i32 @nk_utf_len(ptr noundef %1, i32 noundef %2)
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = getelementptr inbounds i8, ptr %0, i64 168
  %11 = load i32, ptr %10, align 8, !tbaa !21
  %12 = tail call i32 @nk_str_insert_text_char(ptr noundef nonnull %9, i32 noundef %11, ptr noundef %1, i32 noundef %2)
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %18, label %13

13:                                               ; preds = %7
  %14 = load i32, ptr %10, align 8, !tbaa !21
  tail call void @nk_textedit_makeundo_insert(ptr noundef nonnull %0, i32 noundef %14, i32 noundef %8)
  %15 = load i32, ptr %10, align 8, !tbaa !21
  %16 = add nsw i32 %15, %2
  store i32 %16, ptr %10, align 8, !tbaa !21
  %17 = getelementptr inbounds i8, ptr %0, i64 183
  store i8 0, ptr %17, align 1, !tbaa !22
  br label %23

18:                                               ; preds = %7
  %19 = getelementptr inbounds i8, ptr %0, i64 5376
  %20 = load i16, ptr %19, align 8, !tbaa !23
  %.not19 = icmp eq i16 %20, 0
  br i1 %.not19, label %23, label %21

21:                                               ; preds = %18
  %22 = add i16 %20, -1
  store i16 %22, ptr %19, align 8, !tbaa !23
  br label %23

23:                                               ; preds = %18, %21, %3, %13
  %.0 = phi i32 [ 1, %13 ], [ 0, %3 ], [ 0, %21 ], [ 0, %18 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @nk_textedit_makeundo_insert(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #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, !8, i64 180}
!6 = !{!"nk_text_edit", !7, i64 0, !11, i64 24, !10, i64 152, !18, i64 160, !14, i64 168, !14, i64 172, !14, i64 176, !8, i64 180, !8, i64 181, !8, i64 182, !8, i64 183, !8, i64 184, !8, i64 185, !8, i64 186, !17, i64 188, !19, i64 192}
!7 = !{!"nk_clipboard", !8, i64 0, !10, i64 8, !10, i64 16}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"nk_str", !12, i64 0, !14, i64 120}
!12 = !{!"nk_buffer", !8, i64 0, !13, i64 32, !14, i64 56, !15, i64 64, !17, i64 80, !16, i64 88, !16, i64 96, !16, i64 104, !16, i64 112}
!13 = !{!"nk_allocator", !8, i64 0, !10, i64 8, !10, i64 16}
!14 = !{!"int", !8, i64 0}
!15 = !{!"nk_memory", !10, i64 0, !16, i64 8}
!16 = !{!"long", !8, i64 0}
!17 = !{!"float", !8, i64 0}
!18 = !{!"nk_vec2", !17, i64 0, !17, i64 4}
!19 = !{!"nk_text_undo_state", !8, i64 0, !8, i64 1188, !20, i64 5184, !20, i64 5186, !20, i64 5188, !20, i64 5190}
!20 = !{!"short", !8, i64 0}
!21 = !{!6, !14, i64 168}
!22 = !{!6, !8, i64 183}
!23 = !{!6, !20, i64 5376}


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