#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 */
scalar_t__ EOF;
scalar_t__ isPrime(int);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ scanf(char *, int *, int *, int *);
int main() {
  int a, b, n;
  int res, i;
  while (scanf("%d %d %d", &a, &b, &n) != EOF) {
    if (a == 0 && b == 0 && n == 0)
      break;
    res = a;
    i = 0;
    while (1) {
      if (isPrime(res)) {
        i++;
        if (i >= n)
          break;
      }
      res += b;
    }
    printf("%d\n", res);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
call   1050 <scanf@plt>
mov    0x2e8a(%rip),%rcx
cmp    (%rcx),%rax
je     11ea <main+0xba>
cmpl   $0x0,-0x8(%rbp)
jne    118a <main+0x5a>
cmpl   $0x0,-0xc(%rbp)
jne    118a <main+0x5a>
cmpl   $0x0,-0x10(%rbp)
jne    118a <main+0x5a>
jmp    11ea <main+0xba>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <isPrime@plt>
cmp    $0x0,%rax
je     11c8 <main+0x98>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jl     11c3 <main+0x93>
jmp    11d6 <main+0xa6>
jmp    11c8 <main+0x98>
mov    -0xc(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1197 <main+0x67>
mov    -0x14(%rbp),%esi
lea    0xe29(%rip),%rdi
call   1030 <printf@plt>
jmp    113f <main+0xf>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xebb(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
call   1050 <scanf@plt>
mov    0x2e88(%rip),%r14
cmp    (%r14),%rax
je     11e3 <main+0xb3>
lea    0x14(%rsp),%r12
lea    0x10(%rsp),%r13
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x14(%rsp),%ebp
test   %ebp,%ebp
jne    1196 <main+0x66>
cmpl   $0x0,0x10(%rsp)
jne    1196 <main+0x66>
cmpl   $0x0,0xc(%rsp)
je     11e3 <main+0xb3>
xor    %r15d,%r15d
jmp    11a4 <main+0x74>
nopl   0x0(%rax,%rax,1)
add    0x10(%rsp),%ebp
mov    %ebp,%edi
call   1040 <isPrime@plt>
test   %rax,%rax
je     11a0 <main+0x70>
add    $0x1,%r15d
cmp    0xc(%rsp),%r15d
jl     11a0 <main+0x70>
lea    0xe47(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
lea    0xe30(%rip),%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
call   1050 <scanf@plt>
cmp    (%r14),%rax
jne    1180 <main+0x50>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%d %d %d\00"
@EOF = global i64 0
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
br label %7
7: ; preds = %39, %0
%8 = call i64 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3, i32* %4)
%9 = load i64, i64* @EOF
%10 = icmp ne i64 %8, %9
br i1 %10, label %11, label %42
11: ; preds = %7
%12 = load i32, i32* %2
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
br label %42
21: ; preds = %17, %14, %11
%22 = load i32, i32* %2
store i32 %22, i32* %5
store i32 0, i32* %6
br label %23
23: ; preds = %21, %35
%24 = load i32, i32* %5
%25 = call i64 @isPrime(i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %35
27: ; preds = %23
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = load i32, i32* %4
%32 = icmp sge i32 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %27
br label %39
34: ; preds = %27
br label %35
35: ; preds = %34, %23
%36 = load i32, i32* %3
%37 = load i32, i32* %5
%38 = add nsw i32 %37, %36
store i32 %38, i32* %5
br label %23
39: ; preds = %33
%40 = load i32, i32* %5
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %40)
br label %7
42: ; preds = %20, %7
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"%d %d %d\00"
@EOF = global i64 0
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = call i64 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2, i32* %3)
%8 = load i64, i64* @EOF
%9 = icmp eq i64 %7, %8
br i1 %9, label %37, label %10
10: ; preds = %0, %32
%11 = load i32, i32* %1
%12 = icmp eq i32 %11, 0
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, 0
%15 = select i1 %12, i1 %14, i1 false
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 0
%18 = select i1 %15, i1 %17, i1 false
br i1 %18, label %37, label %19
19: ; preds = %10, %28
%20 = phi i32 [ %31, %28 ], [ %11, %10 ]
%21 = phi i32 [ %29, %28 ], [ 0, %10 ]
%22 = call i64 @isPrime(i32 %20)
%23 = icmp eq i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %19
%25 = add nsw i32 %21, 1
%26 = load i32, i32* %3
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %32
28: ; preds = %24, %19
%29 = phi i32 [ %25, %24 ], [ %21, %19 ]
%30 = load i32, i32* %2
%31 = add nsw i32 %30, %20
br label %19
32: ; preds = %24
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%34 = call i64 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2, i32* %3)
%35 = load i64, i64* @EOF
%36 = icmp eq i64 %34, %35
br i1 %36, label %37, label %10
37: ; preds = %32, %10, %0
ret i32 0
}