#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 *, ...);
int powers_of_2(int n) {
  if (n <= 0)
    return -1;
  if (n == 1) {
    printf(" 1");
    return 1;
  }
  int prev = powers_of_2(n / 2);
  int curr = prev * 2;
  printf(" %d", curr);
  return curr;
}


x86 assembly (clang, -O0):
<powers_of_2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     1141 <powers_of_2+0x21>
movl   $0xffffffff,-0x4(%rbp)
jmp    119a <powers_of_2+0x7a>
cmpl   $0x1,-0x8(%rbp)
jne    1165 <powers_of_2+0x45>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    119a <powers_of_2+0x7a>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1040 <powers_of_2@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<powers_of_2>:
push   %rbx
test   %edi,%edi
jle    113f <powers_of_2+0x1f>
cmp    $0x1,%edi
jne    1146 <powers_of_2+0x26>
lea    0xecf(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%ebx
jmp    1161 <powers_of_2+0x41>
mov    $0xffffffff,%ebx
jmp    1161 <powers_of_2+0x41>
shr    %edi
call   1040 <powers_of_2@plt>
mov    %eax,%ebx
add    %eax,%ebx
lea    0xeab(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c" 1\00"
@.str.1 = [4 x i8] c" %d\00"
define i32 @powers_of_2(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %7, label %3
3: ; preds = %1
%4 = icmp eq i32 %0, 1
br i1 %4, label %5, label %9
5: ; preds = %3
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %1, %9
%8 = phi i32 [ %12, %9 ], [ 1, %5 ], [ -1, %1 ]
ret i32 %8
9: ; preds = %3
%10 = lshr i32 %0, 1
%11 = tail call i32 @powers_of_2(i32 %10)
%12 = shl nsw i32 %11, 1
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %7
}