#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int sqrt(int);
int nextprime(int n) {
  int i;
  while (n > 1) {
    n++;
    for (i = 2; i <= sqrt(n); i++)
      if (n % i == 0)
        goto ss;
    return n;
  ss:;
  }
  return 0;
}


x86 assembly (clang, -O0):
<nextprime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1188 <nextprime+0x78>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <sqrt@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jg     1178 <nextprime+0x68>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    1165 <nextprime+0x55>
jmp    1183 <nextprime+0x73>
jmp    116a <nextprime+0x5a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1135 <nextprime+0x25>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118f <nextprime+0x7f>
jmp    111b <nextprime+0xb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nextprime>:
push   %rbp
push   %rbx
push   %rax
xor    %ebx,%ebx
cmp    $0x2,%edi
jl     116f <nextprime+0x5f>
mov    %edi,%ebp
add    $0x1,%ebp
mov    %ebp,%edi
call   1030 <sqrt@plt>
mov    %ebp,%ebx
cmp    $0x2,%eax
jl     116f <nextprime+0x5f>
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%ebp
mov    %ebx,%eax
cltd
idiv   %ebp
test   %edx,%edx
je     1160 <nextprime+0x50>
mov    %ebx,%edi
call   1030 <sqrt@plt>
cmp    %eax,%ebp
jl     1140 <nextprime+0x30>
jmp    116f <nextprime+0x5f>
nopl   0x0(%rax)
add    $0x1,%ebx
mov    %ebx,%edi
call   1030 <sqrt@plt>
cmp    $0x2,%eax
jge    112d <nextprime+0x1d>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @nextprime(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
br label %5
5: ; preds = %28, %1
%6 = load i32, i32* %3
%7 = icmp sgt i32 %6, 1
br i1 %7, label %8, label %29
8: ; preds = %5
%9 = load i32, i32* %3
%10 = add nsw i32 %9, 1
store i32 %10, i32* %3
store i32 2, i32* %4
br label %11
11: ; preds = %23, %8
%12 = load i32, i32* %4
%13 = load i32, i32* %3
%14 = call i32 @sqrt(i32 %13)
%15 = icmp sle i32 %12, %14
br i1 %15, label %16, label %26
16: ; preds = %11
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = srem i32 %17, %18
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
br label %28
22: ; preds = %16
br label %23
23: ; preds = %22
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %11
26: ; preds = %11
%27 = load i32, i32* %3
store i32 %27, i32* %2
br label %30
28: ; preds = %21
br label %5
29: ; preds = %5
store i32 0, i32* %2
br label %30
30: ; preds = %29, %26
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
define i32 @nextprime(i32 %0) {
%2 = icmp sgt i32 %0, 1
br i1 %2, label %3, label %21
3: ; preds = %1
%4 = add nuw nsw i32 %0, 1
%5 = tail call i32 @sqrt(i32 %4)
%6 = icmp slt i32 %5, 2
br i1 %6, label %21, label %11
7: ; preds = %17
%8 = add nuw nsw i32 %12, 1
%9 = tail call i32 @sqrt(i32 %8)
%10 = icmp slt i32 %9, 2
br i1 %10, label %21, label %11
11: ; preds = %3, %7
%12 = phi i32 [ %8, %7 ], [ %4, %3 ]
br label %17
13: ; preds = %17
%14 = add nuw nsw i32 %18, 1
%15 = tail call i32 @sqrt(i32 %12)
%16 = icmp slt i32 %18, %15
br i1 %16, label %17, label %21
17: ; preds = %11, %13
%18 = phi i32 [ %14, %13 ], [ 2, %11 ]
%19 = srem i32 %12, %18
%20 = icmp eq i32 %19, 0
br i1 %20, label %7, label %13
21: ; preds = %7, %13, %3, %1
%22 = phi i32 [ 0, %1 ], [ %4, %3 ], [ %12, %13 ], [ %8, %7 ]
ret i32 %22
}