#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*/ formatedOutput(int);
scalar_t__ isOdd(int);
int /*<<< orphan*/ printf(char *, int);
void printCollatzSequence(int term) {
  int numberOfTerms = 1;
  printf("\n%d  ", term);
  while (term != 1) {
    if (isOdd(term))
      term = term / 2;
    else
      term = 3 * term + 1;
    printf("%d  ", term);
    formatedOutput(++numberOfTerms);
  }
  printf("\n\n%d  ", numberOfTerms);
}


x86 assembly (clang, -O0):
<printCollatzSequence>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x4(%rbp),%esi
lea    0xeb5(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x1,-0x4(%rbp)
je     11ac <printCollatzSequence+0x7c>
mov    -0x4(%rbp),%edi
call   1040 <isOdd@plt>
cmp    $0x0,%rax
je     1180 <printCollatzSequence+0x50>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    118a <printCollatzSequence+0x5a>
imul   $0x3,-0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
add    $0x1,%edi
mov    %edi,-0x8(%rbp)
call   1050 <formatedOutput@plt>
jmp    1151 <printCollatzSequence+0x21>
mov    -0x8(%rbp),%esi
lea    0xe4a(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printCollatzSequence>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
lea    0xec4(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    $0x1,%ebp
cmp    $0x1,%ebx
jne    1160 <printCollatzSequence+0x30>
lea    0xeab(%rip),%rdi
mov    %ebp,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <printf@plt>
mov    $0x1,%ebp
lea    0xe96(%rip),%r14
jmp    118f <printCollatzSequence+0x5f>
xchg   %ax,%ax
lea    (%rbx,%rbx,2),%ebx
add    $0x1,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
add    $0x1,%ebp
mov    %ebp,%edi
call   1050 <formatedOutput@plt>
cmp    $0x1,%ebx
je     114e <printCollatzSequence+0x1e>
mov    %ebx,%edi
call   1040 <isOdd@plt>
test   %rax,%rax
je     1170 <printCollatzSequence+0x40>
mov    %ebx,%eax
shr    $0x1f,%eax
add    %ebx,%eax
sar    %eax
mov    %eax,%ebx
jmp    1176 <printCollatzSequence+0x46>

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

LLVM IR (-O2):
@.str = [6 x i8] c"\0A%d \00"
@.str.1 = [5 x i8] c"%d \00"
@.str.2 = [7 x i8] c"\0A\0A%d \00"
define void @printCollatzSequence(i32 %0) {
%2 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = icmp eq i32 %0, 1
br i1 %3, label %20, label %4
4: ; preds = %1, %14
%5 = phi i32 [ %17, %14 ], [ 1, %1 ]
%6 = phi i32 [ %15, %14 ], [ %0, %1 ]
%7 = tail call i64 @isOdd(i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = sdiv i32 %6, 2
br label %14
11: ; preds = %4
%12 = mul nsw i32 %6, 3
%13 = add nsw i32 %12, 1
br label %14
14: ; preds = %11, %9
%15 = phi i32 [ %10, %9 ], [ %13, %11 ]
%16 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = add nuw nsw i32 %5, 1
%18 = tail call i32 @formatedOutput(i32 %17)
%19 = icmp eq i32 %15, 1
br i1 %19, label %20, label %4
20: ; preds = %14, %1
%21 = phi i32 [ 1, %1 ], [ %17, %14 ]
%22 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %21)
ret void
}