#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*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
main() {
  int num = 0;
  while (num < 1) {
    printf("Please insert a positive integer: ");
    scanf("%d", &num);
  }
  while (num != 1) {
    if (num % 2 == 0) {
      num = num / 2;
    } else {
      num = (num * 3) + 1;
    }
    printf("%d\n", num);
  }
  getchar();
  getchar();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jge    1173 <main+0x43>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebe(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
jmp    1146 <main+0x16>
jmp    1178 <main+0x48>
cmpl   $0x1,-0x8(%rbp)
je     11c9 <main+0x99>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11a9 <main+0x79>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    11b3 <main+0x83>
imul   $0x3,-0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1178 <main+0x48>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
lea    0xeb8(%rip),%r14
lea    0xed4(%rip),%r15
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    1160 <main+0x30>
cmp    $0x1,%eax
jne    119c <main+0x6c>
xor    %eax,%eax
call   1040 <getchar@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe83(%rip),%rbx
jmp    11cd <main+0x9d>
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%rax,%rax,2),%esi
add    $0x1,%esi
mov    %esi,0xc(%rsp)
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0xc(%rsp),%eax
cmp    $0x1,%eax
je     1182 <main+0x52>
test   $0x1,%al
jne    11b0 <main+0x80>
mov    %eax,%esi
shr    $0x1f,%esi
add    %eax,%esi
sar    %esi
jmp    11b6 <main+0x86>

LLVM IR (-O0):
@.str = [35 x i8] c"Please insert a positive integer: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
br label %3
3: ; preds = %6, %0
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 1
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %3
9: ; preds = %3
br label %10
10: ; preds = %24, %9
%11 = load i32, i32* %2
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %27
13: ; preds = %10
%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 = %13
%18 = load i32, i32* %2
%19 = sdiv i32 %18, 2
store i32 %19, i32* %2
br label %24
20: ; preds = %13
%21 = load i32, i32* %2
%22 = mul nsw i32 %21, 3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %2
br label %24
24: ; preds = %20, %17
%25 = load i32, i32* %2
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %10
27: ; preds = %10
%28 = call i32 (...) @getchar()
%29 = call i32 (...) @getchar()
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str = [35 x i8] c"Please insert a positive integer: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
br label %5
3: ; preds = %5
%4 = icmp eq i32 %8, 1
br i1 %4, label %24, label %10
5: ; preds = %0, %5
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = icmp slt i32 %8, 1
br i1 %9, label %5, label %3
10: ; preds = %3, %19
%11 = phi i32 [ %22, %19 ], [ %8, %3 ]
%12 = and i32 %11, 1
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = sdiv i32 %11, 2
br label %19
16: ; preds = %10
%17 = mul nsw i32 %11, 3
%18 = add nsw i32 %17, 1
br label %19
19: ; preds = %16, %14
%20 = phi i32 [ %18, %16 ], [ %15, %14 ]
store i32 %20, i32* %1
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %1
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %10
24: ; preds = %19, %3
%25 = call i32 (...) @getchar()
%26 = call i32 (...) @getchar()
ret i32 0
}