#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 /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int a, b, c;
  scanf("%d %d", &a, &b);
  while (1) {
    scanf("%d", &c);
    if (c < 0) {
      printf("%d", c);
      break;
    }
    if (!(c % a) && !(c % b)) {
      printf("%d\n2", c);
      break;
    } else if (!(c % a)) {
      printf("%d\n0", c);
      break;
    } else if (!(c % b)) {
      printf("%d\n1", c);
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xeb7(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmpl   $0x0,-0x10(%rbp)
jge    1175 <main+0x55>
mov    -0x10(%rbp),%esi
lea    0xe98(%rip),%rdi
call   1030 <printf@plt>
jmp    1200 <main+0xe0>
mov    -0x10(%rbp),%eax
cltd
idivl  -0x8(%rbp)
cmp    $0x0,%edx
jne    11a9 <main+0x89>
mov    -0x10(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    11a9 <main+0x89>
mov    -0x10(%rbp),%esi
lea    0xe67(%rip),%rdi
call   1030 <printf@plt>
jmp    1200 <main+0xe0>
mov    -0x10(%rbp),%eax
cltd
idivl  -0x8(%rbp)
cmp    $0x0,%edx
jne    11cd <main+0xad>
mov    -0x10(%rbp),%esi
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
jmp    1200 <main+0xe0>
mov    -0x10(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    11f1 <main+0xd1>
mov    -0x10(%rbp),%esi
lea    0xe29(%rip),%rdi
call   1030 <printf@plt>
jmp    1200 <main+0xe0>
jmp    11f6 <main+0xd6>
jmp    11fb <main+0xdb>
jmp    1145 <main+0x25>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xed0(%rip),%rdi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
lea    0xebb(%rip),%rbx
lea    0x4(%rsp),%r14
lea    0xebc(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x4(%rsp),%esi
test   %esi,%esi
js     11a6 <main+0x86>
mov    %esi,%eax
cltd
idivl  0xc(%rsp)
mov    %edx,%ecx
mov    %esi,%eax
cltd
idivl  0x8(%rsp)
test   %ecx,%ecx
je     1192 <main+0x72>
test   %edx,%edx
jne    1160 <main+0x40>
mov    %r15,%rbx
jmp    11a6 <main+0x86>
test   %edx,%edx
lea    0xe6b(%rip),%rax
lea    0xe69(%rip),%rbx
cmove  %rax,%rbx
mov    %rbx,%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [5 x i8] c"%d\0A2\00"
@.str.3 = [5 x i8] c"%d\0A0\00"
@.str.4 = [5 x i8] c"%d\0A1\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 i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
br label %8
8: ; preds = %21, %0
%9 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 0
br i1 %11, label %22, label %12
12: ; preds = %8
%13 = load i32, i32* %1
%14 = srem i32 %10, %13
%15 = icmp eq i32 %14, 0
%16 = load i32, i32* %2
%17 = srem i32 %10, %16
%18 = icmp eq i32 %17, 0
br i1 %15, label %19, label %21
19: ; preds = %12
%20 = select i1 %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0)
br label %22
21: ; preds = %12
br i1 %18, label %22, label %8
22: ; preds = %21, %8, %19
%23 = phi i8* [ %20, %19 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), %21 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %8 ]
%24 = call i32 @printf(i8* %23, i32 %10)
ret i32 0
}