#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 *, ...);
void collatzConjectureIterative(int x) {
  if (x < 1) {
    printf("Invalid input for the Collatz Conjecture.\n");
    return;
  }
  while (x > 1) {
    printf("%d\n", x);
    if ((x % 2) == 0) {
      x = x / 2;
    } else {
      x = (3 * x) + 1;
    }
  }
  printf("%d\n", x);
}


x86 assembly (clang, -O0):
<collatzConjectureIterative>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x1,-0x4(%rbp)
jge    1138 <collatzConjectureIterative+0x28>
lea    0xed4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119f <collatzConjectureIterative+0x8f>
jmp    113d <collatzConjectureIterative+0x2d>
cmpl   $0x1,-0x4(%rbp)
jle    118e <collatzConjectureIterative+0x7e>
mov    -0x4(%rbp),%esi
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    117f <collatzConjectureIterative+0x6f>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1189 <collatzConjectureIterative+0x79>
imul   $0x3,-0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    113d <collatzConjectureIterative+0x2d>
mov    -0x4(%rbp),%esi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<collatzConjectureIterative>:
test   %edi,%edi
jle    1176 <collatzConjectureIterative+0x56>
push   %r14
push   %rbx
push   %rax
mov    $0x1,%ebx
cmp    $0x1,%edi
je     115f <collatzConjectureIterative+0x3f>
lea    0xec7(%rip),%r14
mov    %edi,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
shr    %eax
test   $0x1,%bl
lea    0x1(%rbx,%rbx,2),%ebx
cmove  %eax,%ebx
cmp    $0x1,%ebx
jg     1140 <collatzConjectureIterative+0x20>
lea    0xe9a(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printf@plt>
lea    0xe87(%rip),%rdi
jmp    1030 <puts@plt>

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

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%d\0A\00"
@str = [42 x i8] c"Invalid input for the Collatz Conjecture.\00"
define void @collatzConjectureIterative(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %5, label %3
3: ; preds = %1
%4 = icmp eq i32 %0, 1
br i1 %4, label %17, label %7
5: ; preds = %1
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
br label %20
7: ; preds = %3, %7
%8 = phi i32 [ %15, %7 ], [ %0, %3 ]
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = and i32 %8, 1
%11 = icmp eq i32 %10, 0
%12 = lshr i32 %8, 1
%13 = mul nsw i32 %8, 3
%14 = add nsw i32 %13, 1
%15 = select i1 %11, i32 %12, i32 %14
%16 = icmp sgt i32 %15, 1
br i1 %16, label %7, label %17
17: ; preds = %7, %3
%18 = phi i32 [ 1, %3 ], [ %15, %7 ]
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %17, %5
ret void
}