; RUN: %clam -O0 --crab-dom=int --crab-track=mem --crab-opt=replace-with-constants --devirt-functions=sea-dsa --crab-print-invariants=false --crab-disable-warnings "%s".c -o %s.bc
; RUN: %llvm_dis < %s.bc | OutputCheck %s --comment=";"

; ModuleID = 'test.bc'
source_filename = "../tests/opt/test-opt-1.c"
target datalayout = "e-m:o-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:128-n8:16:32-S128"
target triple = "i386-apple-macosx10.15.0"

@.str = private unnamed_addr constant [18 x i8] c"Value of a is %d\0A\00", align 1
@fun_ptr = internal unnamed_addr global void (i32)* @fun3, align 4
@str = private unnamed_addr constant [24 x i8] c"You shoud not see this.\00", align 1

; Function Attrs: noinline nounwind ssp uwtable
define internal void @fun1(i32 %arg) #0 {
_2:
  %_ret = call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i32 0, i32 0), i32 %arg) #4
  ret void
}

declare i32 @printf(i8*, ...) local_unnamed_addr #1

; Function Attrs: noinline nounwind ssp uwtable
define internal void @fun2(i32 %arg) #0 {
_2:
  %_3 = add nsw i32 %arg, 1
  %_ret = call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i32 0, i32 0), i32 %_3) #4
  ret void
}

; Function Attrs: noinline nounwind ssp uwtable
define internal void @fun3(i32 %arg) #0 {
_2:
  %puts = call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i32 0, i32 0))
  ret void
}

; Function Attrs: noinline nounwind ssp uwtable
define i32 @main() local_unnamed_addr #0 {
; CHECK: main
_1:
  %_3 = call i32 bitcast (i32 (...)* @nd to i32 ()*)() #4
  %_4 = icmp sgt i32 %_3, -1
  %_call = zext i1 %_4 to i32
  call void @__CRAB_assume(i32 %_call) #4
  %_fun1.fun2 = icmp sgt i32 %_3, 0
  %fun1.fun2 = select i1 %_fun1.fun2, void (i32)* @fun1, void (i32)* @fun2
  store void (i32)* %fun1.fun2, void (i32)** @fun_ptr, align 4
  br i1 %_fun1.fun2, label %if.true.direct_targ, label %if.false.orig_indirect2

if.true.direct_targ:                              ; preds = %_1
  call void @fun1(i32 %_3)
  br label %if.end.icp

if.false.orig_indirect2:                          ; preds = %_1
  %not._fun1.fun2 = xor i1 %_fun1.fun2, true
  call void @llvm.assume(i1 %not._fun1.fun2)
  call void @fun2(i32 %_3)
  br label %if.end.icp

if.end.icp:                                       ; preds = %if.false.orig_indirect2, %if.true.direct_targ
  ret i32 0
; CHECK-NOT: fun3
}

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

declare void @__CRAB_assume(i32) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare i32 @puts(i8* nocapture readonly) #2

; Function Attrs: nounwind willreturn
declare void @llvm.assume(i1) #3

attributes #0 = { noinline nounwind ssp uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #2 = { nofree nounwind }
attributes #3 = { nounwind willreturn }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2}
!llvm.ident = !{!3}

!0 = !{i32 1, !"NumRegisterParameters", i32 0}
!1 = !{i32 1, !"wchar_size", i32 4}
!2 = !{i32 7, !"PIC Level", i32 2}
!3 = !{!"clang version 10.0.0 "}
