#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, long, int, int);
scalar_t__ scanf(char *, long *, int *);
int main() {
  int L;
  long A;
  int num_case = 1;
  while (scanf("%ld%d", &A, &L) && (!(A < 0 && L < 0))) {
    long A_source = A;
    int count = 1;
    if (A != 1) {
      while (1) {
        if (A & 0x1)
          A = 3 * A + 1;
        else
          A = A / 2;
        if (A == 1) {
          count++;
          break;
        } else if (A > L) {
          break;
        }
        count++;
      }
    }
    printf("Case %d: A = %ld, limit = %d, number of terms = %d\n", num_case,
           A_source, L, count);
    num_case++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x14(%rbp)
lea    0xec3(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x8(%rbp),%rdx
call   1040 <scanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x25(%rbp)
je     117e <main+0x5e>
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x26(%rbp)
jge    1176 <main+0x56>
cmpl   $0x0,-0x8(%rbp)
setl   %al
mov    %al,-0x26(%rbp)
mov    -0x26(%rbp),%al
xor    $0xff,%al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    118e <main+0x6e>
jmp    1252 <main+0x132>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
cmpq   $0x1,-0x10(%rbp)
je     122a <main+0x10a>
jmp    11ad <main+0x8d>
mov    -0x10(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     11d1 <main+0xb1>
imul   $0x3,-0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11e3 <main+0xc3>
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
cmpq   $0x1,-0x10(%rbp)
jne    11fc <main+0xdc>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1225 <main+0x105>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
cmp    %rcx,%rax
jle    1212 <main+0xf2>
jmp    1225 <main+0x105>
jmp    1217 <main+0xf7>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ad <main+0x8d>
jmp    122a <main+0x10a>
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x8(%rbp),%ecx
mov    -0x24(%rbp),%r8d
lea    0xdc7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1136 <main+0x16>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xecc(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1040 <scanf@plt>
test   %rax,%rax
je     123a <main+0x11a>
mov    $0x1,%ebx
lea    0xeae(%rip),%r14
lea    0xea1(%rip),%r15
lea    0x8(%rsp),%r12
lea    0x4(%rsp),%r13
jmp    11a1 <main+0x81>
nopl   0x0(%rax,%rax,1)
movq   $0x1,0x8(%rsp)
add    $0x1,%r8d
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
add    $0x1,%ebx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1040 <scanf@plt>
test   %rax,%rax
je     123a <main+0x11a>
mov    0x8(%rsp),%rdx
mov    0x4(%rsp),%ecx
test   %rdx,%rdx
jns    11b7 <main+0x97>
test   %ecx,%ecx
js     123a <main+0x11a>
mov    $0x1,%r8d
cmp    $0x1,%rdx
je     117d <main+0x5d>
movslq %ecx,%rax
mov    $0x1,%r8d
mov    %rdx,%rsi
test   $0x1,%sil
jne    1200 <main+0xe0>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rsi,%rdi
shr    $0x3f,%rdi
add    %rsi,%rdi
sar    %rdi
mov    %rdi,%rsi
cmp    $0x1,%rsi
jne    1212 <main+0xf2>
jmp    1170 <main+0x50>
nopl   0x0(%rax,%rax,1)
lea    (%rsi,%rsi,2),%rsi
add    $0x1,%rsi
cmp    $0x1,%rsi
je     1170 <main+0x50>
cmp    %rax,%rsi
jg     1230 <main+0x110>
add    $0x1,%r8d
test   $0x1,%sil
jne    1200 <main+0xe0>
jmp    11e0 <main+0xc0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rsi,0x8(%rsp)
jmp    117d <main+0x5d>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%ld%d\00"
@.str.1 = [52 x i8] c"Case %d: A = %ld, limit = %d, number of terms = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %4
br label %7
7: ; preds = %54, %0
%8 = call i64 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64* %3, i32* %2)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %7
%11 = load i64, i64* %3
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* %2
%15 = icmp slt i32 %14, 0
br label %16
16: ; preds = %13, %10
%17 = phi i1 [ false, %10 ], [ %15, %13 ]
%18 = xor i1 %17, true
br label %19
19: ; preds = %16, %7
%20 = phi i1 [ false, %7 ], [ %18, %16 ]
br i1 %20, label %21, label %62
21: ; preds = %19
%22 = load i64, i64* %3
store i64 %22, i64* %5
store i32 1, i32* %6
%23 = load i64, i64* %3
%24 = icmp ne i64 %23, 1
br i1 %24, label %25, label %54
25: ; preds = %21
br label %26
26: ; preds = %25, %50
%27 = load i64, i64* %3
%28 = and i64 %27, 1
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i64, i64* %3
%32 = mul nsw i64 3, %31
%33 = add nsw i64 %32, 1
store i64 %33, i64* %3
br label %37
34: ; preds = %26
%35 = load i64, i64* %3
%36 = sdiv i64 %35, 2
store i64 %36, i64* %3
br label %37
37: ; preds = %34, %30
%38 = load i64, i64* %3
%39 = icmp eq i64 %38, 1
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %53
43: ; preds = %37
%44 = load i64, i64* %3
%45 = load i32, i32* %2
%46 = sext i32 %45 to i64
%47 = icmp sgt i64 %44, %46
br i1 %47, label %48, label %49
48: ; preds = %43
br label %53
49: ; preds = %43
br label %50
50: ; preds = %49
%51 = load i32, i32* %6
%52 = add nsw i32 %51, 1
store i32 %52, i32* %6
br label %26
53: ; preds = %48, %40
br label %54
54: ; preds = %53, %21
%55 = load i32, i32* %4
%56 = load i64, i64* %5
%57 = load i32, i32* %2
%58 = load i32, i32* %6
%59 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %55, i64 %56, i32 %57, i32 %58)
%60 = load i32, i32* %4
%61 = add nsw i32 %60, 1
store i32 %61, i32* %4
br label %7
62: ; preds = %19
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"%ld%d\00"
@.str.1 = [52 x i8] c"Case %d: A = %ld, limit = %d, number of terms = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = bitcast i32* %1 to i8*
%4 = bitcast i64* %2 to i8*
%5 = call i64 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64* %2, i32* %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %44, label %7
7: ; preds = %0, %38
%8 = phi i32 [ %41, %38 ], [ 1, %0 ]
%9 = load i64, i64* %2
%10 = icmp sgt i64 %9, -1
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, -1
%13 = select i1 %10, i1 true, i1 %12
br i1 %13, label %14, label %44
14: ; preds = %7
%15 = icmp eq i64 %9, 1
br i1 %15, label %38, label %16
16: ; preds = %14
%17 = sext i32 %11 to i64
br label %18
18: ; preds = %16, %35
%19 = phi i64 [ %29, %35 ], [ %9, %16 ]
%20 = phi i32 [ %36, %35 ], [ 1, %16 ]
%21 = and i64 %19, 1
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %18
%24 = mul nsw i64 %19, 3
%25 = add nsw i64 %24, 1
br label %28
26: ; preds = %18
%27 = sdiv i64 %19, 2
br label %28
28: ; preds = %26, %23
%29 = phi i64 [ %27, %26 ], [ %25, %23 ]
%30 = icmp eq i64 %29, 1
br i1 %30, label %31, label %33
31: ; preds = %28
store i64 1, i64* %2
%32 = add nuw nsw i32 %20, 1
br label %38
33: ; preds = %28
%34 = icmp sgt i64 %29, %17
br i1 %34, label %37, label %35
35: ; preds = %33
%36 = add nuw nsw i32 %20, 1
br label %18
37: ; preds = %33
store i64 %29, i64* %2
br label %38
38: ; preds = %37, %31, %14
%39 = phi i32 [ %32, %31 ], [ 1, %14 ], [ %20, %37 ]
%40 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %8, i64 %9, i32 %11, i32 %39)
%41 = add nuw nsw i32 %8, 1
%42 = call i64 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64* %2, i32* %1)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %7
44: ; preds = %7, %38, %0
ret i32 0
}