#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*/ printf(char *, int);
main(int c, char **v) {
  int n = atoi(v[1]);
  while (n - 1) {
    n = n & 1 ? 3 * n + 1 : n / 2;
    printf("%d\n", n);
  }
}


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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cmp    $0x0,%eax
je     119b <main+0x7b>
mov    -0x14(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1173 <main+0x53>
imul   $0x3,-0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1181 <main+0x61>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
jmp    1146 <main+0x26>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x8(%rsi),%rdi
call   1040 <atoi@plt>
cmp    $0x1,%eax
jne    113c <main+0x1c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %eax,%ebx
lea    0xebb(%rip),%r14
jmp    116a <main+0x4a>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%eax
shr    $0x1f,%eax
add    %ebx,%eax
sar    %eax
mov    %eax,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
cmp    $0x1,%ebx
je     1132 <main+0x12>
test   $0x1,%bl
je     1150 <main+0x30>
lea    (%rbx,%rbx,2),%ebx
add    $0x1,%ebx
jmp    115b <main+0x3b>

LLVM IR (-O0):
@.str = [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 i8**, i8*** %5
%8 = getelementptr inbounds i8*, i8** %7, i64 1
%9 = load i8*, i8** %8
%10 = call i32 @atoi(i8* %9)
store i32 %10, i32* %6
br label %11
11: ; preds = %26, %2
%12 = load i32, i32* %6
%13 = sub nsw i32 %12, 1
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %30
15: ; preds = %11
%16 = load i32, i32* %6
%17 = and i32 %16, 1
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = load i32, i32* %6
%21 = mul nsw i32 3, %20
%22 = add nsw i32 %21, 1
br label %26
23: ; preds = %15
%24 = load i32, i32* %6
%25 = sdiv i32 %24, 2
br label %26
26: ; preds = %23, %19
%27 = phi i32 [ %22, %19 ], [ %25, %23 ]
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %28)
br label %11
30: ; preds = %11
%31 = load i32, i32* %3
ret i32 %31
}

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