#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 collatz_conjecture_sequence(int n) {
  printf("%d ", n);
  while (n != 1) {
    if (n % 2 == 0)
      n = n / 2;
    else
      n = (3 * n) + 1;
    printf("%d ", n);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<collatz_conjecture_sequence>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xedb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1,-0x4(%rbp)
je     117d <collatz_conjecture_sequence+0x6d>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    115d <collatz_conjecture_sequence+0x4d>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1167 <collatz_conjecture_sequence+0x57>
imul   $0x3,-0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    112c <collatz_conjecture_sequence+0x1c>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<collatz_conjecture_sequence>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0xed3(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%ebx
jne    114c <collatz_conjecture_sequence+0x2c>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <putchar@plt>
lea    0xead(%rip),%r14
jmp    1177 <collatz_conjecture_sequence+0x57>
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%rbx,%rbx,2),%ebx
add    $0x1,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%ebx
je     113b <collatz_conjecture_sequence+0x1b>
test   $0x1,%bl
jne    1160 <collatz_conjecture_sequence+0x40>
mov    %ebx,%eax
shr    $0x1f,%eax
add    %ebx,%eax
sar    %eax
mov    %eax,%ebx
jmp    1166 <collatz_conjecture_sequence+0x46>

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

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