#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*/ fork();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ wait();
void lab4(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;
    }
    fork();
    wait();
  }
}


x86 assembly (clang, -O0):
<lab4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x1,-0x4(%rbp)
jge    1158 <lab4+0x28>
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bc <lab4+0x8c>
jmp    115d <lab4+0x2d>
cmpl   $0x1,-0x4(%rbp)
je     11bc <lab4+0x8c>
mov    -0x4(%rbp),%esi
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    119f <lab4+0x6f>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    11a9 <lab4+0x79>
imul   $0x3,-0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1050 <fork@plt>
mov    $0x0,%al
call   1040 <wait@plt>
jmp    115d <lab4+0x2d>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lab4>:
test   %edi,%edi
jle    1157 <lab4+0x17>
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
cmp    $0x1,%edi
jne    1163 <lab4+0x23>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xea6(%rip),%rdi
jmp    1030 <puts@plt>
lea    0xe96(%rip),%r14
jmp    1189 <lab4+0x49>
nopl   0x0(%rax)
lea    (%rbx,%rbx,2),%ebx
add    $0x1,%ebx
xor    %eax,%eax
call   1060 <fork@plt>
xor    %eax,%eax
call   1050 <wait@plt>
cmp    $0x1,%ebx
je     114f <lab4+0xf>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0x1,%bl
jne    1170 <lab4+0x30>
mov    %ebx,%eax
shr    $0x1f,%eax
add    %ebx,%eax
sar    %eax
mov    %eax,%ebx
jmp    1176 <lab4+0x36>

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 @lab4(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 %27
7: ; preds = %1
br label %8
8: ; preds = %24, %7
%9 = load i32, i32* %2
%10 = icmp ne i32 %9, 1
br i1 %10, label %11, label %27
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
%25 = call i32 (...) @fork()
%26 = call i32 (...) @wait()
br label %8
27: ; preds = %5, %8
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 @lab4(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 %22, 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 %22
7: ; preds = %3, %17
%8 = phi i32 [ %18, %17 ], [ %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
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = sdiv i32 %8, 2
br label %17
14: ; preds = %7
%15 = mul nsw i32 %8, 3
%16 = add nsw i32 %15, 1
br label %17
17: ; preds = %14, %12
%18 = phi i32 [ %13, %12 ], [ %16, %14 ]
%19 = tail call i32 (...) @fork()
%20 = tail call i32 (...) @wait()
%21 = icmp eq i32 %18, 1
br i1 %21, label %22, label %7
22: ; preds = %17, %3, %5
ret void
}