#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int recursion(int n) {
  if (n == 4) {
    return n;
  } else if (n % 2 == 1) {
    return recursion(3 * n + 1);
  } else if (n % 2 == 0) {
    return recursion(n / 2);
  }
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<recursion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    1140 <recursion+0x20>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ae <recursion+0x8e>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    1168 <recursion+0x48>
imul   $0x3,-0x8(%rbp),%edi
add    $0x1,%edi
call   1030 <recursion@plt>
mov    %eax,-0x4(%rbp)
jmp    11ae <recursion+0x8e>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1196 <recursion+0x76>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1030 <recursion@plt>
mov    %eax,-0x4(%rbp)
jmp    11ae <recursion+0x8e>
jmp    119b <recursion+0x7b>
jmp    11a0 <recursion+0x80>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recursion>:
cmp    $0x4,%edi
jne    1129 <recursion+0x19>
jmp    114b <recursion+0x3b>
nopw   0x0(%rax,%rax,1)
sar    %eax
mov    %eax,%edi
cmp    $0x4,%edi
je     114b <recursion+0x3b>
mov    %edi,%eax
shr    $0x1f,%eax
add    %edi,%eax
mov    %eax,%edx
and    $0xfffffffe,%edx
mov    %edi,%ecx
sub    %edx,%ecx
je     1120 <recursion+0x10>
cmp    $0x1,%ecx
jne    1151 <recursion+0x41>
lea    (%rdi,%rdi,2),%edi
add    $0x1,%edi
cmp    $0x4,%edi
jne    1129 <recursion+0x19>
mov    $0x4,%eax
ret
push   %rax
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
call   1030 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
define i32 @recursion(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp eq i32 %4, 4
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = load i32, i32* %3
store i32 %7, i32* %2
br label %30
8: ; preds = %1
%9 = load i32, i32* %3
%10 = srem i32 %9, 2
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i32, i32* %3
%14 = mul nsw i32 3, %13
%15 = add nsw i32 %14, 1
%16 = call i32 @recursion(i32 %15)
store i32 %16, i32* %2
br label %30
17: ; preds = %8
%18 = load i32, i32* %3
%19 = srem i32 %18, 2
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load i32, i32* %3
%23 = sdiv i32 %22, 2
%24 = call i32 @recursion(i32 %23)
store i32 %24, i32* %2
br label %30
25: ; preds = %17
br label %26
26: ; preds = %25
br label %27
27: ; preds = %26
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %21, %12, %6
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
define i32 @recursion(i32 %0) {
%2 = icmp eq i32 %0, 4
br i1 %2, label %16, label %3
3: ; preds = %1, %10
%4 = phi i32 [ %11, %10 ], [ %0, %1 ]
%5 = srem i32 %4, 2
%6 = sdiv i32 %4, 2
switch i32 %5, label %13 [
i32 1, label %7
i32 0, label %10
]
7: ; preds = %3
%8 = mul nsw i32 %4, 3
%9 = add nsw i32 %8, 1
br label %10
10: ; preds = %3, %7
%11 = phi i32 [ %9, %7 ], [ %6, %3 ]
%12 = icmp eq i32 %11, 4
br i1 %12, label %16, label %3
13: ; preds = %3
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %10, %1
ret i32 4
}