int basic_prime_successor(n)
int n;
{
  if (n < 2)
    return (2);
  else {
    n++;
    if (!((n) % 2 == 1))
      n++;
    while (!basic_prime_test(n))
      n += 2;
    return (n);
  }
}


x86 assembly (clang, -O0):
<basic_prime_successor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1131 <basic_prime_successor+0x21>
movl   $0x2,-0x4(%rbp)
jmp    118f <basic_prime_successor+0x7f>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
je     1157 <basic_prime_successor+0x47>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    115c <basic_prime_successor+0x4c>
mov    -0x8(%rbp),%edi
mov    $0x0,%al
call   1030 <basic_prime_test@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    117b <basic_prime_successor+0x6b>
jmp    1189 <basic_prime_successor+0x79>
mov    -0x8(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x8(%rbp)
jmp    115c <basic_prime_successor+0x4c>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basic_prime_successor>:
mov    $0x2,%eax
cmp    $0x2,%edi
jl     1146 <basic_prime_successor+0x36>
push   %rbx
mov    %edi,%ebx
lea    0x1(%rbx),%eax
add    $0x2,%ebx
test   $0x1,%al
cmovne %eax,%ebx
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <basic_prime_test@plt>
add    $0x2,%ebx
test   %eax,%eax
je     1130 <basic_prime_successor+0x20>
add    $0xfffffffe,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @basic_prime_successor(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp slt i32 %4, 2
br i1 %5, label %6, label %7
6: ; preds = %1
store i32 2, i32* %2
br label %27
7: ; preds = %1
%8 = load i32, i32* %3
%9 = add nsw i32 %8, 1
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = srem i32 %10, 2
%12 = icmp eq i32 %11, 1
br i1 %12, label %16, label %13
13: ; preds = %7
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
store i32 %15, i32* %3
br label %16
16: ; preds = %13, %7
br label %17
17: ; preds = %22, %16
%18 = load i32, i32* %3
%19 = call i32 (i32, ...) bitcast (i32 (...)* @basic_prime_test to i32 (i32, ...)*)(i32 %18)
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 2
store i32 %24, i32* %3
br label %17
25: ; preds = %17
%26 = load i32, i32* %3
store i32 %26, i32* %2
br label %27
27: ; preds = %25, %6
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
define i32 @basic_prime_successor(i32 %0) {
%2 = icmp slt i32 %0, 2
br i1 %2, label %14, label %3
3: ; preds = %1
%4 = add nuw nsw i32 %0, 1
%5 = and i32 %4, 1
%6 = icmp eq i32 %5, 0
%7 = add nuw nsw i32 %0, 2
%8 = select i1 %6, i32 %7, i32 %4
br label %9
9: ; preds = %9, %3
%10 = phi i32 [ %8, %3 ], [ %13, %9 ]
%11 = tail call i32 (i32, ...) bitcast (i32 (...)* @basic_prime_test to i32 (i32, ...)*)(i32 %10)
%12 = icmp eq i32 %11, 0
%13 = add nsw i32 %10, 2
br i1 %12, label %9, label %14
14: ; preds = %9, %1
%15 = phi i32 [ 2, %1 ], [ %10, %9 ]
ret i32 %15
}