#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 */
long long sqrt(long long);
int isadvprime(long long int x, int *primes) {
  long long int i, root = sqrt(x);
  for (i = 0; (i < 3401) && primes[i] <= root; i++)
    if (x % primes[i] == 0)
      return 0;
  return 1;
}


x86 assembly (clang, -O0):
<isadvprime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <sqrt@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0xd49,-0x20(%rbp)
mov    %al,-0x29(%rbp)
jge    115e <isadvprime+0x4e>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq (%rax,%rcx,4),%rax
cmp    -0x28(%rbp),%rax
setle  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    116e <isadvprime+0x5e>
jmp    11af <isadvprime+0x9f>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    1199 <isadvprime+0x89>
movl   $0x0,-0x4(%rbp)
jmp    11b6 <isadvprime+0xa6>
jmp    119e <isadvprime+0x8e>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1135 <isadvprime+0x25>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isadvprime>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <sqrt@plt>
mov    %rax,%r8
mov    $0x1,%edi
nopw   0x0(%rax,%rax,1)
movslq -0x4(%r14,%rdi,4),%rcx
mov    $0x1,%esi
cmp    %rcx,%r8
jl     11bb <isadvprime+0xab>
mov    %rbx,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     1160 <isadvprime+0x50>
mov    %rbx,%rax
cqto
idiv   %rcx
test   %rdx,%rdx
jne    116b <isadvprime+0x5b>
jmp    11b9 <isadvprime+0xa9>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
test   %rdx,%rdx
je     11b9 <isadvprime+0xa9>
cmp    $0xd49,%rdi
je     11bb <isadvprime+0xab>
movslq (%r14,%rdi,4),%rcx
cmp    %rcx,%r8
jl     11bb <isadvprime+0xab>
mov    %rbx,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     11a0 <isadvprime+0x90>
mov    %rbx,%rax
cqto
idiv   %rcx
jmp    11a6 <isadvprime+0x96>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
mov    $0x0,%esi
test   %rdx,%rdx
je     11bb <isadvprime+0xab>
add    $0x2,%rdi
jmp    1130 <isadvprime+0x20>
xor    %esi,%esi
mov    %esi,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @isadvprime(i64 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
store i64 %0, i64* %4
store i32* %1, i32** %5
%8 = load i64, i64* %4
%9 = call i64 @sqrt(i64 %8)
store i64 %9, i64* %7
store i64 0, i64* %6
br label %10
10: ; preds = %34, %2
%11 = load i64, i64* %6
%12 = icmp slt i64 %11, 3401
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = load i32*, i32** %5
%15 = load i64, i64* %6
%16 = getelementptr inbounds i32, i32* %14, i64 %15
%17 = load i32, i32* %16
%18 = sext i32 %17 to i64
%19 = load i64, i64* %7
%20 = icmp sle i64 %18, %19
br label %21
21: ; preds = %13, %10
%22 = phi i1 [ false, %10 ], [ %20, %13 ]
br i1 %22, label %23, label %37
23: ; preds = %21
%24 = load i64, i64* %4
%25 = load i32*, i32** %5
%26 = load i64, i64* %6
%27 = getelementptr inbounds i32, i32* %25, i64 %26
%28 = load i32, i32* %27
%29 = sext i32 %28 to i64
%30 = srem i64 %24, %29
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %23
store i32 0, i32* %3
br label %38
33: ; preds = %23
br label %34
34: ; preds = %33
%35 = load i64, i64* %6
%36 = add nsw i64 %35, 1
store i64 %36, i64* %6
br label %10
37: ; preds = %21
store i32 1, i32* %3
br label %38
38: ; preds = %37, %32
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
define i32 @isadvprime(i64 %0, i32* nocapture %1) {
%3 = tail call i64 @sqrt(i64 %0)
br label %17
4: ; preds = %23
%5 = or i64 %18, 1
%6 = icmp eq i64 %5, 3401
br i1 %6, label %26, label %7
7: ; preds = %4
%8 = getelementptr inbounds i32, i32* %1, i64 %5
%9 = load i32, i32* %8
%10 = sext i32 %9 to i64
%11 = icmp slt i64 %3, %10
br i1 %11, label %26, label %12
12: ; preds = %7
%13 = srem i64 %0, %10
%14 = icmp eq i64 %13, 0
br i1 %14, label %26, label %15
15: ; preds = %12
%16 = add nuw nsw i64 %18, 2
br label %17
17: ; preds = %15, %2
%18 = phi i64 [ 0, %2 ], [ %16, %15 ]
%19 = getelementptr inbounds i32, i32* %1, i64 %18
%20 = load i32, i32* %19
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %3, %21
br i1 %22, label %26, label %23
23: ; preds = %17
%24 = srem i64 %0, %21
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %4
26: ; preds = %12, %7, %17, %4, %23
%27 = phi i32 [ 0, %23 ], [ 1, %4 ], [ 1, %17 ], [ 1, %7 ], [ 0, %12 ]
ret i32 %27
}