#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 handle(int, int);
scalar_t__ is_num_pld(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, int *);
int main(int argc, const char *argv[]) {
  int hex, n, a, i, j, flag;
  scanf("%d\n%d", &hex, &a);
  flag = 0;
  for (j = 1; j <= 30; j++) {
    a = handle(a, hex);
    if (is_num_pld(a, hex)) {
      printf("STEP=%d\n", j);
      flag = 1;
      break;
    }
  }
  if (!flag)
    printf("Impossible!");
}


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)
lea    0xea3(%rip),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1060 <scanf@plt>
movl   $0x0,-0x28(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x1e,-0x24(%rbp)
jg     11d5 <main+0x95>
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1050 <handle@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <is_num_pld@plt>
cmp    $0x0,%rax
je     11c2 <main+0x82>
mov    -0x24(%rbp),%esi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x28(%rbp)
jmp    11d5 <main+0x95>
jmp    11c7 <main+0x87>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1178 <main+0x38>
cmpl   $0x0,-0x28(%rbp)
jne    11ed <main+0xad>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xeb4(%rip),%rdi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1060 <scanf@plt>
mov    $0x1,%ebx
mov    0x8(%rsp),%edi
mov    0xc(%rsp),%esi
call   1050 <handle@plt>
mov    %eax,0x8(%rsp)
mov    0xc(%rsp),%esi
mov    %eax,%edi
call   1030 <is_num_pld@plt>
test   %rax,%rax
jne    1199 <main+0x59>
add    $0x1,%ebx
cmp    $0x1f,%ebx
jne    1160 <main+0x20>
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11a9 <main+0x69>
lea    0xe66(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%d\0A%d\00"
@.str.1 = [9 x i8] c"STEP=%d\0A\00"
@.str.2 = [12 x i8] c"Impossible!\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %6, i32* %8)
store i32 0, i32* %11
store i32 1, i32* %10
br label %13
13: ; preds = %28, %2
%14 = load i32, i32* %10
%15 = icmp sle i32 %14, 30
br i1 %15, label %16, label %31
16: ; preds = %13
%17 = load i32, i32* %8
%18 = load i32, i32* %6
%19 = call i32 @handle(i32 %17, i32 %18)
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = load i32, i32* %6
%22 = call i64 @is_num_pld(i32 %20, i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %16
%25 = load i32, i32* %10
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %25)
store i32 1, i32* %11
br label %31
27: ; preds = %16
br label %28
28: ; preds = %27
%29 = load i32, i32* %10
%30 = add nsw i32 %29, 1
store i32 %30, i32* %10
br label %13
31: ; preds = %24, %13
%32 = load i32, i32* %11
%33 = icmp ne i32 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %31
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %34, %31
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d\0A%d\00"
@.str.1 = [9 x i8] c"STEP=%d\0A\00"
@.str.2 = [12 x i8] c"Impossible!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4)
br label %8
8: ; preds = %2, %18
%9 = phi i32 [ 1, %2 ], [ %19, %18 ]
%10 = load i32, i32* %4
%11 = load i32, i32* %3
%12 = call i32 @handle(i32 %10, i32 %11)
store i32 %12, i32* %4
%13 = load i32, i32* %3
%14 = call i64 @is_num_pld(i32 %12, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %8
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %23
18: ; preds = %8
%19 = add nuw nsw i32 %9, 1
%20 = icmp eq i32 %19, 31
br i1 %20, label %21, label %8
21: ; preds = %18
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %16, %21
ret i32 0
}