#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ printf(char *, int);
int scanf(char *, int *);
int main(int argc, char **argv) {
  int n;
  int count = 0;
  if (scanf("%d", &n) != 1) {
    return EXIT_FAILURE;
  };
  if (n < 1) {
    return EXIT_FAILURE;
  }
  while (n > 1) {
    if (n % 2) {
      n = (3 * n + 1) / 2;
    } else {
      n /= 2;
    }
    count++;
  }
  if (n != 1) {
    return EXIT_FAILURE;
  }
  printf("%d", count);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xebc(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
je     1167 <main+0x47>
mov    0x2e83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    120e <main+0xee>
cmpl   $0x1,-0x14(%rbp)
jge    1182 <main+0x62>
mov    0x2e68(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    120e <main+0xee>
jmp    1187 <main+0x67>
cmpl   $0x1,-0x14(%rbp)
jle    11d8 <main+0xb8>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11bc <main+0x9c>
imul   $0x3,-0x14(%rbp),%eax
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
jmp    11ca <main+0xaa>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1187 <main+0x67>
cmpl   $0x1,-0x14(%rbp)
je     11f3 <main+0xd3>
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    120e <main+0xee>
mov    -0x18(%rbp),%esi
lea    0xe03(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x2ea7(%rip),%rcx
cmp    $0x1,%eax
jne    1189 <main+0x69>
mov    0x4(%rsp),%eax
test   %eax,%eax
jle    1189 <main+0x69>
xor    %esi,%esi
cmp    $0x2,%eax
jb     1176 <main+0x56>
xor    %esi,%esi
nop
test   $0x1,%al
lea    0x1(%rax,%rax,2),%edx
cmove  %eax,%edx
mov    %edx,%eax
shr    $0x1f,%eax
add    %edx,%eax
sar    %eax
add    $0x1,%esi
cmp    $0x3,%edx
jg     1150 <main+0x30>
mov    %eax,0x4(%rsp)
and    $0xfffffffe,%edx
cmp    $0x2,%edx
jne    1189 <main+0x69>
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e4f(%rip),%rcx
mov    (%rcx),%eax
pop    %rcx
ret

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

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