#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 uint64_t;

/* Variables and functions */
int fscanf(int /*<<< orphan*/, char *, int *, int *, unsigned int *);
int /*<<< orphan*/ printf(char *, int, int, unsigned int, char);
int /*<<< orphan*/ sieve_small_primes(int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int try_all_factors(int, unsigned int, int);
int main(int argc, char **argv) {
  int f;
  uint64_t K, temp;
  unsigned int N;
  int sign = 1;
  sieve_small_primes(0);
  while (fscanf(stdin, "%lu | %lu*2^%u+1\n", &temp, &K, &N) == 3) {
    f = try_all_factors(K, N, sign);
    if (f == 0)
      printf("%lu | %lu*2^%u%c1\n", temp, K, N, (sign < 0) ? '-' : '+');
    else
      printf("sm %d | %lu*2^%u%c1\n", f, K, N, (sign < 0) ? '-' : '+');
  }
  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)
movl   $0x1,-0x24(%rbp)
xor    %edi,%edi
call   1060 <sieve_small_primes@plt>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
lea    0xe8c(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%r8
call   1050 <fscanf@plt>
cmp    $0x3,%eax
jne    120f <main+0xcf>
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1030 <try_all_factors@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11dc <main+0x9c>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    $0x2b,%eax
mov    $0x2d,%edi
cmp    $0x0,%r8d
cmovl  %edi,%eax
lea    0xe44(%rip),%rdi
movsbl %al,%r8d
call   1040 <printf@plt>
jmp    120a <main+0xca>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    $0x2b,%eax
mov    $0x2d,%edi
cmp    $0x0,%r8d
cmovl  %edi,%eax
lea    0xe24(%rip),%rdi
movsbl %al,%r8d
call   1040 <printf@plt>
jmp    1164 <main+0x24>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %edi,%edi
call   1060 <sieve_small_primes@plt>
mov    0x2e8c(%rip),%r14
mov    (%r14),%edi
lea    0xe9a(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
call   1050 <fscanf@plt>
cmp    $0x3,%eax
jne    11fc <main+0xbc>
lea    0xe7a(%rip),%r15
lea    0x14(%rsp),%r12
lea    0x10(%rsp),%r13
lea    0xc(%rsp),%rbx
lea    0xe89(%rip),%rbp
jmp    11d1 <main+0x91>
xchg   %ax,%ax
mov    0x10(%rsp),%edx
mov    0xc(%rsp),%ecx
mov    %rbp,%rdi
mov    %eax,%esi
mov    $0x2b,%r8d
call   1040 <printf@plt>
mov    (%r14),%edi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbx,%r8
call   1050 <fscanf@plt>
cmp    $0x3,%eax
jne    11fc <main+0xbc>
mov    0x10(%rsp),%edi
mov    0xc(%rsp),%esi
mov    $0x1,%edx
call   1030 <try_all_factors@plt>
test   %eax,%eax
jne    11a0 <main+0x60>
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
mov    0xc(%rsp),%ecx
lea    0xe18(%rip),%rdi
jmp    11ad <main+0x6d>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [18 x i8] c"%lu | %lu*2^%u+1\0A\00"
@.str.1 = [19 x i8] c"%lu | %lu*2^%u%c1\0A\00"
@.str.2 = [21 x i8] c"sm %d | %lu*2^%u%c1\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %10
%11 = call i32 @sieve_small_primes(i32 0)
br label %12
12: ; preds = %43, %2
%13 = load i32, i32* @stdin
%14 = call i32 @fscanf(i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32* %8, i32* %7, i32* %9)
%15 = icmp eq i32 %14, 3
br i1 %15, label %16, label %44
16: ; preds = %12
%17 = load i32, i32* %7
%18 = load i32, i32* %9
%19 = load i32, i32* %10
%20 = call i32 @try_all_factors(i32 %17, i32 %18, i32 %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %16
%24 = load i32, i32* %8
%25 = load i32, i32* %7
%26 = load i32, i32* %9
%27 = load i32, i32* %10
%28 = icmp slt i32 %27, 0
%29 = zext i1 %28 to i64
%30 = select i1 %28, i32 45, i32 43
%31 = trunc i32 %30 to i8
%32 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %25, i32 %26, i8 signext %31)
br label %43
33: ; preds = %16
%34 = load i32, i32* %6
%35 = load i32, i32* %7
%36 = load i32, i32* %9
%37 = load i32, i32* %10
%38 = icmp slt i32 %37, 0
%39 = zext i1 %38 to i64
%40 = select i1 %38, i32 45, i32 43
%41 = trunc i32 %40 to i8
%42 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %34, i32 %35, i32 %36, i8 signext %41)
br label %43
43: ; preds = %33, %23
br label %12
44: ; preds = %12
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [18 x i8] c"%lu | %lu*2^%u+1\0A\00"
@.str.1 = [19 x i8] c"%lu | %lu*2^%u%c1\0A\00"
@.str.2 = [21 x i8] c"sm %d | %lu*2^%u%c1\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = tail call i32 @sieve_small_primes(i32 0)
%10 = load i32, i32* @stdin
%11 = call i32 @fscanf(i32 %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %3, i32* %5)
%12 = icmp eq i32 %11, 3
br i1 %12, label %13, label %31
13: ; preds = %2, %27
%14 = load i32, i32* %3
%15 = load i32, i32* %5
%16 = call i32 @try_all_factors(i32 %14, i32 %15, i32 1)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %13
%19 = load i32, i32* %4
%20 = load i32, i32* %3
%21 = load i32, i32* %5
%22 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %20, i32 %21, i8 signext 43)
br label %27
23: ; preds = %13
%24 = load i32, i32* %3
%25 = load i32, i32* %5
%26 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %16, i32 %24, i32 %25, i8 signext 43)
br label %27
27: ; preds = %23, %18
%28 = load i32, i32* @stdin
%29 = call i32 @fscanf(i32 %28, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %3, i32* %5)
%30 = icmp eq i32 %29, 3
br i1 %30, label %13, label %31
31: ; preds = %27, %2
ret i32 0
}