#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 */
typedef int /*<<< orphan*/ mpz_t;

/* Variables and functions */
int /*<<< orphan*/ gmp_printf(char *, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ isprime(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_add(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_add_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
scalar_t__ mpz_cmp(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init_set_str(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ mpz_init_set_ui(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mul(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mul_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int strtol(char *, int /*<<< orphan*/ *, int);
int main(int ac, char *av[]) {
  int a, b, c;
  mpz_t n, n2, max_n, tmp;
  if (ac < 5) {
    printf("usage : primegen a b c max_n\n");
    return (1);
  }
  a = strtol(av[1], NULL, 10);
  b = strtol(av[2], NULL, 10);
  c = strtol(av[3], NULL, 10);
  mpz_init_set_str(max_n, av[4], 10);
  mpz_init_set_ui(n, 0);
  mpz_init(n2);
  mpz_init(tmp);
  while (mpz_cmp(n, max_n) <= 0) {
    mpz_mul(n2, n, n);
    mpz_mul_ui(n2, n2, a);
    mpz_mul_ui(tmp, n, b);
    mpz_add(n2, n2, tmp);
    mpz_add_ui(n2, n2, c);
    if (isprime(n2))
      gmp_printf("%Zd %Zd OK\n", n, n2);
    else
      gmp_printf("%Zd %Zd NG\n", n, n2);
    mpz_add_ui(n, n, 1);
  }
  mpz_clear(n);
  mpz_clear(n2);
  mpz_clear(max_n);
  mpz_clear(tmp);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    1208 <main+0x38>
lea    0xe09(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1354 <main+0x184>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rsi
mov    $0xa,%edx
call   1050 <mpz_init_set_str@plt>
mov    -0x20(%rbp),%edi
xor    %esi,%esi
call   10b0 <mpz_init_set_ui@plt>
mov    -0x24(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x2c(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x20(%rbp),%edi
mov    -0x28(%rbp),%esi
call   10c0 <mpz_cmp@plt>
cmp    $0x0,%rax
jg     132d <main+0x15d>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x20(%rbp),%edx
call   10a0 <mpz_mul@plt>
mov    -0x24(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x14(%rbp),%edx
call   10f0 <mpz_mul_ui@plt>
mov    -0x2c(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x18(%rbp),%edx
call   10f0 <mpz_mul_ui@plt>
mov    -0x24(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   1090 <mpz_add@plt>
mov    -0x24(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1030 <mpz_add_ui@plt>
mov    -0x24(%rbp),%edi
call   1070 <isprime@plt>
cmp    $0x0,%rax
je     1306 <main+0x136>
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xd22(%rip),%rdi
call   10e0 <gmp_printf@plt>
jmp    1318 <main+0x148>
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xd17(%rip),%rdi
call   10e0 <gmp_printf@plt>
mov    -0x20(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    $0x1,%edx
call   1030 <mpz_add_ui@plt>
jmp    1282 <main+0xb2>
mov    -0x20(%rbp),%edi
call   10d0 <mpz_clear@plt>
mov    -0x24(%rbp),%edi
call   10d0 <mpz_clear@plt>
mov    -0x28(%rbp),%edi
call   10d0 <mpz_clear@plt>
mov    -0x2c(%rbp),%edi
call   10d0 <mpz_clear@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x4,%edi
jg     11f7 <main+0x27>
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r14d
jmp    12cc <main+0xfc>
mov    %rsi,%r12
mov    0x8(%rsi),%rdi
xor    %r14d,%r14d
xor    %esi,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %eax,%r15d
mov    0x10(%r12),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %eax,%ebx
mov    0x18(%r12),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %eax,%ebp
mov    0x20(%r12),%rsi
mov    $0xa,%edx
call   1050 <mpz_init_set_str@plt>
xor    %esi,%esi
call   10b0 <mpz_init_set_ui@plt>
call   1060 <mpz_init@plt>
call   1060 <mpz_init@plt>
call   10c0 <mpz_cmp@plt>
test   %rax,%rax
jg     12b8 <main+0xe8>
lea    0xda5(%rip),%r12
lea    0xd92(%rip),%r13
xchg   %ax,%ax
call   10a0 <mpz_mul@plt>
mov    %r15d,%edx
call   10f0 <mpz_mul_ui@plt>
mov    %ebx,%edx
call   10f0 <mpz_mul_ui@plt>
call   1090 <mpz_add@plt>
mov    %ebp,%edx
call   1040 <mpz_add_ui@plt>
call   1070 <isprime@plt>
test   %rax,%rax
mov    %r13,%rdi
cmove  %r12,%rdi
call   10e0 <gmp_printf@plt>
mov    $0x1,%edx
call   1040 <mpz_add_ui@plt>
call   10c0 <mpz_cmp@plt>
test   %rax,%rax
jle    1270 <main+0xa0>
call   10d0 <mpz_clear@plt>
call   10d0 <mpz_clear@plt>
call   10d0 <mpz_clear@plt>
call   10d0 <mpz_clear@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"usage : primegen a b c max_n\0A\00"
@.str.1 = [12 x i8] c"%Zd %Zd OK\0A\00"
@.str.2 = [12 x i8] c"%Zd %Zd NG\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 5
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %91
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @strtol(i8* %20, i32* null, i32 10)
store i32 %21, i32* %6
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @strtol(i8* %24, i32* null, i32 10)
store i32 %25, i32* %7
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 3
%28 = load i8*, i8** %27
%29 = call i32 @strtol(i8* %28, i32* null, i32 10)
store i32 %29, i32* %8
%30 = load i32, i32* %11
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 4
%33 = load i8*, i8** %32
%34 = call i32 @mpz_init_set_str(i32 %30, i8* %33, i32 10)
%35 = load i32, i32* %9
%36 = call i32 @mpz_init_set_ui(i32 %35, i32 0)
%37 = load i32, i32* %10
%38 = call i32 @mpz_init(i32 %37)
%39 = load i32, i32* %12
%40 = call i32 @mpz_init(i32 %39)
br label %41
41: ; preds = %78, %17
%42 = load i32, i32* %9
%43 = load i32, i32* %11
%44 = call i64 @mpz_cmp(i32 %42, i32 %43)
%45 = icmp sle i64 %44, 0
br i1 %45, label %46, label %82
46: ; preds = %41
%47 = load i32, i32* %10
%48 = load i32, i32* %9
%49 = load i32, i32* %9
%50 = call i32 @mpz_mul(i32 %47, i32 %48, i32 %49)
%51 = load i32, i32* %10
%52 = load i32, i32* %10
%53 = load i32, i32* %6
%54 = call i32 @mpz_mul_ui(i32 %51, i32 %52, i32 %53)
%55 = load i32, i32* %12
%56 = load i32, i32* %9
%57 = load i32, i32* %7
%58 = call i32 @mpz_mul_ui(i32 %55, i32 %56, i32 %57)
%59 = load i32, i32* %10
%60 = load i32, i32* %10
%61 = load i32, i32* %12
%62 = call i32 @mpz_add(i32 %59, i32 %60, i32 %61)
%63 = load i32, i32* %10
%64 = load i32, i32* %10
%65 = load i32, i32* %8
%66 = call i32 @mpz_add_ui(i32 %63, i32 %64, i32 %65)
%67 = load i32, i32* %10
%68 = call i64 @isprime(i32 %67)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %74
70: ; preds = %46
%71 = load i32, i32* %9
%72 = load i32, i32* %10
%73 = call i32 @gmp_printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %71, i32 %72)
br label %78
74: ; preds = %46
%75 = load i32, i32* %9
%76 = load i32, i32* %10
%77 = call i32 @gmp_printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %75, i32 %76)
br label %78
78: ; preds = %74, %70
%79 = load i32, i32* %9
%80 = load i32, i32* %9
%81 = call i32 @mpz_add_ui(i32 %79, i32 %80, i32 1)
br label %41
82: ; preds = %41
%83 = load i32, i32* %9
%84 = call i32 @mpz_clear(i32 %83)
%85 = load i32, i32* %10
%86 = call i32 @mpz_clear(i32 %85)
%87 = load i32, i32* %11
%88 = call i32 @mpz_clear(i32 %87)
%89 = load i32, i32* %12
%90 = call i32 @mpz_clear(i32 %89)
store i32 0, i32* %3
br label %91
91: ; preds = %82, %15
%92 = load i32, i32* %3
ret i32 %92
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"%Zd %Zd OK\0A\00"
@.str.2 = [12 x i8] c"%Zd %Zd NG\0A\00"
@str = [29 x i8] c"usage : primegen a b c max_n\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 5
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %42
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @strtol(i8* nocapture %8, i32* null, i32 10)
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @strtol(i8* nocapture %11, i32* null, i32 10)
%13 = getelementptr inbounds i8*, i8** %1, i64 3
%14 = load i8*, i8** %13
%15 = tail call i32 @strtol(i8* nocapture %14, i32* null, i32 10)
%16 = getelementptr inbounds i8*, i8** %1, i64 4
%17 = load i8*, i8** %16
%18 = tail call i32 @mpz_init_set_str(i32 undef, i8* %17, i32 10)
%19 = tail call i32 @mpz_init_set_ui(i32 undef, i32 0)
%20 = tail call i32 @mpz_init(i32 undef)
%21 = tail call i32 @mpz_init(i32 undef)
%22 = tail call i64 @mpz_cmp(i32 undef, i32 undef)
%23 = icmp slt i64 %22, 1
br i1 %23, label %24, label %37
24: ; preds = %6, %24
%25 = tail call i32 @mpz_mul(i32 undef, i32 undef, i32 undef)
%26 = tail call i32 @mpz_mul_ui(i32 undef, i32 undef, i32 %9)
%27 = tail call i32 @mpz_mul_ui(i32 undef, i32 undef, i32 %12)
%28 = tail call i32 @mpz_add(i32 undef, i32 undef, i32 undef)
%29 = tail call i32 @mpz_add_ui(i32 undef, i32 undef, i32 %15)
%30 = tail call i64 @isprime(i32 undef)
%31 = icmp eq i64 %30, 0
%32 = select i1 %31, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0)
%33 = tail call i32 @gmp_printf(i8* %32, i32 undef, i32 undef)
%34 = tail call i32 @mpz_add_ui(i32 undef, i32 undef, i32 1)
%35 = tail call i64 @mpz_cmp(i32 undef, i32 undef)
%36 = icmp slt i64 %35, 1
br i1 %36, label %24, label %37
37: ; preds = %24, %6
%38 = tail call i32 @mpz_clear(i32 undef)
%39 = tail call i32 @mpz_clear(i32 undef)
%40 = tail call i32 @mpz_clear(i32 undef)
%41 = tail call i32 @mpz_clear(i32 undef)
br label %42
42: ; preds = %37, %4
%43 = phi i32 [ 1, %4 ], [ 0, %37 ]
ret i32 %43
}