#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 *, long);
long r(long n) {
  printf("%ld\n", n);
  if (n <= 1)
    return n;
  if (n % 2)
    return r((n * 3) + 1);
  return r(n / 2);
}


x86 assembly (clang, -O0):
<r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xec9(%rip),%rdi
call   1040 <printf@plt>
cmpq   $0x1,-0x10(%rbp)
jg     1154 <r+0x34>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    119d <r+0x7d>
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
je     1183 <r+0x63>
imul   $0x3,-0x10(%rbp),%rdi
add    $0x1,%rdi
call   1030 <r@plt>
mov    %rax,-0x8(%rbp)
jmp    119d <r+0x7d>
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,%rdi
call   1030 <r@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<r>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xee2(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
cmp    $0x2,%rbx
jl     1163 <r+0x53>
lea    0xecd(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rax
shr    %rax
test   $0x1,%bl
lea    0x1(%rbx,%rbx,2),%rbx
cmove  %rax,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
cmp    $0x1,%rbx
jg     1140 <r+0x30>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"%ld\0A\00"
define i64 @r(i64 %0) {
%2 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %0)
%3 = icmp slt i64 %0, 2
br i1 %3, label %14, label %4
4: ; preds = %1, %4
%5 = phi i64 [ %11, %4 ], [ %0, %1 ]
%6 = and i64 %5, 1
%7 = icmp eq i64 %6, 0
%8 = mul nsw i64 %5, 3
%9 = add nsw i64 %8, 1
%10 = lshr i64 %5, 1
%11 = select i1 %7, i64 %10, i64 %9
%12 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %11)
%13 = icmp slt i64 %11, 2
br i1 %13, label %14, label %4
14: ; preds = %4, %1
%15 = phi i64 [ %0, %1 ], [ %11, %4 ]
ret i64 %15
}