#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int n;
  if (argc != 2) {
    printf("Number required!\n");
    exit(1);
  }
  n = atoi(argv[1]);
  if (n <= 0) {
    printf("Number MUST be greater than zero.\n");
    exit(1);
  }
  while (n != 1) {
    printf("%d ", n);
    if (n % 2 == 0) {
      n = n / 2;
    } else {
      n = 3 * n + 1;
    }
  }
  printf("%d\n", n);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1168 <main+0x38>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     119a <main+0x6a>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    119f <main+0x6f>
cmpl   $0x1,-0x14(%rbp)
je     11f0 <main+0xc0>
mov    -0x14(%rbp),%esi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11e1 <main+0xb1>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
jmp    11eb <main+0xbb>
imul   $0x3,-0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119f <main+0x6f>
mov    -0x14(%rbp),%esi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    115f <main+0x1f>
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
test   %eax,%eax
jg     1175 <main+0x35>
lea    0xeab(%rip),%rdi
jmp    1166 <main+0x26>
lea    0xec4(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    %eax,%ebx
cmp    $0x1,%eax
je     11bc <main+0x7c>
lea    0xe7d(%rip),%r14
jmp    119b <main+0x5b>
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%rbx,%rbx,2),%ebx
add    $0x1,%ebx
cmp    $0x1,%ebx
je     11bc <main+0x7c>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0x1,%bl
jne    1190 <main+0x50>
mov    %ebx,%eax
shr    $0x1f,%eax
add    %ebx,%eax
sar    %eax
mov    %eax,%ebx
cmp    $0x1,%ebx
jne    119b <main+0x5b>
lea    0xe41(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"Number required!\0A\00"
@.str.1 = [35 x i8] c"Number MUST be greater than zero.\0A\00"
@.str.2 = [4 x i8] c"%d \00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp sle i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %12
br label %23
23: ; preds = %39, %22
%24 = load i32, i32* %6
%25 = icmp ne i32 %24, 1
br i1 %25, label %26, label %40
26: ; preds = %23
%27 = load i32, i32* %6
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %6
%30 = srem i32 %29, 2
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = load i32, i32* %6
%34 = sdiv i32 %33, 2
store i32 %34, i32* %6
br label %39
35: ; preds = %26
%36 = load i32, i32* %6
%37 = mul nsw i32 3, %36
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %39
39: ; preds = %35, %32
br label %23
40: ; preds = %23
%41 = load i32, i32* %6
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %41)
%43 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.2 = [4 x i8] c"%d \00"
@.str.3 = [4 x i8] c"%d\0A\00"
@str = [34 x i8] c"Number MUST be greater than zero.\00"
@str.4 = [17 x i8] c"Number required!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.4, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = icmp slt i32 %10, 1
br i1 %11, label %14, label %12
12: ; preds = %7
%13 = icmp eq i32 %10, 1
br i1 %13, label %30, label %17
14: ; preds = %7
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %12, %27
%18 = phi i32 [ %28, %27 ], [ %10, %12 ]
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = and i32 %18, 1
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = sdiv i32 %18, 2
br label %27
24: ; preds = %17
%25 = mul nsw i32 %18, 3
%26 = add nsw i32 %25, 1
br label %27
27: ; preds = %24, %22
%28 = phi i32 [ %23, %22 ], [ %26, %24 ]
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %17
30: ; preds = %27, %12
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 1)
%32 = tail call i32 @exit(i32 0)
unreachable
}