#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(void) {
  int num, count;
  while (1) {
    scanf("%d", &num);
    if (num == 0)
      break;
    count = 0;
    while (num != 1) {
      if (num % 2 == 0) {
        num /= 2;
      } else {
        num = num * 3 + 1;
      }
      count++;
    }
    printf("%d\n", count);
  }
  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
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    114e <main+0x2e>
jmp    11b2 <main+0x92>
movl   $0x0,-0xc(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     119e <main+0x7e>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1186 <main+0x66>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    1190 <main+0x70>
imul   $0x3,-0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1155 <main+0x35>
mov    -0xc(%rbp),%esi
lea    0xe5b(%rip),%rdi
call   1030 <printf@plt>
jmp    112f <main+0xf>
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
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     11af <main+0x8f>
lea    0xeba(%rip),%r14
lea    0xeb0(%rip),%r15
lea    0xc(%rsp),%rbx
jmp    1183 <main+0x63>
nopw   0x0(%rax,%rax,1)
movl   $0x1,0xc(%rsp)
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     11af <main+0x8f>
xor    %esi,%esi
cmp    $0x1,%eax
je     1168 <main+0x48>
xor    %esi,%esi
jmp    119e <main+0x7e>
xchg   %ax,%ax
lea    (%rax,%rax,2),%eax
add    $0x1,%eax
add    $0x1,%esi
cmp    $0x1,%eax
je     1160 <main+0x40>
test   $0x1,%al
jne    1190 <main+0x70>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
mov    %ecx,%eax
jmp    1196 <main+0x76>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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