#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 iterative(int n) {
  while (true) {
    if (n == 4) {
      return n;
    } else if (n % 2 == 1) {
      n = (3 * n + 1);
    } else if (n % 2 == 0) {
      n = (n / 2);
    }
    printf("%d, ", n);
  }
}


x86 assembly (clang, -O0):
<iterative>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x4,-0x4(%rbp)
jne    112e <iterative+0x1e>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    1151 <iterative+0x41>
imul   $0x3,-0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1178 <iterative+0x68>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1173 <iterative+0x63>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1178 <iterative+0x68>
jmp    117d <iterative+0x6d>
mov    -0x4(%rbp),%esi
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
jmp    111b <iterative+0xb>

x86 assembly (clang, -O2):
<iterative>:
push   %r14
push   %rbx
push   %rax
cmp    $0x4,%edi
jne    1126 <iterative+0x16>
mov    $0x4,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %edi,%ebx
lea    0xed1(%rip),%r14
jmp    1153 <iterative+0x43>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
sar    %eax
mov    %eax,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
cmp    $0x4,%ebx
je     1119 <iterative+0x9>
mov    %ebx,%eax
shr    $0x1f,%eax
add    %ebx,%eax
mov    %eax,%edx
and    $0xfffffffe,%edx
mov    %ebx,%ecx
sub    %edx,%ecx
je     1140 <iterative+0x30>
cmp    $0x1,%ecx
jne    1144 <iterative+0x34>
lea    (%rbx,%rbx,2),%ebx
add    $0x1,%ebx
jmp    1144 <iterative+0x34>

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

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